Browse Source

fix(metric_alerts): Fix Slack timestamp footer (#24733)

* fix(metric_alerts): Fix Slack timestamp footer

Fix Slack timestamp footer to include 'started' to avoid confusion.

FIXES WOR-396

* fix tests
Kelly Carino 4 years ago
parent
commit
e85ea88128

+ 7 - 2
src/sentry/integrations/slack/utils.py

@@ -326,6 +326,12 @@ def build_incident_attachment(action, incident, metric_value=None, method=None):
         "Critical": LEVEL_TO_COLOR["fatal"],
     }
 
+    incident_footer_ts = (
+        "<!date^{:.0f}^Sentry Incident - Started {} at {} | Sentry Incident>".format(
+            to_timestamp(data["ts"]), "{date_pretty}", "{time}"
+        )
+    )
+
     return {
         "fallback": data["title"],
         "title": data["title"],
@@ -334,8 +340,7 @@ def build_incident_attachment(action, incident, metric_value=None, method=None):
         "fields": [],
         "mrkdwn_in": ["text"],
         "footer_icon": data["logo_url"],
-        "footer": "Sentry Incident",
-        "ts": to_timestamp(data["ts"]),
+        "footer": incident_footer_ts,
         "color": colors[data["status"]],
         "actions": [],
     }

+ 12 - 4
tests/sentry/integrations/slack/test_utils.py

@@ -104,6 +104,11 @@ class BuildIncidentAttachmentTest(TestCase):
             alert_rule_trigger=trigger, triggered_for_incident=incident
         )
         title = f"Resolved: {alert_rule.name}"
+        incident_footer_ts = (
+            "<!date^{:.0f}^Sentry Incident - Started {} at {} | Sentry Incident>".format(
+                to_timestamp(incident.date_started), "{date_pretty}", "{time}"
+            )
+        )
         assert build_incident_attachment(action, incident) == {
             "fallback": title,
             "title": title,
@@ -120,8 +125,7 @@ class BuildIncidentAttachmentTest(TestCase):
             "fields": [],
             "mrkdwn_in": ["text"],
             "footer_icon": logo_url,
-            "footer": "Sentry Incident",
-            "ts": to_timestamp(incident.date_started),
+            "footer": incident_footer_ts,
             "color": RESOLVED_COLOR,
             "actions": [],
         }
@@ -136,6 +140,11 @@ class BuildIncidentAttachmentTest(TestCase):
         action = self.create_alert_rule_trigger_action(
             alert_rule_trigger=trigger, triggered_for_incident=incident
         )
+        incident_footer_ts = (
+            "<!date^{:.0f}^Sentry Incident - Started {} at {} | Sentry Incident>".format(
+                to_timestamp(incident.date_started), "{date_pretty}", "{time}"
+            )
+        )
         # This should fail because it pulls status from `action` instead of `incident`
         assert build_incident_attachment(
             action, incident, metric_value=metric_value, method="fire"
@@ -155,8 +164,7 @@ class BuildIncidentAttachmentTest(TestCase):
             "fields": [],
             "mrkdwn_in": ["text"],
             "footer_icon": logo_url,
-            "footer": "Sentry Incident",
-            "ts": to_timestamp(incident.date_started),
+            "footer": incident_footer_ts,
             "color": LEVEL_TO_COLOR["fatal"],
             "actions": [],
         }