From 1585f6327b90e01a67312aba862dd76804eeee6b Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sat, 26 Jul 2025 23:55:59 +0200 Subject: [PATCH] AMG compatibility: Fetch Grafana version from `/api/frontend/settings` ... instead of `/api/health`. --- CHANGELOG.md | 5 ++ grafana_client/elements/_async/health.py | 6 ++- grafana_client/elements/health.py | 6 ++- test/elements/test_dashboard.py | 8 +-- test/elements/test_datasource_base.py | 56 ++++++++++----------- test/elements/test_datasource_health.py | 52 +++++++++---------- test/elements/test_health.py | 7 ++- test/elements/test_libraryelement.py | 64 ++++++++++++------------ test/elements/test_team.py | 8 +-- test/test_grafana_client.py | 33 ++++++++---- 10 files changed, 134 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81c45bf..2d5aa33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/grafana_client/elements/_async/health.py b/grafana_client/elements/_async/health.py index f899229..810adfa 100644 --- a/grafana_client/elements/_async/health.py +++ b/grafana_client/elements/_async/health.py @@ -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") diff --git a/grafana_client/elements/health.py b/grafana_client/elements/health.py index ca00880..fbf7203 100644 --- a/grafana_client/elements/health.py +++ b/grafana_client/elements/health.py @@ -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") diff --git a/test/elements/test_dashboard.py b/test/elements/test_dashboard.py index f8a9ed1..1a92f6c 100644 --- a/test/elements/test_dashboard.py +++ b/test/elements/test_dashboard.py @@ -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", @@ -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") diff --git a/test/elements/test_datasource_base.py b/test/elements/test_datasource_base.py index 33246e3..77f9e2e 100644 --- a/test/elements/test_datasource_base.py +++ b/test/elements/test_datasource_base.py @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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", @@ -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", @@ -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", @@ -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__" diff --git a/test/elements/test_datasource_health.py b/test/elements/test_datasource_health.py index 7055c8f..6c6bb8f 100644 --- a/test/elements/test_datasource_health.py +++ b/test/elements/test_datasource_health.py @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", diff --git a/test/elements/test_health.py b/test/elements/test_health.py index 211aaee..47708e6 100644 --- a/test/elements/test_health.py +++ b/test/elements/test_health.py @@ -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") diff --git a/test/elements/test_libraryelement.py b/test/elements/test_libraryelement.py index 9af7585..176ba11 100644 --- a/test/elements/test_libraryelement.py +++ b/test/elements/test_libraryelement.py @@ -589,8 +589,8 @@ class LibraryElementTestCase(unittest.TestCase): } } - HealthResponsePre8_2: dict = {"commit": "unknown", "database": "ok", "version": "8.1.8"} - HealthResponsePost8_2: dict = {"commit": "unknown-dev", "database": "ok", "version": "10.2.2"} + HealthResponsePre8_2: dict = {"buildInfo": {"commit": "unknown", "version": "8.1.8"}} + HealthResponsePost8_2: dict = {"buildInfo": {"commit": "unknown-dev", "version": "10.2.2"}} def setUp(self): self.grafana = GrafanaApi(("admin", "admin"), host="localhost", url_path_prefix="", protocol="http") @@ -598,7 +598,7 @@ def setUp(self): @requests_mock.Mocker() def test_get_library_element(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.get( @@ -611,7 +611,7 @@ def test_get_library_element(self, m): @requests_mock.Mocker() def test_get_library_element_grafana_pre_8_2(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.get( @@ -628,7 +628,7 @@ def test_get_library_element_grafana_pre_8_2(self, m): @requests_mock.Mocker() def test_get_library_element_notfound(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.get( @@ -644,7 +644,7 @@ def test_get_library_element_notfound(self, m): @requests_mock.Mocker() def test_get_library_element_notfound_grafana_pre_8_2(self, m): def custom_matcher(request): - if request.path_url == "/api/health": + if request.path_url == "/api/frontend/settings": return None resp = requests.Response() resp.status_code = 404 @@ -653,7 +653,7 @@ def custom_matcher(request): return resp m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.add_matcher(custom_matcher) @@ -667,7 +667,7 @@ def custom_matcher(request): @requests_mock.Mocker() def test_get_library_element_by_name(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.get( @@ -680,7 +680,7 @@ def test_get_library_element_by_name(self, m): @requests_mock.Mocker() def test_get_library_element_by_name_grafana_pre_8_2(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.get( @@ -697,7 +697,7 @@ def test_get_library_element_by_name_grafana_pre_8_2(self, m): @requests_mock.Mocker() def test_get_library_element_by_name_notfound(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.get( @@ -713,7 +713,7 @@ def test_get_library_element_by_name_notfound(self, m): @requests_mock.Mocker() def test_get_library_element_by_name_notfound_grafana_pre_8_2(self, m): def custom_matcher(request): - if request.path_url == "/api/health": + if request.path_url == "/api/frontend/settings": return None resp = requests.Response() resp.status_code = 404 @@ -722,7 +722,7 @@ def custom_matcher(request): return resp m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.add_matcher(custom_matcher) @@ -736,7 +736,7 @@ def custom_matcher(request): @requests_mock.Mocker() def test_get_library_element_connections(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.get( @@ -753,7 +753,7 @@ def test_get_library_element_connections(self, m): @requests_mock.Mocker() def test_get_library_element_connections_grafana_pre_8_2(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.get( @@ -770,7 +770,7 @@ def test_get_library_element_connections_grafana_pre_8_2(self, m): @requests_mock.Mocker() def test_get_library_element_connections_notfound(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.get( @@ -786,7 +786,7 @@ def test_get_library_element_connections_notfound(self, m): @requests_mock.Mocker() def test_get_library_element_connections_notfound_grafana_pre_8_2(self, m): def custom_matcher(request): - if request.path_url == "/api/health": + if request.path_url == "/api/frontend/settings": return None resp = requests.Response() resp.status_code = 404 @@ -795,7 +795,7 @@ def custom_matcher(request): return resp m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.add_matcher(custom_matcher) @@ -809,7 +809,7 @@ def custom_matcher(request): @requests_mock.Mocker() def test_get_library_element_connections_noconnections(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.get( @@ -824,7 +824,7 @@ def test_get_library_element_connections_noconnections(self, m): @requests_mock.Mocker() def test_get_library_element_connections_noconnections_grafana_pre_8_2(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.get( @@ -841,7 +841,7 @@ def test_get_library_element_connections_noconnections_grafana_pre_8_2(self, m): @requests_mock.Mocker() def test_create_library_element(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.post( @@ -864,7 +864,7 @@ def test_create_library_element(self, m): @requests_mock.Mocker() def test_create_library_element_grafana_pre_8_2(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.post( @@ -886,7 +886,7 @@ def test_create_library_element_grafana_pre_8_2(self, m): @requests_mock.Mocker() def test_create_library_element_already_exists(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.post( @@ -907,7 +907,7 @@ def test_create_library_element_already_exists(self, m): @requests_mock.Mocker() def test_update_library_element(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.patch( @@ -938,7 +938,7 @@ def test_update_library_element(self, m): @requests_mock.Mocker() def test_update_library_element_grafana_pre_8_2(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.patch( @@ -961,7 +961,7 @@ def test_update_library_element_grafana_pre_8_2(self, m): @requests_mock.Mocker() def test_update_library_element_notfound(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.patch( @@ -983,7 +983,7 @@ def test_update_library_element_notfound(self, m): @requests_mock.Mocker() def test_delete_library_element_connections(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.delete( @@ -999,7 +999,7 @@ def test_delete_library_element_connections(self, m): @requests_mock.Mocker() def test_delete_library_element_noconnections(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.delete( @@ -1014,7 +1014,7 @@ def test_delete_library_element_noconnections(self, m): @requests_mock.Mocker() def test_delete_library_element_notfound(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.delete( @@ -1030,7 +1030,7 @@ def test_delete_library_element_notfound(self, m): @requests_mock.Mocker() def test_delete_library_element_notfound_grafana_pre_8_2(self, m): def custom_matcher(request): - if request.path_url == "/api/health": + if request.path_url == "/api/frontend/settings": return None resp = requests.Response() resp.status_code = 404 @@ -1039,7 +1039,7 @@ def custom_matcher(request): return resp m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.add_matcher(custom_matcher) @@ -1053,7 +1053,7 @@ def custom_matcher(request): @requests_mock.Mocker() def test_list_library_elements(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePost8_2, ) m.get( @@ -1073,7 +1073,7 @@ def test_list_library_elements(self, m): @requests_mock.Mocker() def test_list_library_elements_grafana_pre_8_2(self, m): m.get( - "http://localhost/api/health", + "http://localhost/api/frontend/settings", json=LibraryElementTestCase.HealthResponsePre8_2, ) m.get( diff --git a/test/elements/test_team.py b/test/elements/test_team.py index d95a9c0..b21cef2 100644 --- a/test/elements/test_team.py +++ b/test/elements/test_team.py @@ -336,8 +336,8 @@ def test_add_team_external_group(self, m): @requests_mock.Mocker() def test_remove_team_external_group_grafana_1020(self, m): m.get( - "http://localhost/api/health", - json={"commit": "unknown", "database": "ok", "version": "10.2.0"}, + "http://localhost/api/frontend/settings", + json={"buildInfo": {"commit": "unknown", "version": "10.2.0"}}, ) m.delete( @@ -350,8 +350,8 @@ def test_remove_team_external_group_grafana_1020(self, m): @requests_mock.Mocker() def test_remove_team_external_group(self, m): m.get( - "http://localhost/api/health", - json={"commit": "unknown", "database": "ok", "version": "10.1.0"}, + "http://localhost/api/frontend/settings", + json={"buildInfo": {"commit": "unknown", "version": "10.1.0"}}, ) m.delete( diff --git a/test/test_grafana_client.py b/test/test_grafana_client.py index f94817e..170f1ad 100644 --- a/test/test_grafana_client.py +++ b/test/test_grafana_client.py @@ -23,6 +23,22 @@ def json(self): return self.json_data +frontend_settings_buildinfo_payload = { + "buildInfo": { + "buildstamp": 1753567501, + "commit": "e0ba4b480954f8a33aa2cff3229f6bcc05777bd9", + "commitShort": "e0ba4b4809", + "edition": "Open Source", + "env": "production", + "hasUpdate": True, + "hideVersion": False, + "latestVersion": "12.1.0", + "version": "11.6.2", + "versionString": "Grafana v11.6.2 (e0ba4b4809)", + } +} + + class TestGrafanaClient(unittest.TestCase): def test_grafana_client_user_agent_default(self): grafana = GrafanaApi.from_url() @@ -142,12 +158,11 @@ def test_headerauth(self): @patch("grafana_client.client.GrafanaClient.__getattr__") def test_grafana_client_connect_success(self, mock_get): - payload = {"commit": "14e988bd22", "database": "ok", "version": "9.0.1"} mock_get.return_value = Mock() - mock_get.return_value.return_value = payload + mock_get.return_value.return_value = frontend_settings_buildinfo_payload grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="3000") - grafana_info = grafana.connect() - self.assertEqual(grafana_info, payload) + grafana_build_info = grafana.connect() + self.assertEqual(grafana_build_info["version"], "11.6.2") def test_grafana_client_connect_failure(self): grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="32425") @@ -156,17 +171,17 @@ def test_grafana_client_connect_failure(self): @patch("grafana_client.client.GrafanaClient.__getattr__") def test_grafana_client_version_basic(self, mock_get): mock_get.return_value = Mock() - mock_get.return_value.return_value = {"commit": "14e988bd22", "database": "ok", "version": "9.0.1"} + mock_get.return_value.return_value = frontend_settings_buildinfo_payload grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="3000") - self.assertEqual(grafana.version, "9.0.1") + self.assertEqual(grafana.version, "11.6.2") @patch("grafana_client.client.GrafanaClient.__getattr__") def test_grafana_client_version_patch(self, mock_get): mock_get.return_value = Mock() mock_get.return_value.return_value = { - "commit": "14e988bd22", - "database": "ok", - "version": "11.3.0-75420.patch2-75797", + "buildInfo": { + "version": "11.3.0-75420.patch2-75797", + } } grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="3000") self.assertEqual(grafana.version, "11.3.0")