Skip to content

feat(metrics): HTTP metrics middleware with per-minute rollup table#127

Open
anoop-narang wants to merge 7 commits intomainfrom
feat/metrics-middleware
Open

feat(metrics): HTTP metrics middleware with per-minute rollup table#127
anoop-narang wants to merge 7 commits intomainfrom
feat/metrics-middleware

Conversation

@anoop-narang
Copy link
Contributor

Summary

  • Adds a metrics_request_rollup_minute table (v7 migration, SQLite + Postgres) for fast per-minute request/error counts and latency aggregates
  • Introduces a src/metrics module with MetricsEvent, RollupBucket, and a background MetricsWorker that accumulates events in memory and flushes to the DB every 30 s via additive UPSERT
  • Adds an Axum metrics_middleware (registered in the Tower stack) that captures route template, method, status code, and wall-clock latency per request — using try_send so the hot path is never blocked
  • Wires the channel and worker into RuntimeEngine with clean shutdown support (final flush on drop)

Multi-instance safe: the UPSERT is additive, so multiple runtimedb instances sharing one catalog DB sum their counts correctly.
No double-counting: the in-memory bucket map is cleared after every flush.
p50/p99 percentiles for individual queries are already available via query_runs.execution_time_ms; the rollup table covers mean/min/max across all endpoints.

Test plan

  • cargo test --lib — all 404 unit tests pass (includes new worker accumulation/bucket/shutdown tests)
  • cargo test --test result_persistence_tests — 22 integration tests pass
  • cargo clippy and cargo fmt --check — clean
  • Manual: run server, fire requests, wait ~30 s, query SELECT * FROM metrics_request_rollup_minute ORDER BY minute DESC to verify rows populate with correct counts and latency fields

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.

1 participant