Skip to content

fix(config-ui): keep grafana deep links working with an external grafana - #9239

Open
DoDiODev wants to merge 1 commit into
apache:mainfrom
DoDiODev:pr/enterprise-config-ui-grafana-links
Open

DoDiODev wants to merge 1 commit into
apache:mainfrom
DoDiODev:pr/enterprise-config-ui-grafana-links

Conversation

@DoDiODev

Copy link
Copy Markdown
Contributor

Summary

Fixes two bugs with the Grafana links of the config-ui. Part of #9219
(section B). Defaults and proxy mode are unchanged.

External Grafana redirect keeps path and query

With USE_EXTERNAL_GRAFANA=true, nginx.conf answered every /grafana/...
request with 302 ${GRAFANA_ENDPOINT} and dropped the path and the query. All
dashboard links (e.g. /grafana/d/<uid>/<slug>?orgId=1) therefore ended on the
Grafana home page.

  • The redirect now appends the part after /grafana from $request_uri
    (still URL-encoded, query string included), via a map in nginx.conf.
  • nginx.sh drops a trailing slash from GRAFANA_ENDPOINT, so
    https://grafana.example.com/ does not produce //.
  • Proxy mode (default) is unchanged.

"Check Dashboard" button in the onboarding

The button opened import.meta.env.DEVLAKE_DASHBOARD_URL_*. These are
build-time variables; the released image is built without them, so the button
opened an empty tab. The example values in config-ui/env.example also point
to the MySQL dashboard UIDs, while the PostgreSQL dashboards use a -pg
suffix.

  • New getDashboardURL(plugin): uses the configured URL if set, otherwise the
    Grafana dashboard search for the plugin (e.g.
    /grafana/dashboards?query=GitHub, respecting DEVLAKE_GRAFANA_PATH). The
    titles are the same for MySQL and PostgreSQL, so this works for both.
  • Unit tests for the helper.

Docs

  • config-ui/README.md: GRAFANA_ENDPOINT / USE_EXTERNAL_GRAFANA in the
    Docker image.
  • config-ui/env.example: the dashboard URLs are optional, and the
    PostgreSQL UIDs use the -pg suffix.

Does this close any open issues?

Part of #9219 (section B).

Screenshots

N/A

Other Information

Tested with the image built from this branch and from main (ee0079ab3):

Scenario main this PR
External: /grafana/d/KXWvOFQnz-pg/github?orgId=1&var-repo_id=All ❌ redirects to https://grafana.example.com/ ✅ https://grafana.example.com/d/KXWvOFQnz-pg/github?orgId=1&var-repo_id=All
External: encoded query (var-repo=a%20b&var-team=%2Fdev) ❌ dropped ✅ kept as is
External with a sub path (GRAFANA_ENDPOINT=https://example.com/grafana) ❌ https://example.com/grafana ✅ https://example.com/grafana/d/…
External: /grafana/ ✅ ✅
Proxy mode: deep link, /grafana/, SPA route ✅ ✅ unchanged
Built bundle no dashboard URL (empty tab) falls back to the dashboard search

The search URL was checked against Grafana 13.2.3 in a headless browser:
/dashboards?query=GitHub lists only the matching dashboard.
tsc, eslint, vitest and vite build pass. Full CI mirror on my fork:
run

With USE_EXTERNAL_GRAFANA=true, nginx redirected every /grafana/... request
to GRAFANA_ENDPOINT and dropped the path and query, so all dashboard links
(e.g. /grafana/d/<uid>/...) ended on the Grafana home page. The redirect
now keeps the path after /grafana and the query string ($request_uri, still
URL-encoded). A trailing slash in GRAFANA_ENDPOINT is ignored. Proxy mode is
unchanged.

The onboarding "Check Dashboard" button opened DEVLAKE_DASHBOARD_URL_*,
which are build-time variables and are not set in the released image, so
the button opened an empty tab. If no URL is configured, it now opens the
Grafana dashboard search for the plugin (e.g. /grafana/dashboards?query=GitHub),
which works for MySQL and PostgreSQL (PostgreSQL dashboards use "-pg" UIDs).

Also document USE_EXTERNAL_GRAFANA in config-ui/README.md and the
PostgreSQL UIDs in config-ui/env.example.

Refs apache#9219

Signed-off-by: DoDiODev <DoDiDev@proton.me>
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.

1 participant