feat(metrics): HTTP metrics middleware with per-minute rollup table#127
Open
anoop-narang wants to merge 7 commits intomainfrom
Open
feat(metrics): HTTP metrics middleware with per-minute rollup table#127anoop-narang wants to merge 7 commits intomainfrom
anoop-narang wants to merge 7 commits intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
metrics_request_rollup_minutetable (v7 migration, SQLite + Postgres) for fast per-minute request/error counts and latency aggregatessrc/metricsmodule withMetricsEvent,RollupBucket, and a backgroundMetricsWorkerthat accumulates events in memory and flushes to the DB every 30 s via additive UPSERTmetrics_middleware(registered in the Tower stack) that captures route template, method, status code, and wall-clock latency per request — usingtry_sendso the hot path is never blockedRuntimeEnginewith 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 passcargo clippyandcargo fmt --check— cleanSELECT * FROM metrics_request_rollup_minute ORDER BY minute DESCto verify rows populate with correct counts and latency fields