Skip to content

Commit b346242

Browse files
committed
AMG compatibility: Fetch Grafana version from /api/frontend/settings
... instead of `/api/health`.
1 parent 4902dae commit b346242

File tree

10 files changed

+134
-111
lines changed

10 files changed

+134
-111
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# CHANGELOG
22

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

510
## 4.3.3 (2025-07-27)
611
- Async: Fixed code generator for edge cases at "smartquery" interface. Thanks, @JIAQIA.

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/elements/test_dashboard.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def test_get_dashboard(self, m):
3636
@requests_mock.Mocker()
3737
def test_get_dashboard_by_name_grafana7(self, m):
3838
m.get(
39-
"http://localhost/api/health",
40-
json={"commit": "6f8c1d9fe4", "database": "ok", "version": "7.5.11"},
39+
"http://localhost/api/frontend/settings",
40+
json={"buildInfo": {"commit": "6f8c1d9fe4", "version": "7.5.11"}},
4141
)
4242
m.get(
4343
"http://localhost/api/dashboards/db/Production Overview",
@@ -64,8 +64,8 @@ def test_get_dashboard_by_name_grafana7(self, m):
6464
@requests_mock.Mocker()
6565
def test_get_dashboard_by_name_grafana8(self, m):
6666
m.get(
67-
"http://localhost/api/health",
68-
json={"commit": "unknown", "database": "ok", "version": "8.0.2"},
67+
"http://localhost/api/frontend/settings",
68+
json={"buildInfo": {"commit": "unknown", "version": "8.0.2"}},
6969
)
7070
with self.assertRaises(DeprecationWarning) as ex:
7171
self.grafana.dashboard.get_dashboard_by_name("foobar")

test/elements/test_datasource_base.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ def test_delete_datasource_by_name(self, m):
132132
@requests_mock.Mocker()
133133
def test_enable_datasource_permissions(self, m):
134134
m.get(
135-
"http://localhost/api/health",
136-
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
135+
"http://localhost/api/frontend/settings",
136+
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
137137
)
138138

139139
m.post(
@@ -147,8 +147,8 @@ def test_enable_datasource_permissions(self, m):
147147
@requests_mock.Mocker()
148148
def test_enable_datasource_permissions_grafana1023(self, m):
149149
m.get(
150-
"http://localhost/api/health",
151-
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
150+
"http://localhost/api/frontend/settings",
151+
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
152152
)
153153

154154
with patch(
@@ -162,8 +162,8 @@ def test_enable_datasource_permissions_grafana1023(self, m):
162162
@requests_mock.Mocker()
163163
def test_disable_datasource_permissions(self, m):
164164
m.get(
165-
"http://localhost/api/health",
166-
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
165+
"http://localhost/api/frontend/settings",
166+
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
167167
)
168168

169169
m.post(
@@ -177,8 +177,8 @@ def test_disable_datasource_permissions(self, m):
177177
@requests_mock.Mocker()
178178
def test_disable_datasource_permissions_grafana1023(self, m):
179179
m.get(
180-
"http://localhost/api/health",
181-
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
180+
"http://localhost/api/frontend/settings",
181+
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
182182
)
183183

184184
with patch(
@@ -192,8 +192,8 @@ def test_disable_datasource_permissions_grafana1023(self, m):
192192
@requests_mock.Mocker()
193193
def test_get_datasource_permissions(self, m):
194194
m.get(
195-
"http://localhost/api/health",
196-
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
195+
"http://localhost/api/frontend/settings",
196+
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
197197
)
198198

199199
m.get(
@@ -207,8 +207,8 @@ def test_get_datasource_permissions(self, m):
207207
@requests_mock.Mocker()
208208
def test_get_datasource_permissions_grafana1023(self, m):
209209
m.get(
210-
"http://localhost/api/health",
211-
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
210+
"http://localhost/api/frontend/settings",
211+
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
212212
)
213213

214214
with patch(
@@ -222,8 +222,8 @@ def test_get_datasource_permissions_grafana1023(self, m):
222222
@requests_mock.Mocker()
223223
def test_add_datasource_permissions(self, m):
224224
m.get(
225-
"http://localhost/api/health",
226-
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
225+
"http://localhost/api/frontend/settings",
226+
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
227227
)
228228

229229
m.post(
@@ -237,8 +237,8 @@ def test_add_datasource_permissions(self, m):
237237
@requests_mock.Mocker()
238238
def test_add_datasource_permissions_grafana1023(self, m):
239239
m.get(
240-
"http://localhost/api/health",
241-
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
240+
"http://localhost/api/frontend/settings",
241+
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
242242
)
243243

244244
with patch(
@@ -252,8 +252,8 @@ def test_add_datasource_permissions_grafana1023(self, m):
252252
@requests_mock.Mocker()
253253
def test_remove_datasource_permissions(self, m):
254254
m.get(
255-
"http://localhost/api/health",
256-
json={"commit": "unknown", "database": "ok", "version": "10.2.1"},
255+
"http://localhost/api/frontend/settings",
256+
json={"buildInfo": {"commit": "unknown", "version": "10.2.1"}},
257257
)
258258

259259
m.delete(
@@ -267,8 +267,8 @@ def test_remove_datasource_permissions(self, m):
267267
@requests_mock.Mocker()
268268
def test_remove_datasource_permissions_grafana1023(self, m):
269269
m.get(
270-
"http://localhost/api/health",
271-
json={"commit": "unknown", "database": "ok", "version": "10.2.3"},
270+
"http://localhost/api/frontend/settings",
271+
json={"buildInfo": {"commit": "unknown", "version": "10.2.3"}},
272272
)
273273

274274
with patch(
@@ -395,8 +395,8 @@ def test_query_with_datasource_prometheus_grafana7(self, m):
395395
# Mock the version inquiry request, because `smartquery` needs
396396
# it, as Prometheus responses differ between versions.
397397
m.get(
398-
"http://localhost/api/health",
399-
json={"commit": "unknown", "database": "ok", "version": "7.0.1"},
398+
"http://localhost/api/frontend/settings",
399+
json={"buildInfo": {"commit": "unknown", "version": "7.0.1"}},
400400
)
401401
m.post(
402402
"http://localhost/api/ds/query",
@@ -411,8 +411,8 @@ def test_query_with_datasource_prometheus_grafana9(self, m):
411411
# Mock the version inquiry request, because `smartquery` needs
412412
# it, as Prometheus responses differ between versions.
413413
m.get(
414-
"http://localhost/api/health",
415-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
414+
"http://localhost/api/frontend/settings",
415+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
416416
)
417417
m.post(
418418
"http://localhost/api/ds/query",
@@ -453,8 +453,8 @@ def test_query_with_datasource_identifier(self, m):
453453
# Mock the version inquiry request, because `smartquery` needs
454454
# it, as Prometheus responses differ between versions.
455455
m.get(
456-
"http://localhost/api/health",
457-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
456+
"http://localhost/api/frontend/settings",
457+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
458458
)
459459
m.get(
460460
"http://localhost/api/datasources/uid/h8KkCLt7z",
@@ -472,8 +472,8 @@ def test_query_unknown_access_type_failure(self, m):
472472
# Mock the version inquiry request, because `smartquery` needs
473473
# it, as Prometheus responses differ between versions.
474474
m.get(
475-
"http://localhost/api/health",
476-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
475+
"http://localhost/api/frontend/settings",
476+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
477477
)
478478
datasource = PROMETHEUS_DATASOURCE.copy()
479479
datasource["access"] = "__UNKNOWN__"

test/elements/test_datasource_health.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ def test_health_check_loki_success_grafana7(self, m):
332332
# Mock the version inquiry request, because `smartquery` needs
333333
# it, as Loki responses differ between versions.
334334
m.get(
335-
"http://localhost/api/health",
336-
json={"commit": "unknown", "database": "ok", "version": "7.0.1"},
335+
"http://localhost/api/frontend/settings",
336+
json={"buildInfo": {"commit": "unknown", "version": "7.0.1"}},
337337
)
338338
m.get(
339339
"http://localhost/api/datasources/uid/vCyglaq7z",
@@ -364,8 +364,8 @@ def test_health_check_loki_success_grafana9(self, m):
364364
# Mock the version inquiry request, because `smartquery` needs
365365
# it, as Loki responses differ between versions.
366366
m.get(
367-
"http://localhost/api/health",
368-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
367+
"http://localhost/api/frontend/settings",
368+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
369369
)
370370
m.get(
371371
"http://localhost/api/datasources/uid/vCyglaq7z",
@@ -396,8 +396,8 @@ def test_health_check_loki_error_response_failure_grafana7(self, m):
396396
# Mock the version inquiry request, because `smartquery` needs
397397
# it, as Loki responses differ between versions.
398398
m.get(
399-
"http://localhost/api/health",
400-
json={"commit": "unknown", "database": "ok", "version": "7.0.1"},
399+
"http://localhost/api/frontend/settings",
400+
json={"buildInfo": {"commit": "unknown", "version": "7.0.1"}},
401401
)
402402
m.get(
403403
"http://localhost/api/datasources/uid/vCyglaq7z",
@@ -428,8 +428,8 @@ def test_health_check_loki_error_response_failure_grafana9(self, m):
428428
# Mock the version inquiry request, because `smartquery` needs
429429
# it, as Loki responses differ between versions.
430430
m.get(
431-
"http://localhost/api/health",
432-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
431+
"http://localhost/api/frontend/settings",
432+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
433433
)
434434
m.get(
435435
"http://localhost/api/datasources/uid/vCyglaq7z",
@@ -565,8 +565,8 @@ def test_health_check_prometheus_healthy_success(self, grafana_version):
565565
# Mock the version inquiry request, because `smartquery` needs
566566
# it, as Prometheus responses differ between versions.
567567
m.get(
568-
"http://localhost/api/health",
569-
json={"commit": "unknown", "database": "ok", "version": grafana_version},
568+
"http://localhost/api/frontend/settings",
569+
json={"buildInfo": {"commit": "unknown", "version": grafana_version}},
570570
)
571571
m.get(
572572
"http://localhost/api/datasources/uid/h8KkCLt7z",
@@ -599,8 +599,8 @@ def test_health_check_prometheus_empty_dataframe_success(self, grafana_version):
599599
# Mock the version inquiry request, because `smartquery` needs
600600
# it, as Prometheus responses differ between versions.
601601
m.get(
602-
"http://localhost/api/health",
603-
json={"commit": "unknown", "database": "ok", "version": grafana_version},
602+
"http://localhost/api/frontend/settings",
603+
json={"buildInfo": {"commit": "unknown", "version": grafana_version}},
604604
)
605605
m.get(
606606
"http://localhost/api/datasources/uid/h8KkCLt7z",
@@ -633,8 +633,8 @@ def test_health_check_prometheus_invalid_dataframe_failure(self, grafana_version
633633
# Mock the version inquiry request, because `smartquery` needs
634634
# it, as Prometheus responses differ between versions.
635635
m.get(
636-
"http://localhost/api/health",
637-
json={"commit": "unknown", "database": "ok", "version": grafana_version},
636+
"http://localhost/api/frontend/settings",
637+
json={"buildInfo": {"commit": "unknown", "version": grafana_version}},
638638
)
639639
m.get(
640640
"http://localhost/api/datasources/uid/h8KkCLt7z",
@@ -1161,8 +1161,8 @@ def setUp(self):
11611161
@requests_mock.Mocker()
11621162
def test_health_inquiry_native_prometheus_success(self, m):
11631163
m.get(
1164-
"http://localhost/api/health",
1165-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
1164+
"http://localhost/api/frontend/settings",
1165+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
11661166
)
11671167
m.get(
11681168
"http://localhost/api/datasources/uid/39mf288en",
@@ -1191,8 +1191,8 @@ def test_health_inquiry_native_prometheus_success(self, m):
11911191
@requests_mock.Mocker()
11921192
def test_health_inquiry_native_prometheus_failure(self, m):
11931193
m.get(
1194-
"http://localhost/api/health",
1195-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
1194+
"http://localhost/api/frontend/settings",
1195+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
11961196
)
11971197
m.get(
11981198
"http://localhost/api/datasources/uid/39mf288en",
@@ -1221,8 +1221,8 @@ def test_health_inquiry_native_prometheus_failure(self, m):
12211221
@requests_mock.Mocker()
12221222
def test_health_inquiry_native_unknown_error_400(self, m):
12231223
m.get(
1224-
"http://localhost/api/health",
1225-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
1224+
"http://localhost/api/frontend/settings",
1225+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
12261226
)
12271227
m.get(
12281228
"http://localhost/api/datasources/uid/39mf288en",
@@ -1252,8 +1252,8 @@ def test_health_inquiry_native_unknown_error_400(self, m):
12521252
@requests_mock.Mocker()
12531253
def test_health_inquiry_native_unknown_error_418(self, m):
12541254
m.get(
1255-
"http://localhost/api/health",
1256-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
1255+
"http://localhost/api/frontend/settings",
1256+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
12571257
)
12581258
m.get(
12591259
"http://localhost/api/datasources/uid/39mf288en",
@@ -1271,8 +1271,8 @@ def test_health_inquiry_native_unknown_error_418(self, m):
12711271
@requests_mock.Mocker()
12721272
def test_health_inquiry_native_prometheus_error_404(self, m):
12731273
m.get(
1274-
"http://localhost/api/health",
1275-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
1274+
"http://localhost/api/frontend/settings",
1275+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
12761276
)
12771277
m.get(
12781278
"http://localhost/api/datasources/uid/h8KkCLt7z",
@@ -1308,8 +1308,8 @@ def test_health_inquiry_native_prometheus_error_404(self, m):
13081308
@requests_mock.Mocker()
13091309
def test_health_inquiry_native_prometheus_error_500(self, m):
13101310
m.get(
1311-
"http://localhost/api/health",
1312-
json={"commit": "14e988bd22", "database": "ok", "version": "9.0.1"},
1311+
"http://localhost/api/frontend/settings",
1312+
json={"buildInfo": {"commit": "14e988bd22", "version": "9.0.1"}},
13131313
)
13141314
m.get(
13151315
"http://localhost/api/datasources/uid/h8KkCLt7z",

test/elements/test_health.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ def setUp(self):
1212
@requests_mock.Mocker()
1313
def test_healthcheck(self, m):
1414
m.get(
15-
"http://localhost/api/health",
16-
json={"commit": "6f8c1d9fe4", "database": "ok", "version": "7.5.11"},
15+
"http://localhost/api/frontend/settings",
16+
json={"buildInfo": {"commit": "6f8c1d9fe4", "version": "7.5.11"}},
1717
)
1818

1919
result = self.grafana.health.check()
20-
self.assertEqual(result["database"], "ok")
21-
self.assertEqual(len(result), 3)
20+
self.assertEqual(result["version"], "7.5.11")

0 commit comments

Comments
 (0)