FIX: Normalize "active" to "firing" in process_grouped_alerts

FIX: Normalize “active” to “firing” in process_grouped_alerts

Prometheus alertmanager uses different terminology in the API compared to the webhooks

diff --git a/app/jobs/regular/process_grouped_alerts.rb b/app/jobs/regular/process_grouped_alerts.rb
index cc5b478..ca37c0c 100644
--- a/app/jobs/regular/process_grouped_alerts.rb
+++ b/app/jobs/regular/process_grouped_alerts.rb
@@ -49,6 +49,11 @@ module Jobs
       end
     end
 
+    def normalize_status(status)
+      return "firing" if status == "active"
+      status
+    end
+
     def update_open_alerts(receiver, active_alerts, graph_url)
       Topic.open_alerts.each do |topic|
         DistributedMutex.synchronize("prom_alert_receiver_topic_#{topic.id}") do
@@ -63,8 +68,8 @@ module Jobs
                   STALE_DURATION.minute.ago > DateTime.parse(stored_alert["starts_at"])
                 stored_alert["status"] = "stale"
                 updated = true
-              elsif active_alert && stored_alert["status"] != active_alert["status"]["state"]
-                stored_alert["status"] = active_alert["status"]["state"]
+              elsif active_alert && stored_alert["status"] != normalize_status(active_alert["status"]["state"])
+                stored_alert["status"] = normalize_status(active_alert["status"]["state"])
                 stored_alert["description"] = active_alert.dig("annotations", "description")
                 updated = true
               end
diff --git a/spec/integration/discourse_prometheus_alert_receiver/receiver_controller_spec.rb b/spec/integration/discourse_prometheus_alert_receiver/receiver_controller_spec.rb
index 7d01c4e..dbb1716 100644
--- a/spec/integration/discourse_prometheus_alert_receiver/receiver_controller_spec.rb
+++ b/spec/integration/discourse_prometheus_alert_receiver/receiver_controller_spec.rb
@@ -455,7 +455,7 @@ RSpec.describe DiscoursePrometheusAlertReceiver::ReceiverController do
 
             payload["data"].find {
               |a| a["labels"]["id"] == "somethingnotfunny"
-            }["status"]["state"] = "firing"
+            }["status"]["state"] = "active"
 
             post "/prometheus/receiver/grouped/alerts/#{token}", params: payload

GitHub sha: da7d0bdf

1 Like