Skip to content

Commit ecc2964

Browse files
mifu67priscilawebdev
authored andcommitted
fix(aci milestone 3): don't attempt to create IGOP if no corresponding alert rule (#102017)
If a detector was singly written via the workflow engine, we do not need to create incidents for it. Early quit from IGOP creation logic.
1 parent eda2782 commit ecc2964

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/sentry/workflow_engine/models/incident_groupopenperiod.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ def create_from_occurrence(cls, occurrence, group, open_period):
6262
# Extract alert_id from evidence_data using the detector_id
6363
detector_id = occurrence.evidence_data.get("detector_id")
6464
if detector_id:
65-
alert_id = AlertRuleDetector.objects.get(detector_id=detector_id).alert_rule_id
65+
try:
66+
alert_id = AlertRuleDetector.objects.get(detector_id=detector_id).alert_rule_id
67+
except AlertRuleDetector.DoesNotExist:
68+
# detector does not have an analog in the old system, so we do not need to create an IGOP relationship
69+
return None
6670
else:
6771
raise Exception("No detector_id found in evidence_data for metric issue")
6872

@@ -244,8 +248,11 @@ def update_incident_activity_based_on_group_activity(
244248
# the priority change came before relationship creation. This isn't a problem—we create the
245249
# relationship with the new priority in create_from_occurrence() anyway.
246250

247-
# we could also hit this case if there are outstanding open incidents when switching to single
251+
# We could also hit this case if there are outstanding open incidents when switching to single
248252
# processing. Again, create_from_occurrence() will handle any status changes we need.
253+
254+
# Finally, this can also happen if the incident was not created because a detector was single
255+
# written in workflow engine. Just return in this case.
249256
logger.info(
250257
"No IncidentGroupOpenPeriod relationship found when updating IncidentActivity table",
251258
extra={
@@ -294,7 +301,8 @@ def update_incident_based_on_open_period_status_change(
294301
try:
295302
alert_rule_id = AlertRuleDetector.objects.get(detector_id=detector_id).alert_rule_id
296303
except AlertRuleDetector.DoesNotExist:
297-
logger.exception(
304+
# Detector was not dual written.
305+
logger.info(
298306
"No AlertRuleDetector found for detector ID", extra={"detector_id": detector_id}
299307
)
300308
return
@@ -307,7 +315,7 @@ def update_incident_based_on_open_period_status_change(
307315
incident = open_incident
308316
IncidentGroupOpenPeriod.create_relationship(incident=incident, open_period=open_period)
309317
else:
310-
logger.exception(
318+
logger.info(
311319
"No IncidentGroupOpenPeriod relationship and no outstanding incident",
312320
extra={
313321
"open_period_id": open_period.id,

0 commit comments

Comments
 (0)