Commit 2af3ba0
authored
feat(metrics): pre-seed known channels at zero on startup (#165)
* feat(metrics): pre-seed known channels at zero on startup
Without this, Prometheus only creates a series for cryptify_uploads_total
{channel="X"} when the first upload from channel X lands. PromQL
increase(...[1h]) over that series returns nothing because the earliest
sample is already non-zero — dashboards under-report low-volume channels
for an hour after each pod restart.
Pre-seeds website, staging-website, outlook, thunderbird, api, unknown
to 0 in Metrics::new(), so the full label set is visible from the first
scrape and increase() can compute deltas honestly.
The previous render-time "if empty, emit unknown=0" fallback is now
effectively dead (the map is never empty after new()), but left in place
defensively against any future code path that constructs Metrics via
Default rather than new().
* refactor(metrics): route Default through new() so they can't diverge
Address dobby's non-blocking observation on #165: with #[derive(Default)]
still in place, Metrics::default() produced an empty-channels object
while Metrics::new() pre-seeded — a footgun for a future contributor
who reaches for ::default() in a generic context or test helper.
Drops the derive, refactors new() to build the maps directly (no
internal lock dance), and adds a manual `impl Default for Metrics`
that just calls Self::new(). The two construction paths now produce
identical objects.
All 13 metrics tests still pass.1 parent ffeedb6 commit 2af3ba0
1 file changed
Lines changed: 49 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
23 | 37 | | |
24 | 38 | | |
25 | 39 | | |
26 | 40 | | |
27 | 41 | | |
28 | | - | |
29 | 42 | | |
30 | 43 | | |
31 | 44 | | |
| |||
34 | 47 | | |
35 | 48 | | |
36 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
37 | 61 | | |
38 | 62 | | |
39 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
40 | 76 | | |
41 | 77 | | |
42 | 78 | | |
| |||
325 | 361 | | |
326 | 362 | | |
327 | 363 | | |
328 | | - | |
| 364 | + | |
329 | 365 | | |
330 | 366 | | |
331 | | - | |
332 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
333 | 377 | | |
334 | 378 | | |
335 | 379 | | |
| |||
0 commit comments