Skip to content

feat(ingester): Add cortex_ingester_active_metric_names gauge per user#7514

Open
yeya24 wants to merge 1 commit into
masterfrom
active-metric-names-per-user
Open

feat(ingester): Add cortex_ingester_active_metric_names gauge per user#7514
yeya24 wants to merge 1 commit into
masterfrom
active-metric-names-per-user

Conversation

@yeya24
Copy link
Copy Markdown
Contributor

@yeya24 yeya24 commented May 13, 2026

Summary

Expose the number of unique metric names (distinct __name__ values) per tenant in the ingester head as a new Prometheus gauge metric: cortex_ingester_active_metric_names.

Motivation

Operators need visibility into metric name cardinality per tenant to detect cardinality explosions at the metric name level (as opposed to series level which cortex_ingester_active_series already covers).

Changes

  • pkg/ingester/user_state.go: Added ActiveMetricNames() method to metricCounter that returns the total number of unique metric names across all shards.
  • pkg/ingester/metrics.go: Added cortex_ingester_active_metric_names GaugeVec (labels: user), registered under activeSeriesEnabled gate, with cleanup in deletePerUserMetrics.
  • pkg/ingester/ingester.go: Set the gauge in updateActiveSeries loop and clean up on TSDB close.
  • pkg/ingester/user_state_test.go: Unit test for ActiveMetricNames().
  • docs/configuration/v1-guarantees.md: Listed as experimental feature.

How it works

The seriesInMetric (metricCounter) already tracks a sharded map of metricName → seriesCount maintained via TSDB PostCreation/PostDeletion callbacks. The number of keys in this map equals the number of unique metric names in the head. No new data structures or tracking overhead is introduced.

Testing

  • Unit test: TestMetricCounter_ActiveMetricNames — verifies count increases/decreases correctly as series are added/removed.
  • Existing tests pass (pre-existing failures in TestExpandedCachePostings_Race and TestIngester_Push are unrelated race conditions on master).

Expose the number of unique metric names (distinct __name__ values) per
tenant in the ingester head as a new Prometheus gauge metric. The data
is sourced from the existing seriesInMetric counter which already tracks
series counts per metric name via TSDB lifecycle callbacks.

The metric is registered when -ingester.active-series-metrics-enabled is
true (same gate as cortex_ingester_active_series) and updated in the
same periodic loop alongside active series counts.

This enables operators to monitor metric name cardinality per tenant
without additional overhead, as the underlying data structure already
exists.

Signed-off-by: Ben Ye <benye@amazon.com>
@dosubot dosubot Bot added component/ingester type/feature type/observability To help know what is going on inside Cortex labels May 13, 2026
Comment thread pkg/ingester/metrics.go
// Not registered automatically, but only if activeSeriesEnabled is true.
activeMetricNamesPerUser: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "cortex_ingester_active_metric_names",
Help: "Number of unique metric names in the ingester head per user.",
Copy link
Copy Markdown
Member

@SungJin1212 SungJin1212 May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: What about a TSDB head?

Suggested change
Help: "Number of unique metric names in the ingester head per user.",
Help: "Number of unique metric names in the TSDB head per user.",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants