]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/callhome: fix timestamp from Prometheus
authorYaarit Hatuka <yhatuka@ibm.com>
Mon, 17 Nov 2025 05:13:19 +0000 (00:13 -0500)
committerYaarit Hatuka <yhatuka@redhat.com>
Mon, 17 Nov 2025 05:36:44 +0000 (05:36 +0000)
The timestamp from Prometheus uses nanoseconds while we expect
microseconds.

Resolves: rhbz#2408379
Signed-off-by: Yaarit Hatuka <yhatuka@ibm.com>
src/pybind/mgr/call_home_agent/report_service.py
src/pybind/mgr/call_home_agent/report_status_alerts.py

index cc20f239b3c56c2b7119d4ad4fc8ae2204225ea9..fd29ecf5dccb9e765b07874893db2cb486a073f7 100644 (file)
@@ -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"
                 }
             }
         } )
index 1a0d33c0ad0897791362ad4f532719e0018e8c1a..4413d671ae170a3820fc957b2ef548f42d66b5c9 100644 (file)
@@ -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: