8000 [ENHANCEMENT] Implement the `healthcheck` method for Prometheus datasources by sinkingpoint · Pull Request #1595 · perses/perses · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[ENHANCEMENT] Implement the healthcheck method for Prometheus datasources #1595

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

Merged

Conversation

sinkingpoint
Copy link
Contributor

Description

As a first step towards #1542 (and as my first PR, so feedback appreciated), this implements a healthcheck on Prometheus Datasources.

The DatasourceClient interface defines a healthcheck method, which
hasn't actually been implemented. This implements it for the PrometheusDatasourceClient
as a first step towards being able to test the health of a datasource.

The actual implementation calls the /-/healthy
endpoint in the Prometheus API, rather than running a query. I figured
this was a better way to test the health rather than running a dummy
query and checking the result, as running a query is a more expensive
and subjects us to the vagaries of PromQL, and potential
query timeouts which aren't directly related to whether the datasource
is configured correctly.

Checklist

  • Pull request has a descriptive title and context useful to a reviewer.
  • Pull request title follows the [<catalog_entry>] <commit message> naming convention using one of the following catalog_entry values: FEATURE, ENHANCEMENT, BUGFIX, BREAKINGCHANGE, IGNORE.
  • All commits have DCO signoffs.

The `DatasourceClient` interface defines a `healthcheck` method, which
hasn't actually been implemented. This implements it for the `PrometheusDatasourceClient`
as a first step towards being able to test the health of a datasource.

The actual implementation calls the [/-/healthy](https://prometheus.io/docs/prometheus/latest/management_api/#health-check)
endpoint in the Prometheus API, rather than running a query. I figured
this was a better way to test the health rather than running a dummy
query and checking the result, as running a query is a more expensive
and subjects us to the vagaries of PromQL, and potential
query timeouts which aren't directly related to whether the datasource
is configured correctly.

Signed-off-by: sinkingpoint <colin@quirl.co.nz>
@sinkingpoint sinkingpoint force-pushed the sinkingpoint/prometheus-healthcheck branch from e25778e to 78a4647 Compare November 20, 2023 22:27
@nicolastakashi
Copy link
Collaborator

Amazing @sinkingpoint thanks for handling this.
LGTM 🥳

@@ -37,6 +37,7 @@ const createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>
options: {
datasourceUrl,
},
healthCheck: healthCheck({ datasourceUrl, headers: specHeaders }),
Copy link
Member
@Gladorme Gladorme Nov 22, 2023

Choose a reason for hiding this comment

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

For similarity with others requests, I would have add headers as param too. But I guess it's fine 🤔

Suggested change
healthCheck: healthCheck({ datasourceUrl, headers: specHeaders }),
healthCheck: (headers) => healthCheck({ datasourceUrl, headers: headers ?? specHeaders }),

Copy link
Member
@Gladorme Gladorme left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! 🚀

@Gladorme Gladorme merged commit 7d88555 into perses:main Nov 22, 2023
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.

3 participants
0