fix(observability): sample rollup misses per reason per interval, not 1-in-512 - #207
tonyalaribe wants to merge 1 commit into
Conversation
… 1-in-512 A fixed sampling ratio goes silent exactly when the diagnostic becomes useful. The 1-in-512 constant was right for the regime it was written in -- the call site records ~2.7 misses/second, where it yields ~19 samples/hour. Prod 2026-08-21 ran ~170 misses/hour, so it fired about once every three hours and a 30-minute diagnostic window contained nothing at all. That matters because the surviving misses at a low rate are the interesting ones. The window that prompted this was 27% unknown_filter -- a gap in the matcher, and the largest addressable category -- against 37% filter_not_eligible, which is a correct refusal. A global sampler spends its budget on whichever reason is loudest. Now: at most one sample per MissReason per 60s. Rate-based, so it cannot go quiet as traffic falls; per-reason, so a loud refusal cannot crowd out a rare actionable one. MissReason::ALL is declared [Self; Self::COUNT], so adding a variant fails the build rather than silently indexing out of range. The test sweeps every reason and asserts each samples once then rate-limits. Verified it FAILS against the old ratio sampler.
|
Reviewed the diff. This is a well-scoped, well-motivated change — the per-reason/rate-based redesign is the right fix for the problem described (a fixed ratio going silent as traffic drops), the atomic CAS logic in 1. The The doc comments (and the PR description) claim adding a new
Contrast with Suggest either deriving 2. Test only covers "samples once," not "resamples after the interval" (src/observability.rs:1247-1254)
Minor/non-blocking: the Nothing else stood out — no security concerns (all inputs are internal enum values, not attacker-controlled), and the per-reason design genuinely solves the "loud reason crowds out rare actionable one" problem described in the PR. |
The problem
rollup_miss_sampledrenders the refused plan and is the tool that previously turned a "97% missing_project" mystery into a one-line fix. It currently logs nothing.That constant was right for the regime it was written in — the call site records ~2.7 misses/second (~9,700/hour), where 1:512 yields ~19 samples/hour. Prod on 2026-08-21 ran ~170 misses/hour, so it fires about once every three hours, and a 30-minute diagnostic window contained zero events.
A fixed sampling ratio goes silent exactly when the diagnostic becomes most useful. While misses are a flood, 1:512 is right. Once they are a trickle, the survivors are the interesting ones — and the sampler hides them.
Why per-reason and not just a smaller constant
The actionable reason is usually not the loudest one. The window that prompted this:
A global sampler spends its budget on whichever reason dominates. Lowering the constant fixes today's rate and breaks again at the next traffic level.
The change
sample_rollup_miss(reason)— at most one sample perMissReasonper 60s. Rate-based, so it cannot go quiet as traffic falls; per-reason, so a loud refusal cannot crowd out a rare actionable one.MissReason::ALLis declared[Self; Self::COUNT], so adding a variant fails the build rather than silently indexing out of range — a compile-time guarantee rather than a test that can rot.database/mod.rsthat borrow this limiter now pass the semantically closest reason (IncompleteCoverage,TinyInterior).Verification
MissReason::ALL: every reason samples once, then rate-limitscargo lintclean (only pre-existing vendoredwalrus-rustwarnings);cargo fmtappliedNote on scope
Deliberately small and observability-only — it changes no query or maintenance behaviour. Context for why this matters now is in #206: routing hit rate reads ~7% at some hours versus 91.5% at others, and this sampler is the blocker on diagnosing which, because it is the only thing that renders the plan that was refused.