Add request latency histogram metric - #872
Open
mikmatko wants to merge 1 commit into
Open
Conversation
gi0baro
requested changes
Jul 20, 2026
gi0baro
left a comment
Member
There was a problem hiding this comment.
A few things:
- the implementation is not measuring the actual e2e latency, as on responses wrapping an async stream the time to send the actual bytes is outside that future block
- not sure why the naming for the is
req/requestinstead of response - I generally don't allow AI generated code to be merged in Granian, especially if it's added as-is, without the proper refinements (eg: the giant-wall-of-comments is just useless and awful).
Expose granian_request_duration_seconds, a per-worker Prometheus histogram of request durations, using OpenTelemetry-aligned buckets. Static-file requests are excluded so the metric reflects application handling only. Duration is measured end-to-end: a TimedBody response-body wrapper records the elapsed time once the full response body has been sent (or on drop), so streaming responses are measured to the last byte rather than to time-to-first-byte. Adds a DurationHistogram to WorkerMetrics, a MetricValue::Hist variant for IPC transport, histogram exposition in the aggregator, and integration tests covering exposition, counts, static exclusion, streaming end-to-end timing and the empty case. Co-authored-by: GitHub Copilot <[email protected]>
mikmatko
force-pushed
the
latency_metrics
branch
from
July 20, 2026 15:33
b4ba3e9 to
afb1d2a
Compare
Author
|
Thank you for the comments. I've pushed changes.
I believe streaming responses are now correctly tracked.
OTEL convention, seemingly a "standard" thing for Prometheus metrics.
That's fair :) I've reduced the verbosity of the comments. Personally I think the overly verbose comments are a good thing - it helps a lot when jumping to an unknown codebase. A lot of people read and comprehend natural language faster than code. But yes, it's verbose, maybe even awful, but not useless :) |
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.
Solves #871
Note: AI implemented. I'm not familiar with Rust. I've reviewed the code. I apologize if this is seen as too much AI slop :)
Expose granian_request_duration_seconds, a per-worker Prometheus histogram of application request durations. Static-file requests are excluded.
Adds a LatencyHistogram to WorkerMetrics, a MetricValue::Hist variant for IPC transport, histogram exposition in the aggregator, and integration tests covering exposition, counts, static exclusion and the empty case.
Co-authored-by: GitHub Copilot [email protected]