Is there a backend API to execute the queries and get the queries results? The use case is, I want to add e2e test for some self-defined dashboards. Basically, given some existing data in the datasource, I want to verify the query results are expected.
The Grafana frontend is making requests to its backend server, that definitively qualifies as an API. You can inspect the requests using your favorite Browser’s developer tools.
However, while the HTTP endpoints are standardized, the payloads are not. The queries sent to the corresponding datasource endpoints will differ based on the type of database you are talking to. That is probably why the corresponding endpoints, for example https://datahub.example.org/grafana/api/datasources/proxy/42/query, are not part of the official HTTP API reference.
A check program from our pen
We don’t do sophisticated e2e tests, but we are running a check program on our Icinga instance which verifies given data sources through the HTTP API against becoming stale and alerts us when they do, taking configurable freshness time thresholds into account.
You might want to use it as a starting point for inspiration.
At the usage-by-example documentation, you can inspect the options to use for the program. Those options are necessary to direct it to the right data source:
At check-grafana-datasource-stale.sh#L213-L214, you can see that the program is sending a query that is specifically suited for InfluxDB 1.x. With other datasource types, you would need to send a different query. In order to make the program more universal, it could be improved so that the query expression would also be obtained as command line option.