Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# CHANGELOG

## unreleased
- AMG compatibility: Fetch Grafana version from `/api/frontend/settings`
instead of `/api/health`. Thanks, @squadgazzz.
**Breaking change:** This means that authentication is obligatory now, because the
new endpoint requires it. Also, `database` status is no longer represented in the
new response.

## 4.3.3 (2025-07-27)
- Async: Fixed code generator for edge cases at "smartquery" interface. Thanks, @JIAQIA.
Expand Down
6 changes: 4 additions & 2 deletions grafana_client/elements/_async/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ def __init__(self, client):

async def check(self):
"""
Return Grafana build information, compatible with Grafana, and Amazon Managed Grafana (AMG).

:return:
"""
path = "/health"
return await self.client.GET(path)
path = "/frontend/settings"
response = await self.client.GET(path)
return response.get("buildInfo")
6 changes: 4 additions & 2 deletions grafana_client/elements/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ def __init__(self, client):

def check(self):
"""
Return Grafana build information, compatible with Grafana, and Amazon Managed Grafana (AMG).

:return:
"""
path = "/health"
return self.client.GET(path)
path = "/frontend/settings"
response = self.client.GET(path)
return response.get("buildInfo")
8 changes: 4 additions & 4 deletions test/elements/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def test_get_dashboard(self, m):
@requests_mock.Mocker()
def test_get_dashboard_by_name_grafana7(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "6f8c1d9fe4", "database": "ok", "version": "7.5.11"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "6f8c1d9fe4", "version": "7.5.11"}},
)
m.get(
"http://localhost/api/dashboards/db/Production Overview",
Expand All @@ -64,8 +64,8 @@ def test_get_dashboard_by_name_grafana7(self, m):
@requests_mock.Mocker()
def test_get_dashboard_by_name_grafana8(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "8.0.2"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "8.0.2"}},
)
with self.assertRaises(DeprecationWarning) as ex:
self.grafana.dashboard.get_dashboard_by_name("foobar")
Expand Down
56 changes: 28 additions & 28 deletions test/elements/test_datasource_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def test_delete_datasource_by_name(self, m):
@requests_mock.Mocker()
def test_enable_datasource_permissions(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
)

