Skip to content

refactor(node): remove the no-op Metrics::started() recorder (#1264) - #1324

Merged
thiras merged 2 commits into
mainfrom
refactor/1264-metrics-started-noop
Jul 19, 2026
Merged

thiras merged 2 commits into
mainfrom
refactor/1264-metrics-started-noop

Conversation

@thiras

@thiras thiras commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1264.

Metrics::started() was a macro-generated recorder that wrote node_uptime_seconds.set(0), but Metrics::encode() unconditionally recomputes that same gauge from started_at on every scrape, before the registry renders — so the set(0) could never be observed. The method also misled: it read as if it marked the start instant, but Metrics::new() already stamps started_at. Its single call site (build_infra) sat on the line immediately after Metrics::new(), so there was no meaningful gap — "count from bring-up" and "count from construction" were identical, and option 2 from the issue (re-stamp) had nothing to re-stamp. Deletion is the correct resolution; the exported decdn_node_uptime_seconds series is unchanged.

Changes

  • Remove the started => node_uptime_seconds.set(0); row from the recorders! macro table (crates/node/src/metrics.rs) — this was the entire definition of the generated method.
  • Remove the single call site node_metrics.started(); in build_infra (crates/node/src/runtime/mod.rs). The removal is enforced by a compile guarantee — the method no longer exists.
  • Reword the recorders! doc that cited started as its semantic-rename example (keeping the still-valid connection_opened → active_connections example), and replace the brittle hand-maintained "45 of them" divergence count with a non-brittle qualifier.
  • Add a regression test uptime_counts_from_construction_without_any_bring_up_hook that backdates started_at and scrapes without any hook, pinning that uptime counts from construction and guarding against a re-introduced pre-scrape write. The pre-existing key_rotation_metrics_export_canonical_names_at_zero (uptime at 0 on fresh construction) is the complementary guard.

Verification

  • cargo build -p decdn-node — clean
  • cargo clippy -p decdn-node --all-targets — clean
  • cargo fmt -- --check — clean
  • cargo nextest run -p decdn-node — 866 passed, 0 failed (incl. the new test)
  • grep -rn '\.started()' crates/node/src — no stray calls

Review

Reviewed by the pr-review-toolkit agents (code-reviewer, comment-analyzer, pr-test-analyzer). One doc-accuracy finding (an incorrect "most entries" qualifier) was caught and fixed before this PR; all other checks came back clean.

🤖 Generated with Claude Code

`Metrics::started()` was a macro-generated recorder that wrote
`node_uptime_seconds.set(0)`, but `Metrics::encode()` recomputes that gauge
from `started_at` on every scrape, before the registry renders — so the write
was never observable. Its single call site sat on the line immediately after
`Metrics::new()`, so removing it changes nothing about when uptime counts from:
`new()` already stamps `started_at`. The exported `decdn_node_uptime_seconds`
series is unchanged.

- Drop the `started => node_uptime_seconds.set(0);` row from the `recorders!`
  table and its one call site in `build_infra`.
- Reword the `recorders!` doc that used `started` as its example and replace
  the brittle hand-maintained "45 of them" count with a non-brittle qualifier.
- Add a regression test pinning that uptime derives from construction
  (`started_at`) with no bring-up hook.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 19, 2026 17:05
@coderabbitai

coderabbitai Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@thiras, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Free

Run ID: 86b44e09-d7c9-40e7-a96b-1d7554df218f

📥 Commits

Reviewing files that changed from the base of the PR and between 44a0d7a and 54aac18.

📒 Files selected for processing (2)
  • crates/node/src/metrics.rs
  • crates/node/src/runtime/mod.rs

Note

🎁 Summarized by CodeRabbit Free

Your 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 @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request removes the redundant started metric recorder and its corresponding initialization call, relying instead on started_at set during construction to compute node uptime. A regression test was added to verify this behavior. The review feedback suggests reducing the backdated duration in the test from 2 hours to 10 seconds to avoid potential test failures on environments with low system uptime.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/node/src/metrics.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes a misleading, effectively unobservable metrics recorder (Metrics::started()) and its lone call site, relying instead on the already-authoritative started_at timestamp that Metrics::encode() uses to compute decdn_node_uptime_seconds on every scrape. It also adds a regression test to pin that uptime counts from construction and to prevent reintroducing pre-scrape writes that can’t be observed.

Changes:

  • Delete the macro-generated Metrics::started() recorder and remove its only call site during node bring-up.
  • Update recorders! macro documentation to remove the obsolete started example and avoid brittle divergence-count claims.
  • Add a regression test asserting uptime derives from started_at without any bring-up hook.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/node/src/runtime/mod.rs Removes the now-nonexistent node_metrics.started() call from bring-up.
crates/node/src/metrics.rs Drops the started recorder entry, updates recorder docs, and adds an uptime regression test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/node/src/metrics.rs Resolved
@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 81.50% (was 81.50%, ▲ +0.01%) — 49932/61265 lines

File Coverage Lines Δ
crates/node/src/metrics.rs 93.89% 922/982 ▲ +0.09%
crates/node/src/runtime/mod.rs 45.82% 1081/2359 ▲ +0.02%
History
Commit Total Δ vs base
58696aa 81.50% ● 0.00%
54aac18 (HEAD) 81.50% ▲ +0.01%

Address PR review: the test backdated started_at by 2h and asserted an exact
7200s. `Instant` is monotonic (boot-relative), so checked_sub(2h) underflows to
None on a host with <2h uptime (ephemeral CI), and an exact as_secs() assertion
races scrape-time truncation. Use a small 60s backdate and a range assertion,
via a new metric_value() helper (whole-line discipline mirroring
has_metric_line). Still fails hard if uptime resets to 0 — the actual regression.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras merged commit 358cea6 into main Jul 19, 2026
23 checks passed
@thiras
thiras deleted the refactor/1264-metrics-started-noop branch July 19, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(node): Metrics::started() is a no-op — encode() overwrites uptime_seconds

2 participants