|
1 | 1 | import copy |
2 | 2 | import math |
3 | | -from contextlib import contextmanager |
4 | 3 | from datetime import timedelta |
5 | 4 | from functools import cached_property |
6 | 5 | from unittest.mock import MagicMock, call, patch |
|
12 | 11 | from urllib3.response import HTTPResponse |
13 | 12 |
|
14 | 13 | from sentry.constants import ObjectStatus |
15 | | -from sentry.incidents.subscription_processor import SubscriptionProcessor, has_downgraded |
| 14 | +from sentry.incidents.subscription_processor import SubscriptionProcessor |
16 | 15 | from sentry.incidents.utils.types import QuerySubscriptionUpdate |
17 | | -from sentry.models.organization import Organization |
18 | 16 | from sentry.seer.anomaly_detection.types import ( |
19 | 17 | AnomalyDetectionSeasonality, |
20 | 18 | AnomalyDetectionSensitivity, |
@@ -65,17 +63,18 @@ def test_missing_project(self, mock_metrics: MagicMock) -> None: |
65 | 63 | self.sub.project.delete() |
66 | 64 | assert self.send_update(self.critical_threshold + 1) is False |
67 | 65 |
|
68 | | - @patch("sentry.incidents.subscription_processor.has_downgraded", return_value=True) |
69 | | - def test_process_update_returns_false_when_downgraded( |
70 | | - self, mock_has_downgraded: MagicMock |
71 | | - ) -> None: |
| 66 | + @patch( |
| 67 | + "sentry.incidents.subscription_processor.is_metric_subscription_allowed", |
| 68 | + return_value=False, |
| 69 | + ) |
| 70 | + def test_process_update_returns_false_when_downgraded(self, mock_is_enabled: MagicMock) -> None: |
72 | 71 | message = self.build_subscription_update( |
73 | 72 | self.sub, value=self.critical_threshold + 1, time_delta=timedelta() |
74 | 73 | ) |
75 | 74 |
|
76 | 75 | with self.capture_on_commit_callbacks(execute=True): |
77 | 76 | assert SubscriptionProcessor.process(self.sub, message) is False |
78 | | - mock_has_downgraded.assert_called_once() |
| 77 | + mock_is_enabled.assert_called_once() |
79 | 78 |
|
80 | 79 | @patch("sentry.incidents.subscription_processor.metrics") |
81 | 80 | def test_invalid_aggregation_value(self, mock_metrics: MagicMock) -> None: |
@@ -1012,92 +1011,3 @@ def test_ensure_case_when_no_metrics_index_not_found_is_handled_gracefully( |
1012 | 1011 | call("incidents.alert_rules.skipping_update_invalid_aggregation_value"), |
1013 | 1012 | ] |
1014 | 1013 | ) |
1015 | | - |
1016 | | - |
1017 | | -@patch("sentry.incidents.subscription_processor.metrics") |
1018 | | -class TestHasDowngraded: |
1019 | | - org = MagicMock(spec=Organization) |
1020 | | - |
1021 | | - @contextmanager |
1022 | | - def fake_features(self, enabled: set[str]): |
1023 | | - with patch("sentry.incidents.subscription_processor.features") as mock_features: |
1024 | | - mock_features.has.side_effect = lambda name, *a, **kw: name in enabled |
1025 | | - yield |
1026 | | - |
1027 | | - def test_events_without_incidents_feature(self, mock_metrics: MagicMock) -> None: |
1028 | | - with self.fake_features(set()): |
1029 | | - assert has_downgraded(Dataset.Events.value, self.org) is True |
1030 | | - mock_metrics.incr.assert_called_with( |
1031 | | - "incidents.alert_rules.ignore_update_missing_incidents" |
1032 | | - ) |
1033 | | - |
1034 | | - def test_events_with_incidents_feature(self, mock_metrics: MagicMock) -> None: |
1035 | | - with self.fake_features({"organizations:incidents"}): |
1036 | | - assert has_downgraded(Dataset.Events.value, self.org) is False |
1037 | | - |
1038 | | - def test_transactions_without_any_features(self, mock_metrics: MagicMock) -> None: |
1039 | | - with self.fake_features(set()): |
1040 | | - assert has_downgraded(Dataset.Transactions.value, self.org) is True |
1041 | | - mock_metrics.incr.assert_called_with( |
1042 | | - "incidents.alert_rules.ignore_update_missing_incidents_performance" |
1043 | | - ) |
1044 | | - |
1045 | | - def test_transactions_with_only_performance_view(self, mock_metrics: MagicMock) -> None: |
1046 | | - with self.fake_features({"organizations:performance-view"}): |
1047 | | - assert has_downgraded(Dataset.Transactions.value, self.org) is True |
1048 | | - mock_metrics.incr.assert_called_with( |
1049 | | - "incidents.alert_rules.ignore_update_missing_incidents_performance" |
1050 | | - ) |
1051 | | - |
1052 | | - def test_transactions_with_both_features(self, mock_metrics: MagicMock) -> None: |
1053 | | - with self.fake_features({"organizations:incidents", "organizations:performance-view"}): |
1054 | | - assert has_downgraded(Dataset.Transactions.value, self.org) is False |
1055 | | - |
1056 | | - def test_eap_without_features(self, mock_metrics: MagicMock) -> None: |
1057 | | - with self.fake_features(set()): |
1058 | | - assert has_downgraded(Dataset.EventsAnalyticsPlatform.value, self.org) is True |
1059 | | - mock_metrics.incr.assert_called_with( |
1060 | | - "incidents.alert_rules.ignore_update_missing_incidents_eap" |
1061 | | - ) |
1062 | | - |
1063 | | - def test_eap_with_only_explore_view(self, mock_metrics: MagicMock) -> None: |
1064 | | - with self.fake_features({"organizations:visibility-explore-view"}): |
1065 | | - assert has_downgraded(Dataset.EventsAnalyticsPlatform.value, self.org) is True |
1066 | | - mock_metrics.incr.assert_called_with( |
1067 | | - "incidents.alert_rules.ignore_update_missing_incidents_eap" |
1068 | | - ) |
1069 | | - |
1070 | | - def test_eap_with_both_features(self, mock_metrics: MagicMock) -> None: |
1071 | | - with self.fake_features( |
1072 | | - {"organizations:incidents", "organizations:visibility-explore-view"} |
1073 | | - ): |
1074 | | - assert has_downgraded(Dataset.EventsAnalyticsPlatform.value, self.org) is False |
1075 | | - |
1076 | | - def test_performance_metrics_without_on_demand_feature(self, mock_metrics: MagicMock) -> None: |
1077 | | - with self.fake_features(set()): |
1078 | | - assert has_downgraded(Dataset.PerformanceMetrics.value, self.org) is True |
1079 | | - mock_metrics.incr.assert_called_with( |
1080 | | - "incidents.alert_rules.ignore_update_missing_on_demand" |
1081 | | - ) |
1082 | | - |
1083 | | - def test_performance_metrics_with_on_demand_feature(self, mock_metrics: MagicMock) -> None: |
1084 | | - with self.fake_features({"organizations:on-demand-metrics-extraction"}): |
1085 | | - assert has_downgraded(Dataset.PerformanceMetrics.value, self.org) is False |
1086 | | - |
1087 | | - def test_unknown_dataset_not_downgraded(self, mock_metrics: MagicMock) -> None: |
1088 | | - with self.fake_features(set()): |
1089 | | - assert has_downgraded("unknown_dataset", self.org) is False |
1090 | | - mock_metrics.incr.assert_called_with( |
1091 | | - "incidents.alert_rules.no_incidents_not_downgraded", |
1092 | | - sample_rate=1.0, |
1093 | | - tags={"dataset": "unknown_dataset"}, |
1094 | | - ) |
1095 | | - |
1096 | | - def test_no_incidents_not_downgraded_emits_metric(self, mock_metrics: MagicMock) -> None: |
1097 | | - with self.fake_features({"organizations:on-demand-metrics-extraction"}): |
1098 | | - assert has_downgraded(Dataset.PerformanceMetrics.value, self.org) is False |
1099 | | - mock_metrics.incr.assert_called_with( |
1100 | | - "incidents.alert_rules.no_incidents_not_downgraded", |
1101 | | - sample_rate=1.0, |
1102 | | - tags={"dataset": Dataset.PerformanceMetrics.value}, |
1103 | | - ) |
0 commit comments