community.grafana icon indicating copy to clipboard operation
community.grafana copied to clipboard

Draft: Allow datasource to be tested through Grafana after creation

Open rrey opened this issue 2 years ago • 4 comments

SUMMARY

Introduce post create/update datasource test for Prometheus datasource.

Refs: #220

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

grafana_datasource.py

rrey avatar Feb 27 '22 14:02 rrey

Codecov Report

:exclamation: 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.

codecov[bot] avatar Feb 27 '22 14:02 codecov[bot]

/rebase

rrey avatar May 01 '22 15:05 rrey

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

kongslund avatar Jul 23 '22 09:07 kongslund

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

rrey avatar Aug 19 '22 16:08 rrey