Skip to content

Make the Grafana metrics link runtime configurable - #808

Open
hedhoud wants to merge 10 commits into
developfrom
agent/runtime-grafana-link
Open

Make the Grafana metrics link runtime configurable#808
hedhoud wants to merge 10 commits into
developfrom
agent/runtime-grafana-link

Conversation

@hedhoud

@hedhoud hedhoud commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Closes #779

Context

Operators need a clear path from OpenRAG raw metrics to the deployment dashboard without knowing the Grafana address or rebuilding the Admin UI.

Problem

A build-time-only link does not work reliably with prebuilt images. Hiding the action when runtime configuration is missing also makes the Grafana capability impossible to discover from the Metrics screen.

Solution

System → Metrics now always shows one Open in Grafana action. When the deployment provides a valid dashboard destination, it opens in a new tab. When configuration is missing, the same action explains how to enable it. Compose and Helm deployments can provide the destination through GRAFANA_URL, while the previous build-time setting remains a compatibility fallback.

Validation

All 160 Admin UI tests pass, the production UI build succeeds, and the backend runtime-configuration tests pass. Linting completes without new errors.

Summary by CodeRabbit

  • New Features
    • Added runtime-configured Grafana “Metrics” tab in the Admin UI with build-time fallback.
    • Enabled Grafana access under the same admin origin via /grafana/ routing/proxy.
    • Exposed grafana_url in the Admin config response; added corresponding Helm/Compose and environment templates.
  • Bug Fixes
    • Hardened Grafana URL validation in runtime configuration.
    • Updated Grafana dashboards and Prometheus scrape targets (including GPU metrics panel updates).
  • Documentation
    • Expanded installation/environment docs for Grafana credentials and sub-path/proxy settings.
  • Tests
    • Added unit tests for Grafana URL validation and UI behavior.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

💤 Files selected but had no reviewable changes (1)
  • infra/compose/grafana/dashboards/gpu-metrics.json
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 67f5edc9-bf6d-402b-a953-6ed4b1e76b3b

📥 Commits

Reviewing files that changed from the base of the PR and between c234813 and 0a80fc8.

📒 Files selected for processing (1)
  • infra/compose/grafana/dashboards/gpu-metrics.json

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The Admin UI now retrieves a validated Grafana URL from the API, falls back to a build-time value when needed, and exposes the dashboard from the Metrics tab. Compose, Nginx, Prometheus, Grafana, GPU exporter, Helm, and documentation configurations are updated accordingly.

Changes

Grafana metrics integration

