File tree Expand file tree Collapse file tree
keep/providers/grafana_provider Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77import hashlib
88import json
99import logging
10+ import re
1011import time
1112
1213import 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 } "
You can’t perform that action at this time.
0 commit comments