Skip to content

Commit

Permalink
Implement Collector pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
zalegrala committed Nov 10, 2021
1 parent f210535 commit 91b548a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions cmd/tempo/app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (t *App) initOverrides() (services.Service, error) {
return nil, fmt.Errorf("failed to create overrides %w", err)
}
t.overrides = overrides
prometheus.MustRegister(t.overrides)

return t.overrides, nil
}
Expand Down
38 changes: 23 additions & 15 deletions modules/overrides/overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
const wildcardTenant = "*"

var (
metricOverridesLimits = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "tempo",
Name: "limits_overrides",
Help: "Per-Tenant usage limits",
}, []string{"limit_name", "user"})
metricOverridesLimitsDesc = prometheus.NewDesc(
"tempo_limits_overrides",
"Resource limit overrides applied to tenants",
[]string{"limit_name", "user"},
nil,
)

metricDefaultsLimits = promauto.NewGaugeVec(prometheus.GaugeOpts{
Namespace: "tempo",
Expand Down Expand Up @@ -56,16 +57,6 @@ func loadPerTenantOverrides(r io.Reader) (interface{}, error) {
return nil, err
}

for tenant, tenantLimits := range overrides.TenantLimits {
metricOverridesLimits.WithLabelValues("max_local_traces_per_user", tenant).Set(float64(tenantLimits.MaxLocalTracesPerUser))
metricOverridesLimits.WithLabelValues("max_global_traces_per_user", tenant).Set(float64(tenantLimits.MaxGlobalTracesPerUser))
metricOverridesLimits.WithLabelValues("max_bytes_per_trace", tenant).Set(float64(tenantLimits.MaxBytesPerTrace))
metricOverridesLimits.WithLabelValues("max_search_bytes_per_trace", tenant).Set(float64(tenantLimits.MaxSearchBytesPerTrace))
metricOverridesLimits.WithLabelValues("ingestion_rate_limit_bytes", tenant).Set(float64(tenantLimits.IngestionRateLimitBytes))
metricOverridesLimits.WithLabelValues("ingestion_burst_size_bytes", tenant).Set(float64(tenantLimits.IngestionBurstSizeBytes))
metricOverridesLimits.WithLabelValues("block_retention", tenant).Set(float64(tenantLimits.BlockRetention))
}

return overrides, nil
}

Expand Down Expand Up @@ -301,3 +292,20 @@ func (o *Overrides) getOverridesForUser(userID string) *Limits {

return o.defaultLimits
}

func (o *Overrides) Describe(ch chan<- *prometheus.Desc) {
ch <- metricOverridesLimitsDesc
}

func (o *Overrides) Collect(ch chan<- prometheus.Metric) {
for tenant, limits := range o.tenantOverrides().TenantLimits {

ch <- prometheus.MustNewConstMetric(metricOverridesLimitsDesc, prometheus.GaugeValue, float64(limits.MaxLocalTracesPerUser), "max_local_traces_per_user", tenant)
ch <- prometheus.MustNewConstMetric(metricOverridesLimitsDesc, prometheus.GaugeValue, float64(limits.MaxGlobalTracesPerUser), "max_global_traces_per_user", tenant)
ch <- prometheus.MustNewConstMetric(metricOverridesLimitsDesc, prometheus.GaugeValue, float64(limits.MaxBytesPerTrace), "max_bytes_per_trace", tenant)
ch <- prometheus.MustNewConstMetric(metricOverridesLimitsDesc, prometheus.GaugeValue, float64(limits.MaxSearchBytesPerTrace), "max_search_bytes_per_trace", tenant)
ch <- prometheus.MustNewConstMetric(metricOverridesLimitsDesc, prometheus.GaugeValue, float64(limits.IngestionRateLimitBytes), "ingestion_rate_limit_bytes", tenant)
ch <- prometheus.MustNewConstMetric(metricOverridesLimitsDesc, prometheus.GaugeValue, float64(limits.IngestionBurstSizeBytes), "ingestion_burst_size_bytes", tenant)
ch <- prometheus.MustNewConstMetric(metricOverridesLimitsDesc, prometheus.GaugeValue, float64(limits.BlockRetention), "block_retention", tenant)
}
}

0 comments on commit 91b548a

Please sign in to comment.