Skip to content

Implement a Metrics Snapshot/Export API #22

Description

@grantfox-oss

Implement a Metrics Snapshot/Export API

Labels: hard observability Official Campaign Maybe Rewarded
Component: src/metrics.rs


Problem

SyncEngineMetrics (src/metrics.rs) is just a bag of AtomicUsize fields with no way to read them together as a consistent snapshot, no way to reset them (e.g. for periodic reporting windows), and no export format. An embedding wallet or relay node has no way to surface "how many payments are queued right now," "how many conflicts have been detected this week," etc. to a dashboard, a support ticket, or a telemetry pipeline — all of which matter for an org running a "Relay Node Monitoring Dashboard" per the top-level roadmap.

Requirements

  • Implement pub fn snapshot(&self) -> MetricsSnapshot, a plain-data struct capturing every counter's current value atomically-enough for reporting purposes (perfect cross-field atomicity isn't required — document that this is an approximate, independently-read snapshot, not a transactionally consistent one).
  • Implement a Prometheus text-exposition-format serializer (pub fn to_prometheus_text(&self) -> String) — this is a well-specified, simple text format; look up the spec rather than inventing your own.
  • Add whatever additional counters are missing but implied by other issues in this backlog (e.g. queue_evictions from issue Bound OutboundTxQueue Capacity with Priority-Aware Eviction #5, conflicts_detected/disputes_escalated are already present — audit SyncEngineMetrics for gaps against every module in src/ and fill them in).
  • Consider a reset/windowed-counting mode (e.g. snapshot_and_reset()) for callers who want periodic deltas rather than lifetime totals, and document when each is appropriate.

Acceptance Criteria

  • snapshot() returns accurate values matching the underlying atomics at call time.
  • to_prometheus_text() output is valid Prometheus exposition format (verify against the spec, e.g. correct # TYPE/# HELP lines and metric naming conventions).
  • Every counter that exists anywhere in this crate (including ones added by other landed issues) is represented in the snapshot — audit for completeness.
  • cargo fmt, cargo clippy -D warnings, and cargo test all pass.

Required Tests

  • test_snapshot_reflects_current_values
  • test_prometheus_output_is_well_formed
  • test_snapshot_and_reset_zeroes_counters

Notes

  • Independent of all other issues — purely additive to src/metrics.rs.
  • Estimated effort: small-medium. Good pickup for a contributor newer to Rust who still wants a genuinely useful, non-trivial task.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions