Skip to content

Commit 2b95360

Browse files
committedMar 18, 2025·
cap at 3 actions, simplify description
1 parent b51dac3 commit 2b95360

File tree

2 files changed

+17
-20
lines changed
  • src/sentry/workflow_engine/migration_helpers
  • tests/sentry/workflow_engine/migration_helpers

2 files changed

+17
-20
lines changed
 

‎src/sentry/workflow_engine/migration_helpers/utils.py

+11-14
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
from sentry.models.team import Team
55
from sentry.users.services.user import RpcUser
66

7-
MAX_CHARS = 248 # (256 minus space for '...(+3_)')
7+
MAX_ACTIONS = 3
88

99

1010
def get_action_description(action: AlertRuleTriggerAction) -> str:
1111
"""
1212
Returns a human readable action description
1313
"""
14-
action_type_to_string = {
15-
AlertRuleTriggerAction.Type.PAGERDUTY.value: f"PagerDuty to {action.target_display}",
16-
AlertRuleTriggerAction.Type.SLACK.value: f"Slack {action.target_display}",
17-
AlertRuleTriggerAction.Type.MSTEAMS.value: f"Microsoft Teams {action.target_display}",
18-
AlertRuleTriggerAction.Type.SENTRY_APP.value: f"Notify {action.target_display}",
14+
ACTION_TYPE_TO_STRING = {
15+
AlertRuleTriggerAction.Type.PAGERDUTY.value: "PagerDuty",
16+
AlertRuleTriggerAction.Type.SLACK.value: "Slack",
17+
AlertRuleTriggerAction.Type.MSTEAMS.value: "Microsoft Teams",
18+
AlertRuleTriggerAction.Type.OPSGENIE.value: "Opsgenie",
1919
}
2020

2121
if action.type == AlertRuleTriggerAction.Type.EMAIL.value:
@@ -26,13 +26,10 @@ def get_action_description(action: AlertRuleTriggerAction) -> str:
2626
elif action.target_type == AlertRuleTriggerAction.TargetType.TEAM.value:
2727
action_target_team = cast(Team, action.target)
2828
return "Email #" + action_target_team.slug
29-
elif action.type == AlertRuleTriggerAction.Type.OPSGENIE.value:
30-
return f"Opsgenie to {action.target_display}"
31-
elif action.type == AlertRuleTriggerAction.Type.DISCORD.value:
32-
return f"Discord to {action.target_display}"
33-
else:
34-
return action_type_to_string[action.type]
35-
return ""
29+
elif action.type == AlertRuleTriggerAction.Type.SENTRY_APP.value:
30+
return f"Notify {action.target_display}"
31+
32+
return f"Notify {action.target_display} via {ACTION_TYPE_TO_STRING[action.type]}"
3633

3734

3835
def get_workflow_name(alert_rule: AlertRule) -> str:
@@ -54,7 +51,7 @@ def get_workflow_name(alert_rule: AlertRule) -> str:
5451
for action in actions.filter(alert_rule_trigger_id=trigger.id):
5552
description = get_action_description(action) + ", "
5653

57-
if len(name) + len(description) <= MAX_CHARS:
54+
if actions_counter < MAX_ACTIONS:
5855
name += description
5956
actions_counter += 1
6057
else:

‎tests/sentry/workflow_engine/migration_helpers/test_utils.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from unittest import mock
2-
31
from sentry.incidents.models.alert_rule import AlertRuleTriggerAction
42
from sentry.integrations.models.integration import Integration
53
from sentry.integrations.models.organization_integration import OrganizationIntegration
@@ -95,10 +93,9 @@ def test_warning_and_critical(self):
9593
== f"Critical - Email {self.rpc_user.email}, Warning - Email {self.rpc_user.email}"
9694
)
9795

98-
@mock.patch("sentry.workflow_engine.migration_helpers.utils.MAX_CHARS", 50)
9996
def test_many_actions(self):
10097
"""
101-
Test that if we have so many actions we exceed the char limit we format the name as expected
98+
Test that if we have more than 3 actions we format the name as expected
10299
"""
103100
user2 = self.create_user(email="meow@woof.com")
104101
user3 = self.create_user(email="bark@meow.com")
@@ -124,7 +121,10 @@ def test_many_actions(self):
124121
workflow = Workflow.objects.get(id=alert_rule_workflow.workflow.id)
125122

126123
assert self.rpc_user
127-
assert workflow.name == f"Email {self.rpc_user.email}, Email {user2.email}...(+2)"
124+
assert (
125+
workflow.name
126+
== f"Email {self.rpc_user.email}, Email {user2.email}, Email {user3.email}...(+1)"
127+
)
128128

129129
def test_with_integrations(self):
130130
"""
@@ -169,5 +169,5 @@ def test_with_integrations(self):
169169
assert self.rpc_user
170170
assert (
171171
workflow.name
172-
== f"Critical - Email {self.rpc_user.email}, Opsgenie to {self.og_team_table["team"]}, Warning - Email #{self.og_team.slug}, Notify {self.sentry_app.name}, Slack {slack_channel_name}"
172+
== f"Critical - Email {self.rpc_user.email}, Notify {self.og_team_table["team"]} via {self.opsgenie_integration.provider.title()}, Warning - Email #{self.og_team.slug}...(+2)"
173173
)

0 commit comments

Comments
 (0)
Please sign in to comment.