Reviewer · Observability
Verify metric correctness end-to-end
When adding or changing metrics, logs, or traces, treat them as part of the feature's correctness, not an afterthought. Verify end-to-end that the signal actually reaches an exported series/log and means what its name and help text say:
When adding or changing metrics, logs, or traces, treat them as part of the feature’s correctness, not an afterthought. Verify end-to-end that the signal actually reaches an exported series/log and means what its name and help text say:
- Follow naming conventions: use base units (e.g.
_bytes_total, not_kb_total) and name the metric after exactly what is measured (e.g. “uncompressed” vs “compressed” bytes). Document any approximation or rounding behavior (e.g. per-chunk rounding to the nearest KB) in the help text so consumers aren’t misled. - Keep a metric’s semantics consistent across all observations; don’t mix different measurement states (e.g. pre-encoding vs post-encoding sizes) in the same series without a flag/label distinguishing them.
- Handle edge cases (zero values, cache hits, divide-by-zero denominators) deliberately: decide whether to add a dedicated bucket/label or to skip the observation, and explain the choice in a comment so it isn’t mistaken for a bug later.
- Before removing or refactoring instrumentation (e.g. dropping a context capture, deleting a code path), check whether any counters, summaries, dashboards, or logs depend on it. If the removal is intentional, say so explicitly in the comment/PR description instead of a misleading claim like “nobody reads this.”
- If you introduce a new reason/label/status value, make sure it is actually wired into an incremented counter or logged somewhere reachable by operators — a constant that’s only used in an error string, with no corresponding
Inc()/log line, provides no real visibility. - Reuse existing reporting/discard-tracking functions instead of adding a parallel path for the same kind of event; this avoids divergent or duplicate series for what is conceptually the same signal.
- Record metrics as close as possible to the event they measure and independent of unrelated error branches, so counts aren’t accidentally skipped or delayed by early returns.
Example of a naming/unit fix applied during review:
// Before: non-standard unit, ambiguous bytes semantics
Name: "loki_compactor_tsdb_listed_chunk_kb_total"
// After: Prometheus base-unit convention, explicit about what's measured
Name: "loki_compactor_tsdb_listed_chunk_uncompressed_bytes_total"
Help: "... rounded per chunk to the nearest KB, so chunks under 512B count as 0."