Skip to content

prometheus: Settings: Fix connection test crash on plain-text response#909

Open
Athang69 wants to merge 1 commit into
headlamp-k8s:mainfrom
Athang69:fix/prometheus-health-check-json-parse
Open

prometheus: Settings: Fix connection test crash on plain-text response#909
Athang69 wants to merge 1 commit into
headlamp-k8s:mainfrom
Athang69:fix/prometheus-health-check-json-parse

Conversation

@Athang69

Copy link
Copy Markdown

Summary

This PR fixes a crash in the Prometheus plugin connection test by replacing the plain text /-/healthy health check with a JSON producing query endpoint.

Related Issue

Fixes kubernetes-sigs/headlamp#6541

Changes

  • Updated the connection test in Settings.tsx to query /api/v1/query?query=up instead of /-/healthy
  • Added a status check on the response body to confirm the query API actually succeeded, not just that something answered on the port

Steps to Test

  1. Deploy a standard external Prometheus server and expose it as a service in your cluster, for example on port 9090
  2. In Headlamp, open the Prometheus plugin settings and configure the namespace, service, and port pointing to that Prometheus instance
  3. Click Test Connection and confirm it succeeds instead of throwing a JSON parse error in the console

Notes for the Reviewer

  • Standard Prometheus servers return text/plain from /-/healthy, for example "Prometheus Server is Healthy.", which crashed the JSON parser with "Unexpected token 'P'... is not valid JSON"
  • Swapped to /api/v1/query?query=up, which always returns JSON and validates the query engine end to end rather than just liveness
  • Verified locally with a script that mocks both the old and new proxy responses, reproducing the original crash and confirming the fix avoids it, without needing a live cluster
  • Also confirmed clean tsc, eslint, and npm run build on this branch

Copilot AI review requested due to automatic review settings July 16, 2026 12:18

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 updates the Prometheus plugin Settings “Test Connection” flow to avoid JSON parsing crashes by switching from the plain-text /-/healthy endpoint to the JSON-based Prometheus query API, and it adds a basic validation of the Prometheus API response.

Changes:

  • Switch connection test endpoint from /-/healthy to /api/v1/query?query=up (JSON response).
  • Validate the returned Prometheus payload by checking response.status === 'success' before reporting success.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread prometheus/src/components/Settings/Settings.tsx Outdated
Comment thread prometheus/src/components/Settings/Settings.tsx
Signed-off-by: Athang69 <athangkali21@gmail.com>
@Athang69 Athang69 force-pushed the fix/prometheus-health-check-json-parse branch from c078688 to 0fc0bb3 Compare July 16, 2026 12:28
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.

bug(plugins/prometheus): Prometheus connection fails with "SyntaxError: Unexpected token 'P' ... is not valid JSON" due to plain-text health check

2 participants