Feat: DO-11819 - add HTTP request metrics middleware#655
Merged
momustafa-causalens merged 2 commits intoJun 26, 2026
Conversation
- Add http_requests_total counter and http_request_duration_seconds histogram - Register PrometheusMiddleware gated by DARA_DISABLE_METRICS and DARA_TEST_FLAG - Export new metrics from metrics package
krzysztof-causalens
left a comment
Collaborator
There was a problem hiding this comment.
Could we add a brief changelog entry, just say that we extended metrics to include http stats
krzysztof-causalens
approved these changes
Jun 26, 2026
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.
Motivation and Context
Dara already exposes Prometheus metrics on port 10000 (task runtimes, DV runtimes, cache size), but has no HTTP request-level metrics. Adding
http_requests_totalandhttp_request_duration_secondsenables the observability service to surface request rate, error rate, and latency for deployed Dara apps.Implementation Description
New
metrics/http.py— defineshttp_requests_total(Counter) andhttp_request_duration_seconds(Histogram) with labelsmethod,status,path. APrometheusMiddleware(StarletteBaseHTTPMiddleware) wraps every request and records both metrics. Uses the matched route pattern (e.g./api/components/{uid}) for thepathlabel to avoid unbounded cardinality.Middleware registration in
main.py— gated by the same conditions as the existing metrics server (DARA_DISABLE_METRICS != TRUEandDARA_TEST_FLAGnot set), so tests are unaffected.Exports added to
metrics/__init__.py—HTTP_REQUESTS_TOTALandHTTP_REQUEST_DURATION_SECONDSare available for downstream code if needed.No changes to the existing
/statusendpoint, metrics server startup, orprometheus_clientdependency — all already in place.Note
Not sure if we need a changelog update for this sort of change
Any new dependencies Introduced
None.
How Has This Been Tested?
DARA_TEST_FLAGguard), so existing tests are unaffected.from dara.core.metrics.http import PrometheusMiddlewaresucceeds.PR Checklist:
Screenshots (if appropriate):
N/A — backend-only change. Metrics are visible via
curl http://localhost:10000/metrics.