|
@@ -7,6 +7,7 @@ from sentry.incidents.models import IncidentStatus
|
|
from sentry.integrations.discord.message_builder import LEVEL_TO_COLOR
|
|
from sentry.integrations.discord.message_builder import LEVEL_TO_COLOR
|
|
from sentry.integrations.discord.message_builder.metric_alerts import (
|
|
from sentry.integrations.discord.message_builder.metric_alerts import (
|
|
DiscordMetricAlertMessageBuilder,
|
|
DiscordMetricAlertMessageBuilder,
|
|
|
|
+ get_started_at,
|
|
)
|
|
)
|
|
from sentry.testutils.cases import TestCase
|
|
from sentry.testutils.cases import TestCase
|
|
from sentry.testutils.silo import region_silo_test
|
|
from sentry.testutils.silo import region_silo_test
|
|
@@ -30,12 +31,13 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
},
|
|
},
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
+
|
|
assert DiscordMetricAlertMessageBuilder(self.alert_rule).build() == {
|
|
assert DiscordMetricAlertMessageBuilder(self.alert_rule).build() == {
|
|
"content": "",
|
|
"content": "",
|
|
"embeds": [
|
|
"embeds": [
|
|
{
|
|
{
|
|
"title": title,
|
|
"title": title,
|
|
- "description": f"<{link}|*{title}*> \n",
|
|
|
|
|
|
+ "description": "",
|
|
"url": f"{link}&referrer=discord",
|
|
"url": f"{link}&referrer=discord",
|
|
"color": LEVEL_TO_COLOR["_incident_resolved"],
|
|
"color": LEVEL_TO_COLOR["_incident_resolved"],
|
|
}
|
|
}
|
|
@@ -69,7 +71,7 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
"embeds": [
|
|
"embeds": [
|
|
{
|
|
{
|
|
"title": title,
|
|
"title": title,
|
|
- "description": f"<{link}|*{title}*> \n",
|
|
|
|
|
|
+ "description": get_started_at(incident.date_started),
|
|
"url": f"{link}&referrer=discord",
|
|
"url": f"{link}&referrer=discord",
|
|
"color": LEVEL_TO_COLOR["_incident_resolved"],
|
|
"color": LEVEL_TO_COLOR["_incident_resolved"],
|
|
}
|
|
}
|
|
@@ -78,9 +80,8 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
}
|
|
}
|
|
|
|
|
|
def test_metric_alert_with_active_incident(self):
|
|
def test_metric_alert_with_active_incident(self):
|
|
- incident = self.create_incident(
|
|
|
|
- alert_rule=self.alert_rule, status=IncidentStatus.CRITICAL.value
|
|
|
|
- )
|
|
|
|
|
|
+ new_status = IncidentStatus.CRITICAL.value
|
|
|
|
+ incident = self.create_incident(alert_rule=self.alert_rule, status=new_status)
|
|
trigger = self.create_alert_rule_trigger(self.alert_rule, CRITICAL_TRIGGER_LABEL, 100)
|
|
trigger = self.create_alert_rule_trigger(self.alert_rule, CRITICAL_TRIGGER_LABEL, 100)
|
|
self.create_alert_rule_trigger_action(
|
|
self.create_alert_rule_trigger_action(
|
|
alert_rule_trigger=trigger, triggered_for_incident=incident
|
|
alert_rule_trigger=trigger, triggered_for_incident=incident
|
|
@@ -102,7 +103,7 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
{
|
|
{
|
|
"color": LEVEL_TO_COLOR["fatal"],
|
|
"color": LEVEL_TO_COLOR["fatal"],
|
|
"title": title,
|
|
"title": title,
|
|
- "description": f"<{link}|*{title}*> \n0 events in the last 10 minutes",
|
|
|
|
|
|
+ "description": "0 events in the last 10 minutes",
|
|
"url": f"{link}&referrer=discord",
|
|
"url": f"{link}&referrer=discord",
|
|
}
|
|
}
|
|
],
|
|
],
|
|
@@ -113,7 +114,6 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
incident = self.create_incident(
|
|
incident = self.create_incident(
|
|
alert_rule=self.alert_rule, status=IncidentStatus.CLOSED.value
|
|
alert_rule=self.alert_rule, status=IncidentStatus.CLOSED.value
|
|
)
|
|
)
|
|
-
|
|
|
|
# This test will use the action/method and not the incident to build status
|
|
# This test will use the action/method and not the incident to build status
|
|
title = f"Critical: {self.alert_rule.name}"
|
|
title = f"Critical: {self.alert_rule.name}"
|
|
metric_value = 5000
|
|
metric_value = 5000
|
|
@@ -130,6 +130,7 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
},
|
|
},
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
+
|
|
assert DiscordMetricAlertMessageBuilder(
|
|
assert DiscordMetricAlertMessageBuilder(
|
|
self.alert_rule, incident, IncidentStatus.CRITICAL, metric_value=metric_value
|
|
self.alert_rule, incident, IncidentStatus.CRITICAL, metric_value=metric_value
|
|
).build() == {
|
|
).build() == {
|
|
@@ -138,8 +139,7 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
{
|
|
{
|
|
"title": title,
|
|
"title": title,
|
|
"color": LEVEL_TO_COLOR["fatal"],
|
|
"color": LEVEL_TO_COLOR["fatal"],
|
|
- "description": f"<{link}?alert={incident.identifier}|*{title}*> \n"
|
|
|
|
- f"{metric_value} events in the last 10 minutes",
|
|
|
|
|
|
+ "description": f"{metric_value} events in the last 10 minutes{get_started_at(incident.date_started)}",
|
|
"url": f"{link}?alert={incident.identifier}&referrer=discord",
|
|
"url": f"{link}?alert={incident.identifier}&referrer=discord",
|
|
}
|
|
}
|
|
],
|
|
],
|
|
@@ -147,6 +147,9 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
}
|
|
}
|
|
|
|
|
|
def test_metric_alert_chart(self):
|
|
def test_metric_alert_chart(self):
|
|
|
|
+ incident = self.create_incident(
|
|
|
|
+ alert_rule=self.alert_rule, status=IncidentStatus.OPEN.value
|
|
|
|
+ )
|
|
title = f"Resolved: {self.alert_rule.name}"
|
|
title = f"Resolved: {self.alert_rule.name}"
|
|
link = absolute_uri(
|
|
link = absolute_uri(
|
|
reverse(
|
|
reverse(
|
|
@@ -157,9 +160,7 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
},
|
|
},
|
|
)
|
|
)
|
|
)
|
|
)
|
|
- incident = self.create_incident(
|
|
|
|
- alert_rule=self.alert_rule, status=IncidentStatus.OPEN.value
|
|
|
|
- )
|
|
|
|
|
|
+
|
|
new_status = IncidentStatus.CLOSED
|
|
new_status = IncidentStatus.CLOSED
|
|
assert DiscordMetricAlertMessageBuilder(
|
|
assert DiscordMetricAlertMessageBuilder(
|
|
self.alert_rule, incident, new_status, chart_url="chart_url"
|
|
self.alert_rule, incident, new_status, chart_url="chart_url"
|
|
@@ -168,7 +169,7 @@ class BuildMetricAlertAttachmentTest(TestCase):
|
|
"embeds": [
|
|
"embeds": [
|
|
{
|
|
{
|
|
"title": title,
|
|
"title": title,
|
|
- "description": f"<{link}?alert={incident.identifier}|*{title}*> \n",
|
|
|
|
|
|
+ "description": get_started_at(incident.date_started),
|
|
"url": f"{link}?alert={incident.identifier}&referrer=discord",
|
|
"url": f"{link}?alert={incident.identifier}&referrer=discord",
|
|
"color": 5097329,
|
|
"color": 5097329,
|
|
"image": {"url": "chart_url"},
|
|
"image": {"url": "chart_url"},
|