Skip to content

feat: add interval-based metrics snapshotting#189

Merged
Jagadeeshftw merged 2 commits into
AnchorNet-Org:mainfrom
d3v-active:fix-metrics-interval
Jul 22, 2026
Merged

feat: add interval-based metrics snapshotting#189
Jagadeeshftw merged 2 commits into
AnchorNet-Org:mainfrom
d3v-active:fix-metrics-interval

Conversation

@d3v-active

Copy link
Copy Markdown
Contributor

Closes #148

This PR adds support for taking periodic snapshots of metrics on a fixed interval, independent of read traffic.

Changes Included:

  • Configuration: Added the METRICS_SNAPSHOT_INTERVAL_MS environment variable to configure the snapshot interval. By default, this is disabled to preserve previous behavior.
  • Metrics Router: Updated the metricsRouter factory (src/routes/metrics.ts) to accept an optional snapshotIntervalMs parameter. When configured, it kicks off a setInterval that records snapshots autonomously.
  • Graceful Shutdown: The interval timer is properly unref()'d to ensure it does not block the Node.js process from exiting gracefully.
  • Backward Compatibility: Read-triggered snapshots via GET / are fully preserved. This means manual polling will still capture the exact state upon read alongside the interval-based snapshots.
  • Testing: Added test coverage in src/routes/metrics.test.ts utilizing jest.useFakeTimers() to verify that the interval-driven snapshots are recorded accurately independent of any API calls.

@Jagadeeshftw
Jagadeeshftw merged commit 0dbe6b6 into AnchorNet-Org:main Jul 22, 2026
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.

routes/metrics.ts only records a history snapshot when a client happens to call GET /, producing sparse history if nobody polls

2 participants