Skip to content

Commit c1b887f

Browse files
committed
AMG compatibility: Fetch Grafana version from /api/frontend/settings
... instead of `/api/health`.
1 parent 3fc0400 commit c1b887f

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## unreleased
44
- Async: Fixed code generator for edge cases at "smartquery" interface. Thanks, @JIAQIA.
5+
- AMG compatibility: Fetch Grafana version from `/api/frontend/settings`
6+
instead of `/api/health`. Thanks, @squadgazzz.
7+
This means that authentication is obligatory now, because the new endpoint
8+
needs it.
59

610
## 4.3.2 (2025-03-04)
711
- Alerting: Allowed the datasource to be specified with managed alerting. Thanks, @dmyerscough.

grafana_client/elements/_async/health.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ def __init__(self, client):
88

99
async def check(self):
1010
"""
11+
Return Grafana build information, compatible with Grafana, and Amazon Managed Grafana (AMG).
1112
1213
:return:
1314
"""
14-
path = "/health"
15-
return await self.client.GET(path)
15+
path = "/frontend/settings"
16+
response = await self.client.GET(path)
17+
return response.get("buildInfo")

grafana_client/elements/health.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ def __init__(self, client):
88

99
def check(self):
1010
"""
11+
Return Grafana build information, compatible with Grafana, and Amazon Managed Grafana (AMG).
1112
1213
:return:
1314
"""
14-
path = "/health"
15-
return self.client.GET(path)
15+
path = "/frontend/settings"
16+
response = self.client.GET(path)
17+
return response.get("buildInfo")

test/test_grafana_client.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,22 @@ def json(self):
2323
return self.json_data
2424

2525

26+
frontend_settings_buildinfo_payload = {
27+
"buildInfo": {
28+
"buildstamp": 1753567501,
29+
"commit": "e0ba4b480954f8a33aa2cff3229f6bcc05777bd9",
30+
"commitShort": "e0ba4b4809",
31+
"edition": "Open Source",
32+
"env": "production",
33+
"hasUpdate": True,
34+
"hideVersion": False,
35+
"latestVersion": "12.1.0",
36+
"version": "11.6.2",
37+
"versionString": "Grafana v11.6.2 (e0ba4b4809)",
38+
}
39+
}
40+
41+
2642
class TestGrafanaClient(unittest.TestCase):
2743
def test_grafana_client_user_agent_default(self):
2844
grafana = GrafanaApi.from_url()
@@ -142,12 +158,11 @@ def test_headerauth(self):
142158

143159
@patch("grafana_client.client.GrafanaClient.__getattr__")
144160
def test_grafana_client_connect_success(self, mock_get):
145-
payload = {"commit": "14e988bd22", "database": "ok", "version": "9.0.1"}
146161
mock_get.return_value = Mock()
147-
mock_get.return_value.return_value = payload
162+
mock_get.return_value.return_value = frontend_settings_buildinfo_payload
148163
grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="3000")
149-
grafana_info = grafana.connect()
150-
self.assertEqual(grafana_info, payload)
164+
grafana_build_info = grafana.connect()
165+
self.assertEqual(grafana_build_info["version"], "11.6.2")
151166

152167
def test_grafana_client_connect_failure(self):
153168
grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="32425")
@@ -156,17 +171,17 @@ def test_grafana_client_connect_failure(self):
156171
@patch("grafana_client.client.GrafanaClient.__getattr__")
157172
def test_grafana_client_version_basic(self, mock_get):
158173
mock_get.return_value = Mock()
159-
mock_get.return_value.return_value = {"commit": "14e988bd22", "database": "ok", "version": "9.0.1"}
174+
mock_get.return_value.return_value = frontend_settings_buildinfo_payload
160175
grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="3000")
161-
self.assertEqual(grafana.version, "9.0.1")
176+
self.assertEqual(grafana.version, "11.6.2")
162177

163178
@patch("grafana_client.client.GrafanaClient.__getattr__")
164179
def test_grafana_client_version_patch(self, mock_get):
165180
mock_get.return_value = Mock()
166181
mock_get.return_value.return_value = {
167-
"commit": "14e988bd22",
168-
"database": "ok",
169-
"version": "11.3.0-75420.patch2-75797",
182+
"buildInfo": {
183+
"version": "11.3.0-75420.patch2-75797",
184+
}
170185
}
171186
grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="3000")
172187
self.assertEqual(grafana.version, "11.3.0")

0 commit comments

Comments
 (0)