Skip to content

Commit 895d4a6

Browse files
committed
fix(incidents): Fix 60x resolution inflation when switching to DYNAMIC detection without explicit time_window
1 parent 40cdd23 commit 895d4a6

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/sentry/incidents/logic.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -918,9 +918,11 @@ def update_alert_rule(
918918
updated_fields["seasonality"] = None
919919
elif detection_type == AlertRuleDetectionType.DYNAMIC:
920920
# NOTE: we set seasonality for EA
921-
updated_query_fields["resolution"] = timedelta(
922-
minutes=time_window if time_window is not None else snuba_query.time_window
923-
)
921+
if time_window is not None:
922+
updated_query_fields["resolution"] = timedelta(minutes=time_window)
923+
else:
924+
# snuba_query.time_window is already in seconds
925+
updated_query_fields["resolution"] = timedelta(seconds=snuba_query.time_window)
924926
updated_fields["seasonality"] = AlertRuleSeasonality.AUTO
925927
updated_fields["comparison_delta"] = None
926928
if (

tests/sentry/incidents/test_logic.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,6 +1541,27 @@ def test_update_alert_rule_static_to_dynamic_enough_data(
15411541
assert mock_seer_request.call_count == 1
15421542
assert alert_rule.status == AlertRuleStatus.PENDING.value
15431543

1544+
@with_feature("organizations:anomaly-detection-alerts")
1545+
@patch("sentry.seer.anomaly_detection.store_data.handle_send_historical_data_to_seer_legacy")
1546+
def test_update_static_to_dynamic_without_time_window_preserves_resolution(
1547+
self, mock_handle_seer: MagicMock
1548+
) -> None:
1549+
time_window_minutes = 30
1550+
alert_rule = self.create_alert_rule(
1551+
time_window=time_window_minutes, detection_type=AlertRuleDetectionType.STATIC
1552+
)
1553+
expected_resolution_seconds = time_window_minutes * 60
1554+
1555+
update_alert_rule(
1556+
alert_rule,
1557+
sensitivity=AlertRuleSensitivity.HIGH,
1558+
seasonality=AlertRuleSeasonality.AUTO,
1559+
detection_type=AlertRuleDetectionType.DYNAMIC,
1560+
)
1561+
1562+
alert_rule.snuba_query.refresh_from_db()
1563+
assert alert_rule.snuba_query.resolution == expected_resolution_seconds
1564+
15441565
@with_feature("organizations:anomaly-detection-alerts")
15451566
@patch(
15461567
"sentry.seer.anomaly_detection.store_data.seer_anomaly_detection_connection_pool.urlopen"

0 commit comments

Comments
 (0)