Skip to content

Commit

Permalink
Enhance llmalert job by converting 'metric_timestamp' to datetime and…
Browse files Browse the repository at this point in the history
… formatting anomaly explanations with timestamps
  • Loading branch information
andrewm4894 committed Dec 27, 2024
1 parent 8d55530 commit ddf8ca8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion anomstack/jobs/llmalert.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ def llmalert(context, df: pd.DataFrame) -> pd.DataFrame:
left_on="metric_timestamp",
right_on="anomaly_timestamp",
)
df_metric["metric_timestamp"] = pd.to_datetime(df_metric["metric_timestamp"], format="%Y-%m-%d %H:%M:%S")

# if there are detected anomalies set metric_alert to 1 if it is not already 1
if not df_metric["metric_alert"].any():
Expand All @@ -170,9 +171,12 @@ def llmalert(context, df: pd.DataFrame) -> pd.DataFrame:
latest_anomaly_timestamp = df_metric[
df_metric["anomaly_timestamp"].notnull()
]["anomaly_timestamp"].max()
# prefix each explanation with the timestamp
anomaly_explanations = df_metric[
df_metric["anomaly_timestamp"].notnull()
]["anomaly_explanation"].unique()
][["anomaly_timestamp", "anomaly_explanation"]].apply(
lambda x: f"{x[0]}: {x[1]}", axis=1
).sort_values(ascending=False)
anomaly_explanations = "\n- ".join(anomaly_explanations)
metric_timestamp_max = df_metric["metric_timestamp"].max()
alert_title = (
Expand Down

0 comments on commit ddf8ca8

Please sign in to comment.