From bf552ec9e4881074eb0f79a41962b637c9dfc2f5 Mon Sep 17 00:00:00 2001 From: Josh Callender <1569818+saponifi3d@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:48:58 -0800 Subject: [PATCH] Tidy up the DetectorType code and add some comments to make it a bit clearer what's linking here and why it's not more explicit --- src/sentry/workflow_engine/models/detector.py | 9 +++++++-- src/sentry/workflow_engine/types.py | 7 +------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sentry/workflow_engine/models/detector.py b/src/sentry/workflow_engine/models/detector.py index 6448ae17b1828e..0cc2145a06a1c5 100644 --- a/src/sentry/workflow_engine/models/detector.py +++ b/src/sentry/workflow_engine/models/detector.py @@ -55,8 +55,7 @@ class Detector(DefaultFieldsModel, OwnerModel, JSONConfigBase): on_delete=models.SET_NULL, ) - # The type of detector that is being used, this is used to determine the class - # to load for the detector + # maps to registry (sentry.issues.grouptype.registry) entries for GroupType.slug in sentry.issues.grouptype.GroupType type = models.CharField(max_length=200) # The user that created the detector @@ -106,8 +105,14 @@ def get_audit_log_data(self) -> dict[str, Any]: @receiver(pre_save, sender=Detector) def enforce_config_schema(sender, instance: Detector, **kwargs): + """ + Ensures the detector type is valid in the grouptype registry. + This needs to be a signal because the grouptype registry's entries are not available at import time. + """ group_type = instance.group_type + if not group_type: raise ValueError(f"No group type found with type {instance.type}") + config_schema = group_type.detector_config_schema instance.validate_config(config_schema) diff --git a/src/sentry/workflow_engine/types.py b/src/sentry/workflow_engine/types.py index 51ec57eb0da29a..24b435e6a34619 100644 --- a/src/sentry/workflow_engine/types.py +++ b/src/sentry/workflow_engine/types.py @@ -1,6 +1,6 @@ from __future__ import annotations -from enum import IntEnum, StrEnum +from enum import IntEnum from typing import TYPE_CHECKING, Any, Generic, TypeVar from sentry.types.group import PriorityLevel @@ -44,8 +44,3 @@ class DataConditionHandler(Generic[T]): @staticmethod def evaluate_value(value: T, comparison: Any, condition: str) -> DataConditionResult: raise NotImplementedError - - -class DetectorType(StrEnum): - ERROR = "ErrorDetector" - METRIC_ALERT_FIRE = "metric_alert_fire"