Skip to content

Commit

Permalink
Add gracefulness when using the new data source health check endpoint
Browse files Browse the repository at this point in the history
Apparently, this is not implemented thoroughly for all data source types
yet. Now, when the example program hits a `404 Not Found` response, it
transparently falls back to the custom machinery.
  • Loading branch information
amotl committed Jun 21, 2022
1 parent d40def0 commit 7697f87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Improve data source API by adding a data source health-check probe.
* Support data source health check endpoint introduced with Grafana 9.
Thanks, @jangaraj!
* Add gracefulness when using the new data source health check endpoint.
Apparently, this is not implemented thoroughly for all data source types yet.


## 2.3.0 (2022-05-26)
Expand Down
9 changes: 6 additions & 3 deletions examples/datasource-health.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ def health_inquiry(grafana: GrafanaApi, datasource: DatasourceModel, grafana_ver
datasource = grafana.datasource.get(datasource_id=datasource_id)

# Check data source health.
health = None
if True or grafana_version and grafana_version >= VERSION_9:
try:
health = grafana.datasource.health(datasource_uid=datasource_uid)
except GrafanaClientError as ex:
logger.error(f"Data source health check for uid={datasource_uid} failed: {ex}. Response: {ex.response}")
raise
else:
logger.warning(f"Native data source health check for uid={datasource_uid} failed: {ex}. Response: {ex.response}")
if ex.status_code != 404:
raise

if health is None:
health = grafana.datasource.health_check(datasource=datasource)

# Delete data source again.
Expand Down

0 comments on commit 7697f87

Please sign in to comment.