github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/pkg/util/validation/exporter.go (about) 1 package validation 2 3 import ( 4 "github.com/prometheus/client_golang/prometheus" 5 ) 6 7 // OverridesExporter exposes per-tenant resource limit overrides as Prometheus metrics 8 type OverridesExporter struct { 9 tenantLimits TenantLimits 10 description *prometheus.Desc 11 } 12 13 // NewOverridesExporter creates an OverridesExporter that reads updates to per-tenant 14 // limits using the provided function. 15 func NewOverridesExporter(tenantLimits TenantLimits) *OverridesExporter { 16 return &OverridesExporter{ 17 tenantLimits: tenantLimits, 18 description: prometheus.NewDesc( 19 "cortex_overrides", 20 "Resource limit overrides applied to tenants", 21 []string{"limit_name", "user"}, 22 nil, 23 ), 24 } 25 } 26 27 func (oe *OverridesExporter) Describe(ch chan<- *prometheus.Desc) { 28 ch <- oe.description 29 } 30 31 func (oe *OverridesExporter) Collect(ch chan<- prometheus.Metric) { 32 allLimits := oe.tenantLimits.AllByUserID() 33 for tenant, limits := range allLimits { 34 ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, limits.IngestionRate, "ingestion_rate", tenant) 35 ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.IngestionBurstSize), "ingestion_burst_size", tenant) 36 37 ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxSeriesPerQuery), "max_series_per_query", tenant) 38 ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxSamplesPerQuery), "max_samples_per_query", tenant) 39 ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxLocalSeriesPerUser), "max_local_series_per_user", tenant) 40 ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxLocalSeriesPerMetric), "max_local_series_per_metric", tenant) 41 ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxGlobalSeriesPerUser), "max_global_series_per_user", tenant) 42 ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxGlobalSeriesPerMetric), "max_global_series_per_metric", tenant) 43 } 44 }