Layer / File(s) Summary
Runtime Grafana configuration and Admin UI action
openrag/api/..., ui/src/lib/api/system.ts, ui/src/pages/admin/system.*, ui/src/mocks/handlers.ts, tests/unit/api/test_runtime_ui.py
The API validates and returns GRAFANA_URL; the Admin UI uses it with a build-time fallback and renders either an external Metrics link or configuration dialog, with tests covering both paths.
Grafana routing and monitoring stack
infra/compose/monitoring.docker-compose.yaml, infra/compose/nginx/..., infra/compose/prometheus/..., infra/compose/grafana/...
Grafana is served under /grafana/, Prometheus uses the Compose service target, the GPU exporter runtime is updated, and dashboard queries use nvidia_smi metrics.
Deployment configuration and documentation
docs/..., infra/charts/..., infra/compose/*.example, infra/compose/docker-compose.yaml, ui/README.md, ui/.env.example, infra/docker/api.Dockerfile, .gitignore
Environment examples, Helm values, UI documentation, Docker installation guidance, API image permissions, and monitoring credential handling are updated for the new configuration and deployment behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SystemPage
  participant ConfigAPI
  participant Nginx
  participant Grafana
  participant Prometheus
  SystemPage->>ConfigAPI: Request runtime Grafana configuration
  ConfigAPI-->>SystemPage: Return validated grafana_url
  SystemPage->>Nginx: Open Grafana metrics link
  Nginx->>Grafana: Proxy /grafana/ request
  Grafana->>Prometheus: Query nvidia_smi metrics
  Prometheus-->>Grafana: Return metric data
  Grafana-->>SystemPage: Render dashboard
Loading
🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements a runtime-configurable Grafana link, but [#779] also requires hiding or disabling the action when no dashboard is configured, which it does not do. Hide or disable the Metrics action when no Grafana dashboard is configured, while keeping the runtime-configurable URL path.
Out of Scope Changes check ⚠️ Warning The PR includes unrelated monitoring/dashboard updates, Prometheus target changes, and build/runtime tweaks beyond the Grafana-link objective. Split the dashboard, Prometheus, and Dockerfile changes into separate PRs unless they are required for the Grafana-link feature.
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: runtime configuration of the Grafana metrics link.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/runtime-grafana-link

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@hedhoud
hedhoud marked this pull request as ready for review July 27, 2026 16:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b16d3e4b47

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread openrag/api/runtime_ui.py Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/assets/env_example.env`:
- Around line 108-111: The proxied Grafana examples use inconsistent URLs. In
docs/assets/env_example.env lines 108-111, update GRAFANA_URL to the
browser-facing /grafana/d/... path; in docs/assets/env_linux_gpu.env lines
55-58, update the runtime URL to match the documented /grafana/ route.

In `@infra/compose/.env.example`:
- Around line 108-111: Update the Grafana environment examples around
GRAFANA_URL and GF_SERVER_ROOT_URL so they are internally consistent: either set
GRAFANA_URL to the Admin UI /grafana/ path when using the proxied
GF_SERVER_ROOT_URL configuration, or clearly provide separate direct-origin and
proxied examples.

In `@infra/compose/grafana/dashboards/gpu-metrics.json`:
- Around line 77-78: Remove the * 100 scaling from the GPU utilization
expression at infra/compose/grafana/dashboards/gpu-metrics.json lines 77-78, and
from the utilization gauge and memory-controller utilization expressions at
lines 167-168 and 350-351. Keep each metric query otherwise unchanged so the
dashboards display the exported 0–1 ratios directly.

In `@openrag/api/runtime_ui.py`:
- Around line 18-20: Update the Grafana URL parsing logic around urlparse to
catch ValueError from malformed netlocs or ports, and require parsed.hostname in
addition to an HTTP(S) scheme before returning the value. Ensure invalid
GRAFANA_URL values safely produce the existing fallback result without raising
while building /config.
- Around line 15-16: Update the relative-path validation around the value check
to reject any string containing a backslash before returning it as same-origin;
preserve the existing slash-prefix and double-slash handling, and add a
regression test covering a path such as “/\evil.example”.

In `@ui/README.md`:
- Around line 40-44: Update the surrounding settings documentation in the README
to state that the listed VITE_* variables are build-time settings, while
preserving the paragraph explaining GRAFANA_URL as an OpenRAG API runtime
setting. Ensure the wording does not imply that GRAFANA_URL is a Vite build-time
configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 91fecfaa-1e0d-4da4-9e28-93695af24dd2

📥 Commits

Reviewing files that changed from the base of the PR and between db3482c and b16d3e4.

📒 Files selected for processing (20)
  • docs/assets/env_example.env
  • docs/assets/env_linux_gpu.env
  • docs/content/docs/documentation/env_vars.md
  • infra/charts/openrag-stack/values.yaml
  • infra/compose/.env.example
  • infra/compose/docker-compose.yaml
  • infra/compose/grafana/dashboards/gpu-metrics.json
  • infra/compose/monitoring.docker-compose.yaml
  • infra/compose/nginx/openrag-admin.conf
  • infra/compose/prometheus/prometheus.yml
  • infra/docker/api.Dockerfile
  • openrag/api/main.py
  • openrag/api/runtime_ui.py
  • tests/unit/api/test_runtime_ui.py
  • ui/.env.example
  • ui/README.md
  • ui/src/lib/api/system.ts
  • ui/src/mocks/handlers.ts
  • ui/src/pages/admin/system.test.tsx
  • ui/src/pages/admin/system.tsx

Comment thread docs/assets/env_example.env
Comment thread infra/compose/.env.example
Comment thread infra/compose/grafana/dashboards/gpu-metrics.json Outdated
Comment thread openrag/api/runtime_ui.py
Comment thread openrag/api/runtime_ui.py Outdated
Comment thread ui/README.md

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/content/docs/installation/docker.mdx`:
- Around line 28-33: Replace the source .env flow in the Docker installation
instructions with Compose-dotenv-aware parsing or direct validation that does
not execute shell code, while correctly supporting valid dotenv values such as
spaces. Preserve exporting or retrieving AUTH_TOKEN for writing
prometheus/openrag_token, and enforce that it is present unless ALLOW_NO_AUTH is
enabled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: af252e33-6832-4531-9960-65d1125a2351

📥 Commits

Reviewing files that changed from the base of the PR and between b16d3e4 and cb98bc0.

📒 Files selected for processing (8)
  • .gitignore
  • docs/assets/env_example.env
  • docs/assets/env_linux_gpu.env
  • docs/content/docs/installation/docker.mdx
  • infra/compose/.env.example
  • openrag/api/runtime_ui.py
  • tests/unit/api/test_runtime_ui.py
  • ui/README.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • openrag/api/runtime_ui.py
  • docs/assets/env_linux_gpu.env
  • infra/compose/.env.example
  • docs/assets/env_example.env
  • ui/README.md

Comment thread docs/content/docs/installation/docker.mdx Outdated

@aditykris aditykris 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.

Looks good.

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.

Admin UI: add a direct link to the Grafana metrics dashboard

2 participants