Skip to content
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

Draft: Allow datasource to be tested through Grafana after creation #221

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rrey
Copy link
Collaborator

@rrey rrey commented Feb 27, 2022

SUMMARY

Introduce post create/update datasource test for Prometheus datasource.

Refs: #220

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

grafana_datasource.py

rrey added 2 commits February 27, 2022 15:15
…th basicAuth enabled

credentials are admin/admin
…after creation/update

The Grafana WUI as a feature on datasource that allows to 'Save & test' the datasource
when creating or updating it.

This patch allows to run the same query after Prometheus datasource
creation and update.

A GrafanaHttpError exception was added to improve error management and
returned message in case of failure.
@rrey rrey requested a review from seuf as a code owner February 27, 2022 14:26
@rrey rrey changed the title Allow datasource to be tested through Grafana after creation Draft: Allow datasource to be tested through Grafana after creation Feb 27, 2022
@codecov
Copy link

codecov bot commented Feb 27, 2022

Codecov Report

❗ No coverage uploaded for pull request base (main@8ef798a). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #221   +/-   ##
=======================================
  Coverage        ?   73.25%           
=======================================
  Files           ?        7           
  Lines           ?      729           
  Branches        ?       75           
=======================================
  Hits            ?      534           
  Misses          ?      179           
  Partials        ?       16           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8ef798a...16c14d4. Read the comment docs.

@rrey
Copy link
Collaborator Author

rrey commented May 1, 2022

/rebase

@kongslund
Copy link
Contributor

In the documentation for the API in Grafana 9.0.x, there's an endpoint for checking the data source health:

/api/datasources/uid/:uid/health

It would be desirable if we could utilize that endpoint in a generic fashion for all current and future data sources.

However, I cannot get it to check the health of Prometheus when using Grafana 9.0.4. I'm not sure if I'm overlooking something simple?

  1. The Prometheus data source looks like this:

Request:

export GF_API_KEY=<Grafana API key with Admin role>
curl -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $GF_API_KEY" \
  "http://localhost:3000/api/datasources/uid/U2LhXyg4k"

Response:

{"id":1,"uid":"U2LhXyg4k","orgId":1,"name":"Prometheus","type":"prometheus","typeLogoUrl":"","access":"proxy","url":"http://host.docker.internal:9090","user":"","database":"","basicAuth":false,"basicAuthUser":"","withCredentials":false,"isDefault":true,"jsonData":{"httpMethod":"POST"},"secureJsonFields":{},"version":2,"readOnly":false}
  1. But when requesting to check the health a "Not found" is returned.

Request:

curl -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $GF_API_KEY" \
  "http://localhost:3000/api/datasources/uid/U2LhXyg4k/health"

Response:

{"message":"Not found","traceID":"00000000000000000000000000000000"}
  1. The Grafana log gives the error "method not implemented" so perhaps this is just not implemented for the Prometheus data source?
ERROR[07-23|08:53:28] Not found                                logger=context traceID=00000000000000000000000000000000 userId=0 orgId=1 uname= error="method not implemented" remote_addr=172.17.0.1 traceID=00000000000000000000000000000000

@rrey rrey marked this pull request as draft August 19, 2022 16:37
@rrey
Copy link
Collaborator Author

rrey commented Aug 19, 2022

@kongslund FYI I have the same result on my side with the health endpoint.
It looks worth an issue on the Grafana side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants