Skip to content

Commit a3a9716

Browse files
committed
de-jargon alerts
1 parent 54c3cec commit a3a9716

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

cabotage/celery/tasks/notify.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
"TraefikHighLatency": "http.latency",
5353
}
5454

55+
# Human-friendly display names for Alertmanager alertnames.
56+
ALERTNAME_DISPLAY = {
57+
"ResidentDeploymentOOMKilled": "Out of Memory",
58+
"ResidentDeploymentCrashLoop": "Crash Loop",
59+
"TraefikHighErrorRate": "High Error Rate",
60+
"TraefikHighLatency": "High Latency",
61+
}
62+
5563

5664
def _format_app_path(application, app_env):
5765
org = application.project.organization
@@ -226,12 +234,13 @@ def format_alert_message(alert, application, app_env):
226234
summary = alert.annotations.get("summary", "")
227235
app_path = _format_app_path(application, app_env) if application else None
228236
app_url = cabotage_url(application) if application else None
237+
display_name = ALERTNAME_DISPLAY.get(alert.alertname, alert.alertname)
229238

230239
if alert.status == "resolved":
231-
title = f"\u2705 RESOLVED: {alert.alertname}"
240+
title = f"\u2705 Resolved: {display_name}"
232241
color_hex, color_int = COLOR_GREEN, DISCORD_GREEN
233242
else:
234-
title = f"\U0001f534 FIRING: {alert.alertname}"
243+
title = f"\U0001f534 {display_name}"
235244
color_hex, color_int = COLOR_RED, DISCORD_RED
236245

237246
body_parts = []

tests/test_notification_dispatch.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ def test_firing_message(self, db_session, firing_alert, application, app_env):
167167
assert "slack_attachments" in result
168168
assert "discord_embeds" in result
169169
text = result["text"]
170-
assert "FIRING" in text
171-
assert "ResidentDeploymentOOMKilled" in text
170+
assert "Out of Memory" in text
172171
assert application.project.organization.slug in text
173172
# Slack attachment has color bar
174173
assert result["slack_attachments"][0]["color"] == "#e74c3c"
@@ -177,15 +176,14 @@ def test_firing_message(self, db_session, firing_alert, application, app_env):
177176

178177
def test_resolved_message(self, db_session, resolved_alert, application, app_env):
179178
result = format_alert_message(resolved_alert, application, app_env)
180-
assert "RESOLVED" in result["text"]
179+
assert "Resolved" in result["text"]
181180
assert "12m 34s" in result["text"]
182181
assert result["slack_attachments"][0]["color"] == "#2ecc71"
183182
assert result["discord_embeds"][0]["color"] == 0x2ECC71
184183

185184
def test_message_without_application(self, db_session, firing_alert):
186185
result = format_alert_message(firing_alert, None, None)
187-
assert "FIRING" in result["text"]
188-
assert "ResidentDeploymentOOMKilled" in result["text"]
186+
assert "Out of Memory" in result["text"]
189187

190188

191189
class TestFormatPipelineMessage:
@@ -548,7 +546,7 @@ def test_dispatches_for_firing_alert(
548546
assert args[1] == "discord"
549547
assert args[2] == "D001"
550548
message = args[6]
551-
assert "FIRING" in message["text"]
549+
assert "Out of Memory" in message["text"]
552550
assert message.get("discord_embeds")
553551

554552
def test_skips_alert_without_application(self, db_session, org):

0 commit comments

Comments
 (0)