Skip to content

Commit

Permalink
ref(workflow_engine): Remove DetectorType (#82111)
Browse files Browse the repository at this point in the history
## Description
Removes the `DetectorType` from the `workflow_engine.type` and adds
comments to clarify how this type is defined and used.
  • Loading branch information
saponifi3d authored and evanh committed Dec 17, 2024
1 parent bc808a6 commit f6caae2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/sentry/workflow_engine/models/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
7 changes: 1 addition & 6 deletions src/sentry/workflow_engine/types.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"

0 comments on commit f6caae2

Please sign in to comment.