Skip to content

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

Closed

Description

@thiras

Spotted while working #1247 (PR #1263).

Problem

Metrics::started() writes uptime_seconds = 0:

started => uptime_seconds.set(0);

But encode() unconditionally recomputes the same gauge from started_at on every scrape, before the registry renders:

pub fn encode(&self) -> anyhow::Result<String> {
    let uptime = i64::try_from(self.started_at.elapsed().as_secs()).unwrap_or(i64::MAX);
    self.decdn.uptime_seconds.set(uptime);
    ...

started_at is set in Metrics::new(), so the gauge is already correct without any help. The set(0) can never be observed: the only path to the value is encode(), which overwrites it first. There is exactly one caller (crates/node/src/runtime/mod.rs:456).

This is harmless today — the exported series is correct either way — but it is a method that reads as if it does something and does not. It also implies started() marks the start instant, which it does not; Metrics::new() does.

Options

  1. Delete started() and its one call site. Metrics::new() already stamps started_at, so uptime is live from construction.
  2. Make it real — have it re-stamp started_at, if the intent was that uptime should count from bring-up rather than from Metrics construction. Worth checking whether the gap between the two is meaningful (it spans config load and endpoint bring-up).

(1) unless someone knows a reason for (2). Either way, no exported-series change.

Acceptance

  • No recorder whose write is unobservable.
  • decdn_uptime_seconds still counts from the intended origin, with a test pinning which origin that is.

Activity

  1. added
    rust
    prio:low
    on Jul 17, 2026
  2. altanoruc commented on Jul 17, 2026

    @altanoruc
    Contributor

    Triage note for a later run: the unresolved decision is the uptime origin. The issue must choose whether uptime starts at Metrics::new() (delete started()) or runtime bring-up (make started() re-stamp the instant), since either is defensible and changes the required test.

  3. self-assigned this
    on Jul 19, 2026
  4. added a commit that references this issue on Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

prio:lowrust

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions