From: Yaarit Hatuka Date: Mon, 17 Nov 2025 05:13:19 +0000 (-0500) Subject: mgr/callhome: fix timestamp from Prometheus X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ebe53ae0560c4e022362a973d9c6d112ae036e08;p=ceph-ci.git mgr/callhome: fix timestamp from Prometheus The timestamp from Prometheus uses nanoseconds while we expect microseconds. Resolves: rhbz#2408379 Signed-off-by: Yaarit Hatuka --- diff --git a/src/pybind/mgr/call_home_agent/report_service.py b/src/pybind/mgr/call_home_agent/report_service.py index cc20f239b3c..fd29ecf5dcc 100644 --- a/src/pybind/mgr/call_home_agent/report_service.py +++ b/src/pybind/mgr/call_home_agent/report_service.py @@ -95,7 +95,7 @@ class EventService(EventGeneric): "ceph_versions": versions, "software": { "diagnostic_provided": True, - "ibm_ceph_version": "7.1.0" # TODO: change to 9.0.0 after the value is available + "ibm_ceph_version": "9.0.0" if self.agent.target_space == "prod" else "8.0.0" } } } ) diff --git a/src/pybind/mgr/call_home_agent/report_status_alerts.py b/src/pybind/mgr/call_home_agent/report_status_alerts.py index 1a0d33c0ad0..4413d671ae1 100644 --- a/src/pybind/mgr/call_home_agent/report_status_alerts.py +++ b/src/pybind/mgr/call_home_agent/report_status_alerts.py @@ -62,6 +62,24 @@ class EventStatusAlerts(EventGeneric): self.set_content(content) return self + def normalize_ts(self, ts: str) -> str: + # Normalize timestamps from Prometheus to use microseconds and a + # '+00:00' time zone instead of nanoseconds and "Z", for example: + # 2025-05-10T08:58:16.720197621Z (ts from Prometheus) + # 2025-05-10T08:58:16.720197+00:00 + + # Prometheus displays time in UTC, and always ends the string with 'Z'. + # Convert "Z" to "+00:00" + ts = ts.replace("Z", "+00:00") + + main_ts, tz = ts.split("+") + if '.' in ts: + date, frac = main_ts.split(".") + frac = frac[:6] # truncate nanoseconds → microseconds + main_ts = f"{date}.{frac}" + + return f"{main_ts}+{tz}" + def service_events(self, alerts: list) -> None: if self.agent.disable_service_events: return @@ -82,7 +100,7 @@ class EventStatusAlerts(EventGeneric): return # don't send more than one service event per hour by default new_events = list(filter( - lambda e: 'activeAt' in e and datetime.fromisoformat(e['activeAt'].replace("Z", "+00:00")).timestamp() > last_service_events_sent, + lambda e: 'activeAt' in e and datetime.fromisoformat(self.normalize_ts(e['activeAt'])).timestamp() > last_service_events_sent, service_events_alerts )) if not new_events: