Skip to content

Commit e0191be

Browse files
authored
fix: avoid version validation error in grafana provider (#6102)
1 parent 2ba721b commit e0191be

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

keep/providers/grafana_provider/grafana_provider.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import hashlib
88
import json
99
import logging
10+
import re
1011
import time
1112

1213
import pydantic
@@ -397,7 +398,12 @@ def _format_legacy_alert(event: dict) -> AlertDto:
397398
return [alert_dto]
398399

399400
def _get_grafana_version(self) -> str:
400-
"""Get the Grafana version."""
401+
"""Get the Grafana version (PEP 440-compatible for comparison).
402+
403+
Grafana Cloud/Enterprise returns versions like '13.0.0-22843068776.patch2'
404+
which packaging.version.Version cannot parse. We extract the base
405+
semantic version (e.g. '13.0.0') before returning.
406+
"""
401407
try:
402408
headers = {"Authorization": f"Bearer {self.authentication_config.token}"}
403409
health_url = f"{self.authentication_config.host}/api/health"
@@ -406,7 +412,11 @@ def _get_grafana_version(self) -> str:
406412

407413
if resp.ok:
408414
health_data = resp.json()
409-
return health_data.get("version", "unknown")
415+
raw_version = health_data.get("version", "unknown")
416+
if not raw_version or raw_version == "unknown":
417+
return "0.0.0"
418+
match = re.match(r"^(\d+\.\d+(?:\.\d+)?)", raw_version)
419+
return match.group(1) if match else "0.0.0"
410420
else:
411421
self.logger.warning(
412422
f"Failed to get Grafana version: {resp.status_code}"

0 commit comments

Comments
 (0)