Skip to content

Add HTTP timing metrics and update Grafana dashboard#2586

Merged
openminddev merged 4 commits into
mainfrom
update-prometheus
May 28, 2026
Merged

Add HTTP timing metrics and update Grafana dashboard#2586
openminddev merged 4 commits into
mainfrom
update-prometheus

Conversation

@openminddev

Copy link
Copy Markdown
Contributor

This pull request introduces comprehensive HTTP client-side and upstream/proxy timing metrics, exposing them via Prometheus and visualizing them in Grafana. The changes include new Prometheus histograms and gauges for various HTTP timing metrics, instrumentation in the HTTPX provider to record these metrics, updates to the Grafana dashboard to display them, and test adjustments to ensure compatibility with the new metrics.

Metrics instrumentation and export:

  • Added new Prometheus histograms and gauges in src/prometheus/__init__.py to track HTTP request duration, upstream/proxy timings (total and TTFB), and their most recent values, all labeled by method, status code, and URL.
  • Instrumented the HTTPX provider (src/providers/httpx.py) to observe and set these metrics on every response, extracting timing information from response headers and request metadata. [1] [2]

Dashboard and observability:

  • Updated grafana/dashboards/om1-dashboard.json to add new panels visualizing the metrics: last HTTP request duration, upstream/proxy timings, request duration percentiles, and request rates by method and status code.

Testing adjustments:

  • Updated tests in tests/providers/test_httpx_provider.py to use httpx.URL objects for mock request URLs, ensuring compatibility with the updated metric labeling logic. [1] [2] [3] [4]

Introduce Prometheus metrics for HTTP timing (histograms and last-value gauges) and instrument the httpx provider to observe/set these metrics from request/response data and timing headers. Update Grafana dashboard to include stat and timeseries panels for request duration, upstream TTFB/total, proxy total, percentiles, and request rates. Adjust tests to construct mock request URLs using httpx.URL for compatibility with the provider instrumentation.
Copilot AI review requested due to automatic review settings May 27, 2026 23:06
@openminddev openminddev requested review from a team as code owners May 27, 2026 23:06
@github-actions github-actions Bot added robotics Robotics code changes python Python code tests Test files config Configuration files labels May 27, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds new Prometheus metrics to capture client-side HTTP request duration plus upstream/proxy timing breakdowns, instruments the HTTPX provider to emit those metrics per response, and extends the Grafana dashboard to visualize the new signals.

Changes:

  • Introduces new Prometheus Histograms/Gauges for HTTP request duration, upstream total/TTFB, and proxy total timings.
  • Instruments providers.httpx response hooks to record the new metrics based on elapsed time and timing headers.
  • Updates the Grafana dashboard with new stat and timeseries panels; adjusts HTTPX provider tests to use httpx.URL.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.

File Description
src/prometheus/__init__.py Adds new HTTP timing Histograms/Gauges exported via Prometheus.
src/providers/httpx.py Records new HTTP timing metrics from request/response context and headers.
tests/providers/test_httpx_provider.py Updates mocks to use httpx.URL objects for request URLs.
grafana/dashboards/om1-dashboard.json Adds panels for “last” timings, percentiles, and request rates.

Comment thread src/providers/httpx.py Outdated
Comment thread src/providers/httpx.py Outdated
Comment thread src/providers/httpx.py Outdated
Comment thread src/prometheus/__init__.py Outdated
Comment thread grafana/dashboards/om1-dashboard.json Outdated
Comment thread grafana/dashboards/om1-dashboard.json Outdated
Comment thread grafana/dashboards/om1-dashboard.json Outdated
Comment thread grafana/dashboards/om1-dashboard.json Outdated
@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.36585% with 6 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/providers/httpx.py 81.81% 6 Missing ⚠️

📢 Thoughts on this report? Let us know!

Replace the Prometheus metrics' 'url' label with 'host' (labels now ['host', 'method', 'status_code']) and update all metric invocations accordingly. In the httpx provider, extract host from response.request.url.host and rename usages, change start_time default to None, and add a guard that logs a warning and skips metric recording when start_time is missing to avoid spurious metrics.
Prune several HTTP timing and stat panels from grafana/dashboards/om1-dashboard.json to simplify the dashboard and remove redundant metrics. Removed panels include: "HTTP Request Duration (Last)", "HTTP Upstream TTFB (Last)", "HTTP Upstream Total (Last)", "HTTP Proxy Total (Last)", "HTTP Request Duration Percentiles", "HTTP Proxy & Upstream Timing Breakdown (p95)", and "HTTP Request Rate by Method & Status Code". This reduces clutter and focuses the dashboard on the remaining LLM request metrics.
Update tests for httpx event hooks to reflect expected behavior when a request has no start_time: add a start_time to the mock_request in the relevant test, rename the test to indicate it should warn-and-skip when start_time is absent, and change assertions to patch logging.warning (ensuring logging.info is not called) and verify the warning message contains "No start_time recorded".
@openminddev openminddev merged commit 0eacb2d into main May 28, 2026
6 checks passed
@openminddev openminddev deleted the update-prometheus branch May 28, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Configuration files python Python code robotics Robotics code changes tests Test files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants