Skip to content

Commit ddf8ca8

Browse files
committed
Enhance llmalert job by converting 'metric_timestamp' to datetime and formatting anomaly explanations with timestamps
1 parent 8d55530 commit ddf8ca8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

anomstack/jobs/llmalert.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ def llmalert(context, df: pd.DataFrame) -> pd.DataFrame:
155155
left_on="metric_timestamp",
156156
right_on="anomaly_timestamp",
157157
)
158+
df_metric["metric_timestamp"] = pd.to_datetime(df_metric["metric_timestamp"], format="%Y-%m-%d %H:%M:%S")
158159

159160
# if there are detected anomalies set metric_alert to 1 if it is not already 1
160161
if not df_metric["metric_alert"].any():
@@ -170,9 +171,12 @@ def llmalert(context, df: pd.DataFrame) -> pd.DataFrame:
170171
latest_anomaly_timestamp = df_metric[
171172
df_metric["anomaly_timestamp"].notnull()
172173
]["anomaly_timestamp"].max()
174+
# prefix each explanation with the timestamp
173175
anomaly_explanations = df_metric[
174176
df_metric["anomaly_timestamp"].notnull()
175-
]["anomaly_explanation"].unique()
177+
][["anomaly_timestamp", "anomaly_explanation"]].apply(
178+
lambda x: f"{x[0]}: {x[1]}", axis=1
179+
).sort_values(ascending=False)
176180
anomaly_explanations = "\n- ".join(anomaly_explanations)
177181
metric_timestamp_max = df_metric["metric_timestamp"].max()
178182
alert_title = (

0 commit comments

Comments
 (0)