Cloud engineering

Metrics Cardinality

A label-value product estimates possible combinations. Count emitted identities and their turnover before using that number in an observability decision.

Synthetic window
144 core identities; 576 with tenant; unrestricted bound 3,456
Turnover result
New replica names double the two-window union to 288 or 1,152
Evidence boundary
Calculated label sets, with no backend resource or billing measurement
A sparse teal cube lattice expands into denser navy layers when amber tags add combinations.
Conceptual illustration of label combinations expanding the set of metric identities.

One new label produced four times as many identities

In the synthetic dataset below, adding tenant increases distinct identities for one counter metric from 144 to 576 within a window. The calculated multiplier is 4. Multiplying by all 24 tenant values would instead predict 3,456 possible identities, six times the observed count. Those answers describe different things: actual combinations in the constructed dataset and an unrestricted upper bound.

Neither number estimates a monitoring bill. The exercise counts label identities without running Prometheus, recording memory use or applying a vendor's pricing model. It gives an engineer a way to review a proposed label before translating measured backend behavior into capacity or cost decisions.

Prometheus identifies a time series by its metric name and label set, as its data model explains. A new combination creates another identity even when the underlying metric name stays unchanged. The useful question is therefore which combinations the service will actually emit and how that set changes over time.

Declare the data before multiplying it

The fixture assigns six route templates, two HTTP methods, two status values, two regions and three replica identities in each of two observation windows. Every combination of those five dimensions is present. Each route is associated with exactly four tenants, and the tenant groups do not overlap between routes. There are 24 tenant values overall, but no route serves all 24 in this constructed dataset.

Window B repeats the same logical traffic combinations with new replica names. This is a deliberate turnover scenario, not evidence about a particular deployment platform. The windows have no assigned duration. All rows represent observed label combinations in the model, rather than counters, individual requests or sampled production telemetry.

Assigned label dimensions and constraints in each synthetic window
DimensionAssigned values per windowConstraint
Route template6Every core combination appears
Method2GET and POST
Status2200 and 500
Region2eu and us
Replica3Names change between A and B
Tenant24 overallFour distinct tenants per route

The core product is 6 × 2 × 2 × 2 × 3 = 144. Because each route has four tenants, the emitted tenant-bearing set is 144 × 4 = 576. The unrestricted product, 144 × 24 = 3,456, answers what could happen if every tenant appeared in every core combination. That is not how this fixture was generated.

Download the 1,152-row dataset, calculation script and results JSON. Save the script as calculate.py and run python3 calculate.py to regenerate both files using only Python's standard library.

Metrics cardinality is the number of distinct time-series identities under a stated scope and observation period. A label's cardinality counts its distinct values. Dimensionality counts label names. Adding a label can multiply possible combinations without proving that every combination will occur. Always distinguish an instrumentation upper bound, currently observed series and the union seen over retention.

Count sets rather than rows

For a fixed metric name, the script projects each row onto the selected label fields and inserts the resulting tuple into a set. The set size is the distinct identity count. Removing tenant from that projection collapses each group of four tenant rows into one core identity. Merely counting the 576 rows in window A would miss that distinction.

Window A has 144 observed core identities and 576 with tenant. The unrestricted product is 3,456, assuming all 24 tenants in every core combination.
Figure 1. Counts calculated from the supplied synthetic rows. The upper bound assumes combinations that the fixture does not emit. View full-size figure.

This method also exposes a missing input: exporter or collector labels. The fixture includes only its declared columns. An actual scrape may add target identity or other labels that distinguish two otherwise identical application series. Collect the emitted label set at the boundary whose capacity you are estimating, rather than assuming the application's instrumentation code describes every downstream dimension.

Prometheus's label naming guidance warns about unbounded dimensions such as user IDs. A route template, such as /orders/{id}, bounds the route vocabulary more usefully than assigning a unique path for every order. Normalization must come from a trustworthy routing contract; a loose replacement rule can merge unrelated endpoints and make the resulting metric misleading.

Stable window counts can hide turnover

Each window contains 144 core identities, so a chart showing only that count appears flat. Across both windows, the union contains 288 because every replica name changed. With tenant included, the per-window count is 576 and the union is 1,152.

Window A and B each have 144 core and 576 tenant identities. With completely new replica names the union becomes 288 core and 1,152 tenant identities.
Figure 2. Replica-name turnover doubles the union while both individual window counts stay unchanged. This is not a backend retention measurement. View full-size figure.

These are distinct sets over declared windows. They are not a measurement of Prometheus head-series retention or a claim that exactly 288 series would remain active in a live server. Backend lifecycle rules determine which old series remain in memory or storage. The union simply shows that a stable per-window count does not establish stable identity over a longer horizon.

Dropping replica from the core projection yields 48 identities in either window and 48 across their union. That calculation shows the dimension's effect, but it is not an instruction to strip a label from independently emitted counters. A real aggregation must preserve counter meaning, handle resets and avoid colliding samples. It also removes the ability to distinguish replica behavior in that aggregate.

