Skip to content

Feat: DO-11819 - add HTTP request metrics middleware#655

Merged
momustafa-causalens merged 2 commits into
masterfrom
DO-11819-implement-metrics-and-uptime-updates
Jun 26, 2026
Merged

Feat: DO-11819 - add HTTP request metrics middleware#655
momustafa-causalens merged 2 commits into
masterfrom
DO-11819-implement-metrics-and-uptime-updates

Conversation

@momustafa-causalens

Copy link
Copy Markdown
Contributor

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_total and http_request_duration_seconds enables the observability service to surface request rate, error rate, and latency for deployed Dara apps.

Implementation Description

  • New metrics/http.py — defines http_requests_total (Counter) and http_request_duration_seconds (Histogram) with labels method, status, path. A PrometheusMiddleware (Starlette BaseHTTPMiddleware) wraps every request and records both metrics. Uses the matched route pattern (e.g. /api/components/{uid}) for the path label to avoid unbounded cardinality.

  • Middleware registration in main.py — gated by the same conditions as the existing metrics server (DARA_DISABLE_METRICS != TRUE and DARA_TEST_FLAG not set), so tests are unaffected.

  • Exports added to metrics/__init__.pyHTTP_REQUESTS_TOTAL and HTTP_REQUEST_DURATION_SECONDS are available for downstream code if needed.

No changes to the existing /status endpoint, metrics server startup, or prometheus_client dependency — 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?

  • Targeted test suite passes (70 passed). The middleware is not registered during tests (DARA_TEST_FLAG guard), so existing tests are unaffected.
  • Import verification: from dara.core.metrics.http import PrometheusMiddleware succeeds.

PR Checklist:

  • I have implemented all requirements? (see JIRA, project documentation).
  • I am not affecting someone else's work, If I am, they are included as a reviewer.
  • I have added relevant tests (unit, integration or regression).
  • I have added comments to all the bits that are hard to follow.
  • I have added/updated Documentation.
  • I have updated the appropriate changelog with a line for my changes.

Screenshots (if appropriate):

N/A — backend-only change. Metrics are visible via curl http://localhost:10000/metrics.

- 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 krzysztof-causalens left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a brief changelog entry, just say that we extended metrics to include http stats

Comment thread packages/dara-core/dara/core/metrics/http.py Outdated
@momustafa-causalens momustafa-causalens merged commit dbbeb3c into master Jun 26, 2026
13 of 15 checks passed
@momustafa-causalens momustafa-causalens deleted the DO-11819-implement-metrics-and-uptime-updates branch June 26, 2026 17:39
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.

2 participants