Skip to content

Commit 20335e1

Browse files
authored
nit(aci): cast detection type config to AlertRuleDetectionType in NOA translation layer (#93835)
1 parent 99c7881 commit 20335e1

9 files changed

+21
-17
lines changed

src/sentry/incidents/typings/metric_detector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def from_workflow_engine_models(
120120
name=detector.name,
121121
action_identifier_id=detector.id,
122122
threshold_type=threshold_type,
123-
detection_type=detector.config.get("detection_type"),
123+
detection_type=AlertRuleDetectionType(detector.config.get("detection_type")),
124124
comparison_delta=detector.config.get("comparison_delta"),
125125
sensitivity=sensitivity,
126126
resolve_threshold=resolve_threshold,

tests/sentry/notifications/notification_action/metric_alert_registry/test_discord_metric_alert_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import uuid
22
from unittest import mock
33

4-
from sentry.incidents.models.alert_rule import AlertRuleThresholdType
4+
from sentry.incidents.models.alert_rule import AlertRuleDetectionType, AlertRuleThresholdType
55
from sentry.incidents.models.incident import IncidentStatus, TriggerStatus
66
from sentry.incidents.typings.metric_detector import (
77
AlertContext,
@@ -106,7 +106,7 @@ def test_invoke_legacy_registry(self, mock_send_alert):
106106
name=self.detector.name,
107107
action_identifier_id=self.detector.id,
108108
threshold_type=AlertRuleThresholdType.ABOVE,
109-
detection_type=None,
109+
detection_type=AlertRuleDetectionType.STATIC,
110110
comparison_delta=None,
111111
alert_threshold=self.evidence_data.conditions[0]["comparison"],
112112
)

tests/sentry/notifications/notification_action/metric_alert_registry/test_email_metric_alert_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import uuid
22
from unittest import mock
33

4-
from sentry.incidents.models.alert_rule import AlertRuleThresholdType
4+
from sentry.incidents.models.alert_rule import AlertRuleDetectionType, AlertRuleThresholdType
55
from sentry.incidents.models.incident import IncidentStatus, TriggerStatus
66
from sentry.incidents.typings.metric_detector import (
77
AlertContext,
@@ -110,7 +110,7 @@ def test_invoke_legacy_registry(self, mock_send_alert):
110110
name=self.detector.name,
111111
action_identifier_id=self.detector.id,
112112
threshold_type=AlertRuleThresholdType.ABOVE,
113-
detection_type=None,
113+
detection_type=AlertRuleDetectionType.STATIC,
114114
comparison_delta=None,
115115
alert_threshold=self.evidence_data.conditions[0]["comparison"],
116116
)

tests/sentry/notifications/notification_action/metric_alert_registry/test_msteams_metric_alert_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import uuid
22
from unittest import mock
33

4-
from sentry.incidents.models.alert_rule import AlertRuleThresholdType
4+
from sentry.incidents.models.alert_rule import AlertRuleDetectionType, AlertRuleThresholdType
55
from sentry.incidents.models.incident import IncidentStatus, TriggerStatus
66
from sentry.incidents.typings.metric_detector import (
77
AlertContext,
@@ -107,7 +107,7 @@ def test_invoke_legacy_registry(self, mock_send_alert):
107107
name=self.detector.name,
108108
action_identifier_id=self.detector.id,
109109
threshold_type=AlertRuleThresholdType.ABOVE,
110-
detection_type=None,
110+
detection_type=AlertRuleDetectionType.STATIC,
111111
comparison_delta=None,
112112
alert_threshold=self.evidence_data.conditions[0]["comparison"],
113113
)

tests/sentry/notifications/notification_action/metric_alert_registry/test_opsgenie_metric_alert_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import uuid
22
from unittest import mock
33

4-
from sentry.incidents.models.alert_rule import AlertRuleThresholdType
4+
from sentry.incidents.models.alert_rule import AlertRuleDetectionType, AlertRuleThresholdType
55
from sentry.incidents.models.incident import IncidentStatus, TriggerStatus
66
from sentry.incidents.typings.metric_detector import (
77
AlertContext,
@@ -103,7 +103,7 @@ def test_invoke_legacy_registry(self, mock_send_alert):
103103
name=self.detector.name,
104104
action_identifier_id=self.detector.id,
105105
threshold_type=AlertRuleThresholdType.ABOVE,
106-
detection_type=None,
106+
detection_type=AlertRuleDetectionType.STATIC,
107107
comparison_delta=None,
108108
alert_threshold=self.evidence_data.conditions[0]["comparison"],
109109
)

tests/sentry/notifications/notification_action/metric_alert_registry/test_pagerduty_metric_alert_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import uuid
22
from unittest import mock
33

4-
from sentry.incidents.models.alert_rule import AlertRuleThresholdType
4+
from sentry.incidents.models.alert_rule import AlertRuleDetectionType, AlertRuleThresholdType
55
from sentry.incidents.models.incident import IncidentStatus, TriggerStatus
66
from sentry.incidents.typings.metric_detector import (
77
AlertContext,
@@ -101,7 +101,7 @@ def test_invoke_legacy_registry(self, mock_send_alert):
101101
name=self.detector.name,
102102
action_identifier_id=self.detector.id,
103103
threshold_type=AlertRuleThresholdType.ABOVE,
104-
detection_type=None,
104+
detection_type=AlertRuleDetectionType.STATIC,
105105
comparison_delta=None,
106106
alert_threshold=self.evidence_data.conditions[0]["comparison"],
107107
)

tests/sentry/notifications/notification_action/metric_alert_registry/test_sentry_app_metric_alert_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import uuid
22
from unittest import mock
33

4-
from sentry.incidents.models.alert_rule import AlertRuleThresholdType
4+
from sentry.incidents.models.alert_rule import AlertRuleDetectionType, AlertRuleThresholdType
55
from sentry.incidents.models.incident import IncidentStatus, TriggerStatus
66
from sentry.incidents.typings.metric_detector import (
77
AlertContext,
@@ -114,7 +114,7 @@ def test_invoke_legacy_registry(self, mock_send_alert):
114114
name=self.detector.name,
115115
action_identifier_id=self.detector.id,
116116
threshold_type=AlertRuleThresholdType.ABOVE,
117-
detection_type=None,
117+
detection_type=AlertRuleDetectionType.STATIC,
118118
comparison_delta=None,
119119
alert_threshold=self.evidence_data.conditions[0]["comparison"],
120120
)

tests/sentry/notifications/notification_action/metric_alert_registry/test_slack_metric_alert_handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import uuid
22
from unittest import mock
33

4-
from sentry.incidents.models.alert_rule import AlertRuleThresholdType
4+
from sentry.incidents.models.alert_rule import AlertRuleDetectionType, AlertRuleThresholdType
55
from sentry.incidents.models.incident import IncidentStatus, TriggerStatus
66
from sentry.incidents.typings.metric_detector import (
77
AlertContext,
@@ -109,7 +109,7 @@ def test_invoke_legacy_registry(self, mock_send_alert):
109109
name=self.detector.name,
110110
action_identifier_id=self.detector.id,
111111
threshold_type=AlertRuleThresholdType.ABOVE,
112-
detection_type=None,
112+
detection_type=AlertRuleDetectionType.STATIC,
113113
comparison_delta=None,
114114
alert_threshold=self.evidence_data.conditions[0]["comparison"],
115115
)

tests/sentry/notifications/notification_action/test_metric_alert_registry_handlers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ def send_alert(
6262
class MetricAlertHandlerBase(BaseWorkflowTest):
6363
def create_models(self):
6464
self.project = self.create_project()
65-
self.detector = self.create_detector(project=self.project)
65+
self.detector = self.create_detector(
66+
project=self.project,
67+
config={"detection_type": "static", "threshold_period": 1},
68+
type="metric_issue",
69+
)
6670

6771
with self.tasks():
6872
self.snuba_query = create_snuba_query(
@@ -406,7 +410,7 @@ def test_invoke_legacy_registry(self, mock_send_alert):
406410
name=self.detector.name,
407411
action_identifier_id=self.detector.id,
408412
threshold_type=AlertRuleThresholdType.ABOVE,
409-
detection_type=None,
413+
detection_type=AlertRuleDetectionType.STATIC,
410414
comparison_delta=None,
411415
sensitivity=None,
412416
resolve_threshold=None,

0 commit comments

Comments
 (0)