Skip to content

Commit

Permalink
fix(alerts): Only grab anomalies if the detection type matches (#76738)
Browse files Browse the repository at this point in the history
We were always getting anomalies if the flag was on, but we only need to
check this if the alert itself is using the dynamic detection type.
  • Loading branch information
ceorourke committed Aug 29, 2024
1 parent ec36348 commit d9df3dc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/sentry/incidents/subscription_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ def process_update(self, subscription_update: QuerySubscriptionUpdate) -> None:
"organizations:fake-anomaly-detection", self.subscription.project.organization
)

if self.has_anomaly_detection:
potential_anomalies = None
if (
self.has_anomaly_detection
and self.alert_rule.detection_type == AlertRuleDetectionType.DYNAMIC
):
potential_anomalies = self.get_anomaly_data_from_seer(aggregation_value)
if potential_anomalies is None:
return []
Expand All @@ -545,8 +549,7 @@ def process_update(self, subscription_update: QuerySubscriptionUpdate) -> None:
with transaction.atomic(router.db_for_write(AlertRule)):
# Triggers is the threshold - NOT an instance of a trigger
for trigger in self.triggers:
detection_type = trigger.alert_rule.detection_type
if self.has_anomaly_detection and detection_type == AlertRuleDetectionType.DYNAMIC:
if potential_anomalies:
# NOTE: There should only be one anomaly in the list
for potential_anomaly in potential_anomalies:
# check to see if we have enough data for the dynamic alert rule now
Expand All @@ -565,7 +568,7 @@ def process_update(self, subscription_update: QuerySubscriptionUpdate) -> None:
) and not self.check_trigger_matches_status(trigger, TriggerStatus.ACTIVE):
metrics.incr(
"incidents.alert_rules.threshold.alert",
tags={"detection_type": detection_type},
tags={"detection_type": self.alert_rule.detection_type},
)
incident_trigger = self.trigger_alert_threshold(
trigger, aggregation_value
Expand All @@ -584,7 +587,7 @@ def process_update(self, subscription_update: QuerySubscriptionUpdate) -> None:
):
metrics.incr(
"incidents.alert_rules.threshold.resolve",
tags={"detection_type": detection_type},
tags={"detection_type": self.alert_rule.detection_type},
)
incident_trigger = self.trigger_resolve_threshold(
trigger, aggregation_value
Expand All @@ -602,7 +605,7 @@ def process_update(self, subscription_update: QuerySubscriptionUpdate) -> None:
# And the trigger is not yet active
metrics.incr(
"incidents.alert_rules.threshold.alert",
tags={"detection_type": detection_type},
tags={"detection_type": self.alert_rule.detection_type},
)
# triggering a threshold will create an incident and set the status to active
incident_trigger = self.trigger_alert_threshold(trigger, aggregation_value)
Expand All @@ -620,7 +623,7 @@ def process_update(self, subscription_update: QuerySubscriptionUpdate) -> None:
):
metrics.incr(
"incidents.alert_rules.threshold.resolve",
tags={"detection_type": detection_type},
tags={"detection_type": self.alert_rule.detection_type},
)
incident_trigger = self.trigger_resolve_threshold(
trigger, aggregation_value
Expand Down

0 comments on commit d9df3dc

Please sign in to comment.