Repository navigation
refactor(node): collapse the 6 watcher downtime recorders into a second macro family (#1266) - #1276
Conversation
#1266) Collapse the three chain watchers' (slash, staker_set, origin_directory) byte-identical backoff/cycle-established recorder pairs onto a second table-macro, `watcher_downtime_recorders!`. These couldn't join #1263's `recorders!` because their bodies branch and touch `Metrics`'s own `Mutex<Option<Instant>>` state; the new macro carries the lock/edge-trigger shape once, with each row spelling out both method names (production hooks call them by exact name) and labelling the three struct-field idents. Behaviour-neutral: normalized `cargo expand` of the metrics module is token-identical for all six methods (differing only by the extra impl-block wrapper). encode()'s down-seconds recompute is left for a follow-up commit. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…tcher macro (#1266) Extend `watcher_downtime_recorders!` to also emit a private `refresh_watcher_down_seconds` that recomputes every watcher's `*_down_seconds` gauge from its `down_since` (poisoned lock -> i64::MAX, the alerting direction). encode() now calls it once instead of hand-repeating the three byte-identical recompute blocks, so adding a fourth watcher is one table row. Unlike the method collapse in the previous commit, this changes encode()'s tokens (the three inline blocks weren't uniform — different local names and wrapping), so it is gated by the down-seconds tests rather than an empty `cargo expand` diff. Adds the missing origin_directory down-seconds test to match the staker_set and slash guards and to exercise the shared recompute. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…acro doc (#1266) PR-review follow-ups. Adds `poisoned_down_since_reports_i64_max_not_zero`, which poisons a `*_watcher_down_since` lock (spawn+join, the `dispatch::tests` pattern) and asserts the shared `refresh_watcher_down_seconds` reports `i64::MAX` — the load-bearing "never mask an outage" invariant that was documented but unenforced across all three watchers before #1266 unified the recompute. It also pins single-scrape isolation: the two healthy gauges still read 0 in the same encode(). Also corrects the macro doc's "three struct-field idents" to note that only `down_since` lives on `Metrics`; `restarts`/`down_seconds` are on `self.decdn`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
Warning Review limit reached
Next review available in: 53 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Free Run ID: 📒 Files selected for processing (1)
WalkthroughThe change replaces three hand-written watcher downtime recorder pairs with a shared macro, centralizes downtime gauge refreshes, wires the three watcher metric sets, and adds coverage for origin-directory downtime and poisoned-lock fallback behavior. ChangesWatcher downtime metrics
Estimated code review effort: 4 (Complex) | ~45 minutes Note 🎁 Summarized by CodeRabbit FreeYour organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login. Comment |
There was a problem hiding this comment.
Pull request overview
This PR refactors decdn-node’s internal metrics recorder layer by collapsing the remaining six chain-watcher downtime recorder methods (*_backoff_started / *_cycle_established for slash, staker_set, and origin_directory) into a dedicated watcher_downtime_recorders! macro family, and consolidates the scrape-time “down seconds” recomputation into a single helper invoked from Metrics::encode().
Changes:
- Introduces
watcher_downtime_recorders!to generate the six watcher downtime recorder methods while preserving exact method names used by production hooks. - Consolidates the three duplicated
*_down_secondsrecompute blocks into a sharedrefresh_watcher_down_seconds()called once per scrape. - Adds tests to cover
origin_directorydowntime semantics and to pin the poisoned-lock →i64::MAXbehavior.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…keeps climbing" (#1276 review) The three "keeps climbing" phrasings attached to the *poison* case were imprecise: a poisoned `down_since` lock is sticky, so `refresh_watcher_down_seconds` hits its `Err(_) => i64::MAX` arm on every scrape and the gauge is pinned at `i64::MAX` — "keeps climbing" describes the distinct healthy-lock ongoing-outage path where `elapsed()` grows. Reword the macro doc, the slash backoff doc, and the staker_set cycle-established doc to say the poison fallback reports `i64::MAX`, matching the already-correct staker_set backoff doc, the field docs, and the `poisoned_down_since_reports_i64_max_not_zero` test. Doc-only; no behaviour or metric-series change. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Coverage reportTotal: 81.50% (was 81.49%, ● 0.00%) — 48593/59626 lines
History
|
Closes #1266.
Finishes the thread #1263 opened: it collapsed 134 trivial recorders onto the
recorders!table but deliberately scoped out six survivors — the three chain watchers' (slash,staker_set,origin_directory) downtime recorder pairs, which branch and touchMetrics's ownMutex<Option<Instant>>state and so couldn't use the single-forward macro.What changed (
crates/node/src/metrics.rsonly)watcher_downtime_recorders!macro family. Each row spells out both method names (production hooks call them by exact name; nopaste) and labels the three backing field idents. Generates the*_backoff_started/*_cycle_establishedpair per watcher.encode()consolidation. The macro also emits a privaterefresh_watcher_down_seconds;encode()calls it once instead of hand-repeating three byte-identical down-seconds recompute blocks. Adding a fourth watcher is now one table row instead of five edits across two functions.origin_directory_watcher_down_seconds_tracks_true_downtime(closes a coverage asymmetry) andpoisoned_down_since_reports_i64_max_not_zero(pins the "poison →i64::MAX, never mask an outage" invariant across all three watchers via the shared recompute, plus single-scrape isolation).Correctness — checked, not asserted
The three commits are sequenced to keep the proofs clean (the #1263 discipline):
cargo expand: all six generated methods are token-identical to the deleted hand-written ones (only the extraimplwrapper differs).encode()collapse — intentionally token-changing (the three inline blocks weren't uniform), so it is test-gated by the down-seconds guards rather than an empty diff.Verification
cargo build,cargo clippy --all-targets,cargo fmt --check,cargo doc -D warnings, and the fulldecdn-nodesuite (837 tests) all pass. No exported metric series changes.Review
A four-agent review (code / tests / comments / silent-failure) found no critical or important issues; the two highest-value suggestions (the poison test and the doc fix) are folded into the third commit.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests