Skip to content

Commit d45ce1a

Browse files
authored
feat(aci): default to the error detector for grouptypes without detector (#97810)
1 parent 719e486 commit d45ce1a

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src/sentry/workflow_engine/processors/detector.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424

2525
def get_detector_by_event(event_data: WorkflowEventData) -> Detector:
26+
from sentry.grouping.grouptype import ErrorGroupType
27+
2628
evt = event_data.event
2729

2830
if not isinstance(evt, GroupEvent):
@@ -33,11 +35,9 @@ def get_detector_by_event(event_data: WorkflowEventData) -> Detector:
3335
issue_occurrence = evt.occurrence
3436

3537
try:
36-
if issue_occurrence is None:
37-
# TODO - @saponifi3d - check to see if there's a way to confirm these are for the error detector
38-
detector = Detector.objects.get(
39-
project_id=evt.project_id, type=evt.group.issue_type.slug
40-
)
38+
if issue_occurrence is None or evt.group.issue_type.detector_settings is None:
39+
# if there are no detector settings, default to the error detector
40+
detector = Detector.objects.get(project_id=evt.project_id, type=ErrorGroupType.slug)
4141
else:
4242
detector = Detector.objects.get(
4343
id=issue_occurrence.evidence_data.get("detector_id", None)

tests/sentry/workflow_engine/processors/test_detector.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from django.utils import timezone
99

1010
from sentry.incidents.grouptype import MetricIssue
11+
from sentry.issues.grouptype import PerformanceNPlusOneAPICallsGroupType
1112
from sentry.issues.issue_occurrence import IssueOccurrence
1213
from sentry.issues.producer import PayloadType
1314
from sentry.issues.status_change_message import StatusChangeMessage
@@ -920,6 +921,33 @@ def test_no_detector_id(self) -> None:
920921
with pytest.raises(Detector.DoesNotExist):
921922
get_detector_by_event(event_data)
922923

924+
def test_defaults_to_error_detector(self) -> None:
925+
occurrence = IssueOccurrence(
926+
id=uuid.uuid4().hex,
927+
project_id=self.project.id,
928+
event_id="asdf",
929+
fingerprint=["asdf"],
930+
issue_title="title",
931+
subtitle="subtitle",
932+
resource_id=None,
933+
evidence_data={},
934+
evidence_display=[],
935+
type=PerformanceNPlusOneAPICallsGroupType,
936+
detection_time=timezone.now(),
937+
level="error",
938+
culprit="",
939+
)
940+
941+
group_event = GroupEvent.from_event(self.event, self.group)
942+
self.group.update(type=PerformanceNPlusOneAPICallsGroupType.type_id)
943+
group_event.occurrence = occurrence
944+
945+
event_data = WorkflowEventData(event=group_event, group=self.group)
946+
947+
result = get_detector_by_event(event_data)
948+
949+
assert result == self.error_detector
950+
923951

924952
class TestGetDetectorsByGroupEventsBulk(TestCase):
925953
def setUp(self) -> None:

tests/sentry/workflow_engine/processors/test_workflow.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ def test_workflow_fire_history_with_action_deduping(
305305
assert WorkflowFireHistory.objects.count() == 3
306306
assert mock_trigger_action.call_count == 3
307307

308+
def test_defaults_to_error_workflows(self) -> None:
309+
issue_occurrence = self.build_occurrence()
310+
self.group_event.occurrence = issue_occurrence
311+
self.group.update(type=issue_occurrence.type.type_id)
312+
313+
triggered_workflows = process_workflows(self.event_data)
314+
assert triggered_workflows == {self.error_workflow}
315+
308316

309317
@mock_redis_buffer()
310318
class TestEvaluateWorkflowTriggers(BaseWorkflowTest):

0 commit comments

Comments
 (0)