An ephemeral instance or pod label can replace an entire identity set without changing the number active in either window. Measure the union across windows and the rate at which new identities appear. A stable instantaneous graph therefore cannot establish stable retention cost. Track which label changes create the new sets and whether the distinction survives a deployment for a useful reason.

Spend label capacity on a question someone must answer

Before adding a dimension, write the operational question and the response it enables. A bounded route label can help identify an endpoint-specific failure. A tenant label may support a real isolation investigation, but requires a deliberate scope, access policy and capacity assessment. Customer-level detail may belong in a separately governed diagnostic path when it is unsuitable for broad always-on metrics.

The label review worksheet asks for the emitted label set, observed distinct count, unrestricted bound, turnover horizon and the question lost by removing each dimension. It leaves capacity thresholds blank because this fixture supplies no backend benchmark from which to derive them.

If the work includes implementing collection, dashboards and alert ownership, Pharos Production describes DevOps observability with metrics, traces and SLO-based alerting, including Prometheus and OpenTelemetry. Use the worksheet to specify the instrumentation and acceptance evidence for that engagement. The published service scope does not establish a cardinality reduction or cost saving for your system.

Use a normalized route template instead of a raw URL containing customer IDs. Request IDs, session tokens and arbitrary user input can create an expanding value space. Tenant identity may be necessary for a defined operational question, but that decision should include the tenant count, retention and access policy. Do not attach a sensitive identifier merely because it helps one investigation.

Keep the count separate from the performance claim

Cardinality is one input to operational load. Sample frequency, retention, label lengths, query patterns and the backend's representation can change resource requirements even when the distinct count is fixed. This analysis does not assign a universal bytes-per-series value or infer a price from a count.

After measuring real emitted identities, test the proposed instrumentation against the queries and retention your team needs. Record the exact metric family and collection boundary. A histogram or another representation that emits additional series requires its own inventory; the single-counter arithmetic here should not be copied onto a different metric type unchanged.

The review decision can then name both the benefit and the observed increase. In this fixture the tenant dimension adds 432 identities per window, a fourfold total, while replica turnover doubles the two-window union. Those are reproducible properties of the supplied rows. Whether they are acceptable requires evidence from the system that will store and query them.

Storage, ingestion frequency, retention, histogram representation, replication and query workload can all affect capacity. A hosted provider may bill a different subset from the series you count locally. Request the applicable billing definition and measure a representative workload. The fixture's fourfold identity increase is not a fourfold memory, latency or invoice measurement.

Treat histogram representation as part of the count

For a classic Prometheus histogram, each label combination can emit bucket series plus count and sum series. Count the actual emitted bucket set, including its infinite bucket where applicable. Summaries add their configured quantile series. Native histograms use a different representation, so a classic-bucket multiplication is not a valid estimate for them. Inspect the exported format before applying a capacity formula.

Diagnose the metric and then the multiplying label

In Prometheus, topk(10, count by (__name__) ({__name__=~"http_.*"})) ranks the currently selected series by metric name. Scope the selector to your job or metric family before running it. For one metric, count(count by (route) (http_requests_total)) counts observed route groups in that instant vector. Neither query measures the union of every historical series.

The Prometheus TSDB statistics endpoint provides additional head-series and label statistics. Compare that evidence with an exported inventory before and after a proposed instrumentation change. These examples describe query semantics. They were not executed against your monitoring server.

Reduce cardinality while preserving the required decision

Choose whether a dimension belongs in aggregated metrics, structured logs or traces. A request identifier is often better suited to a trace or log lookup. Exemplars can connect an aggregate observation to a trace under the backend's supported model. Do not drop a label until you have checked which alerts, aggregations and diagnostic questions depend on it.

Set an instrumentation budget with an owner, allowed value sets, expected combinations, churn horizon and a pre-release inventory check. Reject unexpected values at instrumentation boundaries or aggregate deliberately. Dropping labels downstream can merge series, so review collisions and aggregation semantics rather than assuming a relabel rule is lossless.

Check the collection and billing boundary of each platform

For CloudWatch dimensions, Datadog tags, Grafana/Mimir, OpenTelemetry and VictoriaMetrics, identify which attributes create a stored series, where cardinality limits apply and what happens to overflow. Backend terminology and limits differ. This article supplies a set-counting model and Prometheus diagnostic examples, rather than current prices or a configuration guide for every platform.

Sources

Documentation checked .

  1. Prometheus: time-series identity
  2. Prometheus: metric and label naming

Continue the conversation

Comments (3)

  1. Alex M.

    Stable hourly counts can hide replica-name turnover. Each window may contain the same number of series. The identities can still differ. I would compare their union across the windows. That exposes turnover which a chart of counts alone misses.

  2. Nora K.

    Before adding a tenant label, I would document the support question it answers so the cardinality review can weigh that benefit against the extra identities.

  3. Ethan B.

    Would the next experiment hold emitted identities constant while varying sample frequency? That would separate series growth from observation volume. Neither measure should be presented as a billing estimate.

Leave a comment

Your name and comment stay in this page and are cleared after the spam check.

10–2,000 characters. Keep the discussion relevant to this article.

Spam protection verification
Spam protection loads when you begin the form.

JavaScript is required to use this form and its spam protection.