Synthesis and Self-Test

Synthesis

Cardinality is the unit of cost everywhere

The same mistake has the same cause in every store. Adding user_id creates one new series per user in Prometheus, which means a head-block entry costing a few KB of RAM each (see Prometheus). The same label creates one new stream per user in Loki, so you get millions of tiny chunks (see Log pipelines and storage). In Datadog it is one new custom metric per tag set, multiplied by 5 for a distribution (see Cost and vendors). In the OTel SDK it hits the per-instrument cardinality limit of 2000, and the excess is quietly folded into an otel.metric.overflow series (see OpenTelemetry). The formula from the Metrics part (the product of each label's distinct-value counts) is the bill in all four cases. That is why the cheapest control is to drop the label at the source (see OTel Collector), not to buy a bigger backend (see Scaling Prometheus).

Measure from 100%, sample only what you store

Traces are sampled (see Traces), so any number computed from stored traces is biased. A keep-all-errors tail policy makes the error rate look several times worse than it is. That is why span metrics must come from a connector placed before the sampler (see OTel Collector), and why SLO alerts are built on histogram counters that saw every request (see Alerting and SLOs). Sampling decides which stories you keep, never which numbers you know. The tracing guide reaches the same conclusion from the opposite direction.

Percentiles do not add, buckets do

A latency SLI is only correct if it can be aggregated across pods and over time. Summaries compute quantiles on the client, and averaging those quantiles is meaningless: 19 pods at 100 ms and one at 4 s average to about 295 ms, which hides the outage (see Metrics). Histograms keep cumulative bucket counters, which do add up. So the order in PromQL is fixed: rate each bucket, sum by (le), then histogram_quantile (see PromQL). Even then, the answer is interpolated inside a bucket, so the bucket boundaries should sit where the SLO threshold is (see RED, USE and SLOs). The good-events/valid-events SLI avoids interpolation entirely, because it reads one bucket at exactly the threshold.

Correlation is a schema decision, made in advance

The incident in the Incident walkthrough part was solved by lookups, not searches, because every signal shared keys. Those were resource attributes from semantic conventions (service.name, service.version, deployment.environment.name, see OpenTelemetry), plus trace_id in log lines and in exemplars (see Beyond the three pillars). None of that can be added during an incident. The value of OpenTelemetry is not mainly that it is vendor-neutral. It forces all four signals to describe the same entity with the same names, and that is what makes them joinable.

The read path is a load you design, too

Grafana stores nothing (see Grafana). Each panel refresh is a PromQL or LogQL query, and a 30-panel dashboard on a 10-second refresh, opened by 50 engineers during an incident, puts real load on the backends at exactly the moment you need them. Recording rules (see PromQL) precompute the expensive aggregates. Query frontends split and cache queries (see Scaling Prometheus). Downsampling (see Scaling Prometheus) makes long ranges cheap, but it does not save space. Write-path cost is set by cardinality; read-path cost is set by how dashboards are built.

Self-Test

Question 1

Define a log, a metric and a trace by what each one throws away. Then: a dashboard shows avg(http_p99_seconds) across 20 pods. 19 pods are at 100 ms and one is at 4 s. What does the panel show, why is it wrong, and what should the instrumentation and the query be instead?

Show answer

A log keeps every detail of one event and throws away nothing, so its cost scales with traffic × bytes. A metric throws away the individual events and keeps one number per time bucket per label set, so its cost scales with cardinality. A trace throws away the payloads and keeps the causal shape of one request (see the parts from What observability is to Traces).

The panel shows (19 × 0.1 + 4) / 20 ≈ 0.295 s, comfortably under a 500 ms alert threshold, while one pod in twenty is serving 4-second responses. Percentiles cannot be averaged: a p99 is a rank within a distribution, and the average of ranks from different distributions is not a rank of anything. If the per-pod p99 came from a summary, it cannot be fixed at query time at all, because the quantile was computed on the client (see Metrics). The fix is to instrument a histogram and aggregate its bucket counters before taking the quantile: histogram_quantile(0.99, sum by (le) (rate(http_server_request_duration_seconds_bucket[5m]))). Keep le in the by clause, and take rate before sum (see PromQL). The result is still interpolated inside one bucket, so put a bucket boundary at your SLO threshold. Better still, express the SLI as good-events/valid-events using the le bucket at the threshold, which needs no interpolation (see RED, USE and SLOs).

Question 2

A recording rule computes sum(http_requests_total), and a dashboard then graphs rate() of that recorded series. Two pods sit at 1000 and 2000 requests, and one restarts. What does the graph show, and why? Separately: why does increase() return 193.33 on a counter that only ever moves in whole numbers?

Show answer

The sum drops from 3000 to about 2010 when the restarted pod's counter goes back to near zero. rate() sees a decrease in a counter, treats it as a counter reset, and assumes the counter restarted from 0. It therefore counts the whole post-reset value, about 2010, as new increase instead of the roughly 20 requests that actually happened, which shows up as a spike of about 100×. Reset detection only works on the raw per-process series, which is why the rule is "rate first, then sum". A recording rule should store sum by (job) (rate(http_requests_total[5m])), never the raw sum (see PromQL, see Prometheus).

increase() is rate() × window, and rate() extrapolates. The samples inside a 60 s window span only, say, 45 s from the first to the last. Prometheus measures the increase across those samples (145) and scales it to the full window (145 × 60/45 = 193.33), within limits on how far it extrapolates towards the window edges. So the result is an estimate, not a count. It also misses a brand-new series' first increment, because there is no earlier sample to compare against (see PromQL).

Question 3

A developer adds user_id (50,000 active users) as an attribute on a latency histogram with 12 buckets. Trace what happens in the OTel SDK, in Prometheus, and on a Datadog bill. Which of the three fails silently, and why is that the worst one?

Show answer

Series count first. A classic histogram with 12 buckets (11 finite bounds plus +Inf) produces 14 series per label combination: the 12 bucket series plus _sum and _count. Multiply that by 50,000 users, then by every existing label combination (see Metrics).

OTel SDK: the per-instrument cardinality limit (2000 by default) is reached. Further attribute sets are folded into one series tagged otel.metric.overflow=true. Nothing crashes, but per-user and per-endpoint numbers are now wrong (see OpenTelemetry). Prometheus: every new label set is a new head series costing a few KB of RAM, so memory climbs until the server is OOM-killed. Its WAL replay on restart then takes minutes, during which there is no alerting (see Prometheus). Datadog: each unique tag set is a custom metric, and a distribution counts 5 per set, so this is about 250,000 or more custom metrics on the bill (see Cost and vendors).

The SDK overflow is the worst because it fails silently and plausibly. An OOM pages someone and a bill gets noticed, but a falsified number that still looks like a normal time series gets trusted. The real fix is upstream: user_id belongs on spans, wide events or log lines, which are signals built for high cardinality (see Beyond the three pillars). On metrics, drop it with an OTel View or metric_relabel_configs (see OTel Collector, see Prometheus).

Question 4

Your alert is errors / requests > 0.05. During a full outage the service stopped receiving traffic and stopped reporting, and the alert never fired. Explain exactly why. Then: on a 99.9% SLO over 30 days, how fast does the 14.4×, 1-hour/5-minute burn-rate rule fire during a total outage, and what does Alertmanager do between "firing" and the page reaching the phone?

Show answer

Two mechanisms. If the series disappeared because the target went away, the expression returns an empty vector. Empty is not "false", it is "no alert instances", so nothing ever becomes pending. If the service is up but traffic dropped to zero, then 0/0 is NaN, and every comparison with NaN is false. The fix is to alert on absence and on reachability as well: up == 0, absent(...) or absent_over_time(...), plus a traffic-drop alert, and an always-firing Watchdog alert routed to a dead-man's switch so you notice when the alerting pipeline itself dies (see Alerting and SLOs).

Burn rate during a total outage is 1 / (1 − 0.999) = 1000×. The 1-hour window crosses 14.4× once 14.4/1000 = 1.44% of the hour is bad, which is about 52 seconds. The 5-minute window crosses even sooner. After that come the rule's for duration, if any, and the evaluation interval. A 14.4× burn exhausts a 30-day budget in 30/14.4 ≈ 2.1 days, which is why it pages (see Alerting and SLOs).

Inside Alertmanager the alert is routed down the tree to a receiver, then placed in an aggregation group, which waits group_wait before its first notification. On each flush, inhibition rules are checked, then silences, then the notification log dedups against what was already sent, and finally the receiver is called. In an HA cluster every replica runs this pipeline. Gossip shares only silences and the notification log, so every Prometheus must send to every Alertmanager, and delivery is at-least-once (see Alerting and SLOs).

Question 5

Your Collector gateway tier runs tail_sampling (keep all errors, 5% of the rest) and then a spanmetrics connector. The RED dashboard built on those span metrics shows a 30% error rate, while the load balancer shows 1.5%. There are 4 gateway replicas. Find every bug.

Show answer

Bug 1, sampling bias: span metrics are computed after the sampler, so they count only the surviving traces. Errors are kept at 100% and successes at 5%, so the error ratio is inflated by about 20×. The connector must sit before tail_sampling, in the pipeline that sees every span (see OTel Collector, see Beyond the three pillars). Bug 2, colliding series: four replicas each emit cumulative counters with identical label sets. When they are remote-written into one series, the samples interleave, which looks like constant counter resets to rate(). Add a per-replica label such as collector.instance or service.instance.id and sum across replicas in PromQL (see OTel Collector, see PromQL). Bug 3, possibly wrong attribution: if k8sattributes runs in the gateway, it identifies pods by connection IP, which is the agent's IP, so pod metadata is wrong. Run it in the node agent (see OTel Collector). Related trap: without trace-ID-aware load balancing into the tail tier (the loadbalancing exporter keyed on traceID), spans from one trace reach different replicas, and each replica makes its decision on a partial trace (see OTel Collector; the Distributed Tracing guide).

Question 6

To speed up "find the logs for this trace", someone proposes making trace_id a Loki label. Someone else says "just use Elasticsearch, it indexes everything". Explain what each proposal does to the storage engine, and what you would do instead.

Show answer

In Loki, a stream is one unique label set, and only labels are indexed. Making trace_id a label creates one stream per request: millions of tiny chunks, an exploding index, ingesters holding millions of open streams, and object storage full of small objects. The default limit of 15 index labels per stream exists to steer people away from this (see Log pipelines and storage). Elasticsearch would make the lookup fast, because it builds an inverted index over every field. But you pay for that index on every byte written, and it can approach the size of the raw data. Mapping explosions and shard sizing then become the operational problem (see Log pipelines and storage).

Instead, keep trace_id as a field in the structured line, or as Loki structured metadata (TSDB index, schema v13). Query it by first narrowing with cheap labels such as {service_name="inventory-svc"}, over a time window you already know from the trace, then filtering with | json | trace_id="…". The trace gives you the service and the time range, so the grep only touches a few chunks. In Grafana, wire this up as a derived field or a trace-to-logs link, so it takes one click (see Grafana, see Incident walkthrough). The general principle: index what you select by, and scan for what you look for.