To keep the architecture evolvable without sacrificing reliability, drop offending series at scrape time via `metric_relabel_configs`, enforce `sample_limit`, normalize routes to templates (`/orders/{id}/items`), and move per-user/trace dimensions to logs and traces.
TL;DR30-second simplified summary▾
Core Mechanics: Prometheus stores every unique (metric_name, label_set) as an independent time series in its in-memory TSDB head block (~5-8 KB RAM per active series).
Visual & Structural Flow: Depicts Unbounded Labels (18.4M Series) vs. Relabeling + Route Templates (App Pods (50) -> Scrape Relabeler -> TSDB Head (64GB)); Low-Cardinality Metrics vs. High-Cardinality Logs & Traces (HTTP Middleware -> Scrape Guard -> Prometheus TSDB -> Logs / OTel Traces).
Trade-Offs & Production: Two common mistakes prolong the outage: Using action: labeldrop on user_id: Stripping user_id merges 1,000 distinct series with identical timestamps into one series. Stabilize Prometheus immediately and prevent future regressions: Immediate Stabilization: Add metric_relabel_configs (action: drop on http_server_requests_seconds.*.
Failure Modes & Application: Cardinality limits protect every production observability platform: Multi-Tenant Prometheus / Mimir / Thanos: Enforce per-tenant max_series_per_metric and sample_limit at the distributor.
Why Prometheus TSDB cannot survive unbounded label cardinality.
Why this matters: The mechanism: understand how Why Prometheus TSDB cannot survive unbounded label cardinality works from first principles.
Think of Why Prometheus TSDB cannot survive unbounded label cardinality as the intuition layer for Controlling Prometheus High-Cardinality Metrics: The mechanism: understand how Why Prometheus TSDB cannot survive unbounded label cardinality works from first principles.
Prometheus stores every unique (metric_name, label_set) as an independent time series in its in-memory TSDB head block (~5-8 KB RAM per active series). Worse, a 15-bucket histogram emits 18 series (15 le buckets + +Inf + _sum + _count) per label tuple—so a single unbounded label like user_id or raw path multiplies memory linearly into an instant OOM.
18.4M active series, 92 GB RAM demand, and WAL-replay OOM loops.
Why this matters: The problem: see what breaks without 18.4M active series, 92 GB RAM demand, and WAL-replay OOM loops under real concurrency or scale.
With 1,022,000 unique (user_id, trace_id, path) tuples × 18 histogram series = 18.4M active series:
- 92 GB Head Block: Exceeds the
64 GBpod limit, triggeringExit Code 137every 9 minutes during head-block compaction. - WAL Replay OOM Loop: Even after fixing app code, Prometheus crashes on restart replaying the poisoned 18M-series WAL from disk.
- Alert Blindness: Grafana and Alertmanager go completely dark during an active outage.
Unbounded Labels (18.4M Series) vs. Relabeling + Route Templates
Dropping dynamic labels and normalizing routes shrinks active series by 96% (from 18.4M to 720K / 3.6 GB).
- Problem
- How to implement Controlling Prometheus High-Cardinality Metrics without hitting unbounded tail latency, state divergence, or operational fragility.
- Naive Solution
- Use a single unpartitioned path with unbounded retries and synchronous global coordination.
- Why It Fails
- Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
- Alternatives
- Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
- Engineering Decision
- To keep the architecture evolvable without sacrificing reliability, drop offending series at scrape time via
metric_relabel_configs, enforcesample_limit, normalize routes to templates (/orders/{id}/items), and move per-user/trace dimensions to logs and traces. - Trade-Offs
- Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
When Controlling Prometheus High-Cardinality Metrics experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?
Why `labeldrop` alone causes duplicate-sample collisions.
Why this matters: The problem: see what breaks without Why labeldrop alone causes duplicate-sample collisions under real concurrency or scale.
Two common mistakes prolong the outage:
- Using
action: labeldroponuser_id: Strippinguser_idmerges1,000distinct series with identical timestamps into one series, causingduplicate sample for timestampingestion errors; you mustaction: dropthe broken metric until the app is fixed. - Ignoring 404 Scanner Paths: Vulnerability scanners hitting
/wp-login.phpor/admin/123create millions ofpathvalues unless unmatched routes map toroute="UNMATCHED".
Why `labeldrop` alone causes duplicate-sample collisions
Enterprise solution: Scrape-Time Guardrails + Route Normalization.
Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.
Stabilize Prometheus immediately and prevent future regressions:
- Immediate Stabilization: Add
metric_relabel_configs(action: droponhttp_server_requests_seconds.*temporarily), archive/wipe the poisonedwal/directory, and setsample_limit: 50000per scrape target so one bad deploy never OOMs the server. - Bounded Instrumentation: Use framework route templates (
40 routes × 5 status_classes × 4 methods × 50 pods × 18 = 720,000 series ≈ 3.6 GB), map 404s toUNMATCHED, and moveuser_id/trace_idto structured logs and OpenTelemetry traces (or exemplars).
Low-Cardinality Metrics vs. High-Cardinality Logs & Traces
Keeping Prometheus labels bounded to route/method/status_class cuts RAM 96% while exemplars link to traces.
scrape_configs:
- job_name: 'order-service'
sample_limit: 50000 # Reject runaway targets before TSDB OOMs
metric_relabel_configs:
# Emergency drop while broken app version rolls out
- source_labels: [__name__]
regex: 'http_server_requests_seconds.*'
action: drop
Where metric cardinality governance is applied.
Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.
Cardinality limits protect every production observability platform:
- Multi-Tenant Prometheus / Mimir / Thanos: Enforce per-tenant
max_series_per_metricandsample_limitat the distributor. - OpenTelemetry Exemplars: Attach
trace_idas an exemplar metadata sample on histogram buckets instead of as a metric label.
Practice: Make the trade-off yourself.
Why does `action: labeldrop` on `user_id` often fail as an emergency Prometheus fix, and what should you do instead?