m.post(
Expand All @@ -147,8 +147,8 @@ def test_enable_datasource_permissions(self, m):
@requests_mock.Mocker()
def test_enable_datasource_permissions_grafana1023(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
)

with patch(
Expand All @@ -162,8 +162,8 @@ def test_enable_datasource_permissions_grafana1023(self, m):
@requests_mock.Mocker()
def test_disable_datasource_permissions(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
)

m.post(
Expand All @@ -177,8 +177,8 @@ def test_disable_datasource_permissions(self, m):
@requests_mock.Mocker()
def test_disable_datasource_permissions_grafana1023(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
)

with patch(
Expand All @@ -192,8 +192,8 @@ def test_disable_datasource_permissions_grafana1023(self, m):
@requests_mock.Mocker()
def test_get_datasource_permissions(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
)

m.get(
Expand All @@ -207,8 +207,8 @@ def test_get_datasource_permissions(self, m):
@requests_mock.Mocker()
def test_get_datasource_permissions_grafana1023(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
)

with patch(
Expand All @@ -222,8 +222,8 @@ def test_get_datasource_permissions_grafana1023(self, m):
@requests_mock.Mocker()
def test_add_datasource_permissions(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
)

m.post(
Expand All @@ -237,8 +237,8 @@ def test_add_datasource_permissions(self, m):
@requests_mock.Mocker()
def test_add_datasource_permissions_grafana1023(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
)

with patch(
Expand All @@ -252,8 +252,8 @@ def test_add_datasource_permissions_grafana1023(self, m):
@requests_mock.Mocker()
def test_remove_datasource_permissions(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
)

m.delete(
Expand All @@ -267,8 +267,8 @@ def test_remove_datasource_permissions(self, m):
@requests_mock.Mocker()
def test_remove_datasource_permissions_grafana1023(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
)

with patch(
Expand Down Expand Up @@ -395,8 +395,8 @@ def test_query_with_datasource_prometheus_grafana7(self, m):
# Mock the version inquiry request, because `smartquery` needs
# it, as Prometheus responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "7.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "7.0.1"}},
)
m.post(
"http://localhost/api/ds/query",
Expand All @@ -411,8 +411,8 @@ def test_query_with_datasource_prometheus_grafana9(self, m):
# Mock the version inquiry request, because `smartquery` needs
# it, as Prometheus responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.post(
"http://localhost/api/ds/query",
Expand Down Expand Up @@ -453,8 +453,8 @@ def test_query_with_datasource_identifier(self, m):
# Mock the version inquiry request, because `smartquery` needs
# it, as Prometheus responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/h8KkCLt7z",
Expand All @@ -472,8 +472,8 @@ def test_query_unknown_access_type_failure(self, m):
# Mock the version inquiry request, because `smartquery` needs
# it, as Prometheus responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
datasource = PROMETHEUS_DATASOURCE.copy()
datasource["access"] = "__UNKNOWN__"
Expand Down
52 changes: 26 additions & 26 deletions test/elements/test_datasource_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ def test_health_check_loki_success_grafana7(self, m):
# Mock the version inquiry request, because `smartquery` needs
# it, as Loki responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "7.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "7.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/vCyglaq7z",
Expand Down Expand Up @@ -364,8 +364,8 @@ def test_health_check_loki_success_grafana9(self, m):
# Mock the version inquiry request, because `smartquery` needs
# it, as Loki responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/vCyglaq7z",
Expand Down Expand Up @@ -396,8 +396,8 @@ def test_health_check_loki_error_response_failure_grafana7(self, m):
# Mock the version inquiry request, because `smartquery` needs
# it, as Loki responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": "7.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": "7.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/vCyglaq7z",
Expand Down Expand Up @@ -428,8 +428,8 @@ def test_health_check_loki_error_response_failure_grafana9(self, m):
# Mock the version inquiry request, because `smartquery` needs
# it, as Loki responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/vCyglaq7z",
Expand Down Expand Up @@ -565,8 +565,8 @@ def test_health_check_prometheus_healthy_success(self, grafana_version):
# Mock the version inquiry request, because `smartquery` needs
# it, as Prometheus responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": grafana_version},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": grafana_version}},
)
m.get(
"http://localhost/api/datasources/uid/h8KkCLt7z",
Expand Down Expand Up @@ -599,8 +599,8 @@ def test_health_check_prometheus_empty_dataframe_success(self, grafana_version):
# Mock the version inquiry request, because `smartquery` needs
# it, as Prometheus responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": grafana_version},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": grafana_version}},
)
m.get(
"http://localhost/api/datasources/uid/h8KkCLt7z",
Expand Down Expand Up @@ -633,8 +633,8 @@ def test_health_check_prometheus_invalid_dataframe_failure(self, grafana_version
# Mock the version inquiry request, because `smartquery` needs
# it, as Prometheus responses differ between versions.
m.get(
"http://localhost/api/health",
json={"commit": "unknown", "database": "ok", "version": grafana_version},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "unknown", "version": grafana_version}},
)
m.get(
"http://localhost/api/datasources/uid/h8KkCLt7z",
Expand Down Expand Up @@ -1161,8 +1161,8 @@ def setUp(self):
@requests_mock.Mocker()
def test_health_inquiry_native_prometheus_success(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/39mf288en",
Expand Down Expand Up @@ -1191,8 +1191,8 @@ def test_health_inquiry_native_prometheus_success(self, m):
@requests_mock.Mocker()
def test_health_inquiry_native_prometheus_failure(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/39mf288en",
Expand Down Expand Up @@ -1221,8 +1221,8 @@ def test_health_inquiry_native_prometheus_failure(self, m):
@requests_mock.Mocker()
def test_health_inquiry_native_unknown_error_400(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/39mf288en",
Expand Down Expand Up @@ -1252,8 +1252,8 @@ def test_health_inquiry_native_unknown_error_400(self, m):
@requests_mock.Mocker()
def test_health_inquiry_native_unknown_error_418(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/39mf288en",
Expand All @@ -1271,8 +1271,8 @@ def test_health_inquiry_native_unknown_error_418(self, m):
@requests_mock.Mocker()
def test_health_inquiry_native_prometheus_error_404(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/h8KkCLt7z",
Expand Down Expand Up @@ -1308,8 +1308,8 @@ def test_health_inquiry_native_prometheus_error_404(self, m):
@requests_mock.Mocker()
def test_health_inquiry_native_prometheus_error_500(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
)
m.get(
"http://localhost/api/datasources/uid/h8KkCLt7z",
Expand Down
7 changes: 3 additions & 4 deletions test/elements/test_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ def setUp(self):
@requests_mock.Mocker()
def test_healthcheck(self, m):
m.get(
"http://localhost/api/health",
json={"commit": "6f8c1d9fe4", "database": "ok", "version": "7.5.11"},
"http://localhost/api/frontend/settings",
json={"buildInfo": {"commit": "6f8c1d9fe4", "version": "7.5.11"}},
)

result = self.grafana.health.check()
self.assertEqual(result["database"], "ok")
self.assertEqual(len(result), 3)
self.assertEqual(result["version"], "7.5.11")
Loading
Loading