-
Notifications
You must be signed in to change notification settings - Fork 55
Make the Grafana metrics link runtime configurable #808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hedhoud
wants to merge
10
commits into
develop
Choose a base branch
from
agent/runtime-grafana-link
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3d391c4
Configure Grafana link at runtime
hedhoud afd6a17
Keep the Grafana metrics action discoverable
hedhoud 3c21f26
Merge branch 'develop' into agent/runtime-grafana-link
hedhoud 4e0c6a6
Fix the bundled Grafana monitoring stack
aditykris 245b907
Keep copied API sources readable
aditykris b16d3e4
Refresh the Grafana action on navigation
hedhoud cb98bc0
Harden Grafana runtime configuration
hedhoud 6a042c0
Parse monitoring credentials without sourcing dotenv
hedhoud c234813
Add GPU health to the infrastructure overview
hedhoud 0a80fc8
Remove the redundant GPU dashboard
hedhoud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| """Runtime configuration exposed to the browser-facing Admin UI.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from urllib.parse import urlparse | ||
|
|
||
|
|
||
| def get_grafana_url() -> str | None: | ||
| """Return a safe Grafana destination configured for this deployment.""" | ||
| value = os.getenv("GRAFANA_URL", "").strip() | ||
| if not value: | ||
| return None | ||
|
|
||
| if value.startswith("/") and not value.startswith("//"): | ||
| return value | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| parsed = urlparse(value) | ||
|
hedhoud marked this conversation as resolved.
Outdated
|
||
| if parsed.scheme in {"http", "https"} and parsed.netloc: | ||
| return value | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| return None | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| """Tests for deployment-provided Admin UI destinations.""" | ||
|
|
||
| import pytest | ||
| from api.runtime_ui import get_grafana_url | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("value", "expected"), | ||
| [ | ||
| (None, None), | ||
| ("", None), | ||
| (" ", None), | ||
| ( | ||
| "https://grafana.example/d/openrag-http/openrag-http-metrics", | ||
| "https://grafana.example/d/openrag-http/openrag-http-metrics", | ||
| ), | ||
| ( | ||
| " http://localhost:3000/d/openrag-http/openrag-http-metrics ", | ||
| "http://localhost:3000/d/openrag-http/openrag-http-metrics", | ||
| ), | ||
| ("/grafana/d/openrag-http/openrag-http-metrics", "/grafana/d/openrag-http/openrag-http-metrics"), | ||
| ("//untrusted.example/dashboard", None), | ||
| ("javascript:alert(1)", None), | ||
| ("grafana.example/dashboard", None), | ||
| ], | ||
| ) | ||
| def test_grafana_url_accepts_only_browser_safe_destinations(monkeypatch, value, expected): | ||
| if value is None: | ||
| monkeypatch.delenv("GRAFANA_URL", raising=False) | ||
| else: | ||
| monkeypatch.setenv("GRAFANA_URL", value) | ||
|
|
||
| assert get_grafana_url() == expected |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| VITE_API_BASE_URL=http://localhost:8000 | ||
| # Build-time fallback for frontend-only development. Production uses GRAFANA_URL on the API. | ||
| VITE_GRAFANA_URL=http://localhost:3000/d/system-overview |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.