Skip to content

Commit 2bf850f

Browse files
authored
chore(aci): setup single processing flag for issue alerts in workflow engine (#95178)
1 parent 5cff5e5 commit 2bf850f

File tree

20 files changed

+99
-49
lines changed

20 files changed

+99
-49
lines changed

src/sentry/digests/notifications.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def unsplit_key(
6868
def event_to_record(
6969
event: Event, rules: Sequence[Rule], notification_uuid: str | None = None
7070
) -> Record:
71+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
72+
7173
if not rules:
7274
logger.warning("Creating record for %s that does not contain any rules!", event)
7375

@@ -77,7 +79,7 @@ def event_to_record(
7779
identifier_key = IdentifierKey.WORKFLOW
7880
for rule in rules:
7981
rule_ids.append(int(get_key_from_rule_data(rule, "workflow_id")))
80-
elif features.has("organizations:workflow-engine-trigger-actions", event.organization):
82+
elif should_fire_workflow_actions(event.organization):
8183
for rule in rules:
8284
rule_ids.append(int(get_key_from_rule_data(rule, "legacy_rule_id")))
8385
else:
@@ -166,6 +168,8 @@ def _build_digest_impl(
166168

167169

168170
def get_rules_from_workflows(project: Project, workflow_ids: set[int]) -> dict[int, Rule]:
171+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
172+
169173
rules: dict[int, Rule] = {}
170174
if not workflow_ids:
171175
return rules
@@ -219,14 +223,16 @@ def get_rules_from_workflows(project: Project, workflow_ids: set[int]) -> dict[i
219223

220224
assert rule.project_id == project.id, "Rule must belong to Project"
221225

222-
if features.has("organizations:workflow-engine-trigger-actions", project.organization):
226+
if should_fire_workflow_actions(project.organization):
223227
rule.data["actions"][0]["legacy_rule_id"] = rule.id
224228

225229
rules[workflow_id] = rule
226230
return rules
227231

228232

229233
def build_digest(project: Project, records: Sequence[Record]) -> DigestInfo:
234+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
235+
230236
if not records:
231237
return DigestInfo({}, {}, {})
232238

@@ -253,7 +259,7 @@ def build_digest(project: Project, records: Sequence[Record]) -> DigestInfo:
253259
group_ids = list(groups)
254260
rules = Rule.objects.in_bulk(rule_ids)
255261

256-
if features.has("organizations:workflow-engine-trigger-actions", project.organization):
262+
if should_fire_workflow_actions(project.organization):
257263
for rule in rules.values():
258264
rule.data["actions"][0]["legacy_rule_id"] = rule.id
259265

src/sentry/features/temporary.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,8 @@ def register_temporary_features(manager: FeatureManager):
497497
manager.add("organizations:workflow-engine-process-metric-issue-workflows", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
498498
# Enable workflow engine for issue alerts
499499
manager.add("organizations:workflow-engine-process-workflows", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
500+
# Enable single processing through workflow engine for issue alerts
501+
manager.add("organizations:workflow-engine-single-process-workflows", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
500502
# Enable logging to debug workflow engine process workflows
501503
manager.add("organizations:workflow-engine-process-workflows-logs", OrganizationFeature, FeatureHandlerStrategy.FLAGPOLE, api_expose=False)
502504
# Enable firing actions for workflow engine issue alerts

src/sentry/incidents/action_handlers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ def generate_incident_trigger_email_context(
503503
user: User | RpcUser | None = None,
504504
notification_uuid: str | None = None,
505505
):
506+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
507+
506508
snuba_query = metric_issue_context.snuba_query
507509
is_active = trigger_status == TriggerStatus.ACTIVE
508510
is_threshold_type_above = alert_context.threshold_type == AlertRuleThresholdType.ABOVE
@@ -579,7 +581,7 @@ def generate_incident_trigger_email_context(
579581
),
580582
query=urlencode(alert_link_params),
581583
)
582-
elif features.has("organizations:workflow-engine-trigger-actions", organization):
584+
elif should_fire_workflow_actions(organization):
583585
# lookup the incident_id from the open_period_identifier
584586
try:
585587
incident_group_open_period = IncidentGroupOpenPeriod.objects.get(

src/sentry/integrations/discord/message_builder/issues.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from sentry.models.group import Group, GroupStatus
2323
from sentry.models.project import Project
2424
from sentry.models.rule import Rule
25+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
2526
from sentry.notifications.notifications.base import ProjectNotification
2627
from sentry.notifications.utils.rules import get_key_from_rule_data
2728

@@ -60,9 +61,7 @@ def build(self, notification_uuid: str | None = None) -> dict[str, object]:
6061
rule_environment_id = self.rules[0].environment_id
6162
if features.has("organizations:workflow-engine-ui-links", self.group.organization):
6263
rule_id = int(get_key_from_rule_data(self.rules[0], "workflow_id"))
63-
elif features.has(
64-
"organizations:workflow-engine-trigger-actions", self.group.organization
65-
):
64+
elif should_fire_workflow_actions(self.group.organization):
6665
rule_id = int(get_key_from_rule_data(self.rules[0], "legacy_rule_id"))
6766
else:
6867
rule_id = self.rules[0].id

src/sentry/integrations/messaging/message_builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sentry.models.project import Project
1515
from sentry.models.rule import Rule
1616
from sentry.models.team import Team
17+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
1718
from sentry.notifications.notifications.base import BaseNotification
1819
from sentry.notifications.notifications.rules import AlertRuleNotification
1920
from sentry.notifications.utils.links import create_link_to_workflow
@@ -109,7 +110,7 @@ def get_rule_environment_param_from_rule(
109110
rule_id: int, rule_environment_id: int | None, organization: Organization
110111
) -> dict[str, str]:
111112
params = {}
112-
if features.has("organizations:workflow-engine-trigger-actions", organization):
113+
if should_fire_workflow_actions(organization):
113114
if (
114115
rule_environment_id is not None
115116
and (environment_name := fetch_environment_name(rule_environment_id)) is not None
@@ -269,7 +270,7 @@ def build_attachment_replay_link(
269270
def build_rule_url(rule: Any, group: Group, project: Project) -> str:
270271
org_slug = group.organization.slug
271272
project_slug = project.slug
272-
if features.has("organizations:workflow-engine-trigger-actions", group.organization):
273+
if should_fire_workflow_actions(group.organization):
273274
rule_id = get_key_from_rule_data(rule, "legacy_rule_id")
274275
rule_url = f"/organizations/{org_slug}/alerts/rules/{project_slug}/{rule_id}/details/"
275276
else:

src/sentry/integrations/metric_alerts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ def incident_attachment_info(
194194
referrer: str = "metric_alert",
195195
notification_uuid: str | None = None,
196196
) -> AttachmentInfo:
197+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
198+
197199
status = get_status_text(metric_issue_context.new_status)
198200

199201
text = ""
@@ -220,7 +222,7 @@ def incident_attachment_info(
220222
if notification_uuid:
221223
title_link_params["notification_uuid"] = notification_uuid
222224

223-
if features.has("organizations:workflow-engine-trigger-actions", organization):
225+
if should_fire_workflow_actions(organization):
224226
try:
225227
alert_rule_id = AlertRuleDetector.objects.values_list("alert_rule_id", flat=True).get(
226228
detector_id=alert_context.action_identifier_id

src/sentry/integrations/opsgenie/client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sentry.integrations.services.integration.model import RpcIntegration
1212
from sentry.integrations.types import IntegrationProviderSlug
1313
from sentry.models.group import Group
14+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
1415
from sentry.notifications.utils.links import create_link_to_workflow
1516
from sentry.notifications.utils.rules import get_key_from_rule_data
1617
from sentry.shared_integrations.exceptions import ApiError
@@ -58,7 +59,7 @@ def _get_rule_urls(self, group, rules):
5859
rule_urls = []
5960
for rule in rules:
6061
rule_id = rule.id
61-
if features.has("organizations:workflow-engine-trigger-actions", organization):
62+
if should_fire_workflow_actions(organization):
6263
rule_id = get_key_from_rule_data(rule, "legacy_rule_id")
6364

6465
path = f"/organizations/{organization.slug}/alerts/rules/{group.project.slug}/{rule_id}/details/"

src/sentry/integrations/slack/actions/notification.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import sentry_sdk
1010
from slack_sdk.errors import SlackApiError
1111

12-
from sentry import features
1312
from sentry.api.serializers.rest_framework.rule import ACTION_UUID_KEY
1413
from sentry.constants import ISSUE_ALERTS_THREAD_DEFAULT
1514
from sentry.eventstore.models import GroupEvent
@@ -39,6 +38,7 @@
3938
from sentry.models.organization import Organization
4039
from sentry.models.rule import Rule
4140
from sentry.notifications.additional_attachment_manager import get_additional_attachment
41+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
4242
from sentry.notifications.utils.open_period import open_period_start_for_group
4343
from sentry.rules.actions import IntegrationEventAction
4444
from sentry.rules.base import CallbackFuture
@@ -479,7 +479,7 @@ def send_notification_noa(event: GroupEvent, futures: Sequence[RuleFuture]) -> N
479479
},
480480
skip_internal=False,
481481
)
482-
if features.has("organizations:workflow-engine-trigger-actions", self.project.organization):
482+
if should_fire_workflow_actions(self.project.organization):
483483
yield self.future(send_notification_noa, key=key)
484484
else:
485485
yield self.future(send_notification, key=key)

src/sentry/integrations/slack/message_builder/issues.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from sentry.models.repository import Repository
5454
from sentry.models.rule import Rule
5555
from sentry.models.team import Team
56+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
5657
from sentry.notifications.notifications.base import ProjectNotification
5758
from sentry.notifications.utils.actions import BlockKitMessageAction, MessageAction
5859
from sentry.notifications.utils.participants import (
@@ -615,9 +616,7 @@ def build(self, notification_uuid: str | None = None) -> SlackBlock:
615616
if self.rules:
616617
if features.has("organizations:workflow-engine-ui-links", self.group.organization):
617618
rule_id = int(get_key_from_rule_data(self.rules[0], "workflow_id"))
618-
elif features.has(
619-
"organizations:workflow-engine-trigger-actions", self.group.organization
620-
):
619+
elif should_fire_workflow_actions(self.group.organization):
621620
rule_id = int(get_key_from_rule_data(self.rules[0], "legacy_rule_id"))
622621
else:
623622
rule_id = self.rules[0].id

src/sentry/integrations/slack/service.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import sentry_sdk
1010
from slack_sdk.errors import SlackApiError
1111

12-
from sentry import features
1312
from sentry.constants import ISSUE_ALERTS_THREAD_DEFAULT
1413
from sentry.incidents.grouptype import MetricIssue
1514
from sentry.integrations.messaging.metrics import (
@@ -45,6 +44,7 @@
4544
from sentry.models.options.organization_option import OrganizationOption
4645
from sentry.models.rule import Rule
4746
from sentry.notifications.additional_attachment_manager import get_additional_attachment
47+
from sentry.notifications.notification_action.utils import should_fire_workflow_actions
4848
from sentry.notifications.notifications.activity.archive import ArchiveActivityNotification
4949
from sentry.notifications.notifications.activity.assigned import AssignedActivityNotification
5050
from sentry.notifications.notifications.activity.base import GroupActivityNotification
@@ -248,13 +248,11 @@ def _notify_all_threads_for_activity(
248248
parent_notifications: Generator[
249249
NotificationActionNotificationMessage | IssueAlertNotificationMessage
250250
]
251+
will_fire_workflow_actions = should_fire_workflow_actions(group.organization)
251252
if group.issue_category == GroupCategory.UPTIME:
252253
use_open_period_start = True
253254
open_period_start = open_period_start_for_group(group)
254-
if features.has(
255-
"organizations:workflow-engine-trigger-actions",
256-
group.organization,
257-
):
255+
if will_fire_workflow_actions:
258256
parent_notifications = self._notification_action_repository.get_all_parent_notification_messages_by_filters(
259257
group_ids=[group.id],
260258
open_period_start=open_period_start,
@@ -266,10 +264,7 @@ def _notify_all_threads_for_activity(
266264
open_period_start=open_period_start,
267265
)
268266
else:
269-
if features.has(
270-
"organizations:workflow-engine-trigger-actions",
271-
group.organization,
272-
):
267+
if will_fire_workflow_actions:
273268
parent_notifications = self._notification_action_repository.get_all_parent_notification_messages_by_filters(
274269
group_ids=[group.id],
275270
)

0 commit comments

Comments
 (0)