Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Grafana version parsing for patch releases #185

Merged
merged 1 commit into from
Sep 16, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CHANGELOG

## unreleased
- Improve Grafana version parsing for patch releases like `11.3.0-75420.patch2-75797`
Thanks, @Zhuse.


## 4.1.0 (2024-04-14)
Expand Down
2 changes: 2 additions & 0 deletions grafana_client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def version(self):
if not self._grafana_info:
self._grafana_info = self.health.check()
version = self._grafana_info.get("version", None)
if version:
version = str(version).rsplit("-")[0]
logger.info(f"Inquired Grafana version: {version}")
return version

Expand Down
13 changes: 12 additions & 1 deletion test/test_grafana_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,23 @@ def test_grafana_client_connect_failure(self):
self.assertRaises(niquests.exceptions.ConnectionError, lambda: grafana.connect())

@patch("grafana_client.client.GrafanaClient.__getattr__")
def test_grafana_client_version(self, mock_get):
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"}
grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="3000")
self.assertEqual(grafana.version, "9.0.1")

@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",
}
grafana = GrafanaApi(auth=None, host="localhost", url_path_prefix="", protocol="http", port="3000")
self.assertEqual(grafana.version, "11.3.0")

def test_grafana_client_non_json_response(self):
grafana = GrafanaApi.from_url("https://example.org/")
self.assertRaises((GrafanaClientError, GrafanaServerError), lambda: grafana.connect())
Expand Down
Loading