Skip to content

feat(workflow_engine): Add status columns to Detector and Workflow's #90550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/sentry/workflow_engine/models/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from sentry.issues import grouptype
from sentry.issues.grouptype import GroupType
from sentry.models.owner_base import OwnerModel
from sentry.workflow_engine.types import DeletionStatus

from .json_config import JSONConfigBase

Expand All @@ -30,6 +31,9 @@
class Detector(DefaultFieldsModel, OwnerModel, JSONConfigBase):
__relocation_scope__ = RelocationScope.Organization

class Meta(OwnerModel.Meta):
constraints = OwnerModel.Meta.constraints

project = FlexibleForeignKey("sentry.Project", on_delete=models.CASCADE)
name = models.CharField(max_length=200)

Expand All @@ -41,6 +45,9 @@ class Detector(DefaultFieldsModel, OwnerModel, JSONConfigBase):
# If the detector is not enabled, it will not be evaluated. This is how we "snooze" a detector
enabled = models.BooleanField(db_default=True)

# The detector's status - used for tracking deletion state
status = models.SmallIntegerField(default=DeletionStatus.ACTIVE)

# Optionally set a description of the detector, this will be used in notifications
description = models.TextField(null=True)

Expand All @@ -59,9 +66,6 @@ class Detector(DefaultFieldsModel, OwnerModel, JSONConfigBase):
# The user that created the detector
created_by_id = HybridCloudForeignKey(settings.AUTH_USER_MODEL, null=True, on_delete="SET_NULL")

class Meta(OwnerModel.Meta):
constraints = OwnerModel.Meta.constraints

error_detector_project_options = {
"fingerprinting_rules": "sentry:fingerprinting_rules",
"resolve_age": "sentry:resolve_age",
Expand Down
5 changes: 4 additions & 1 deletion src/sentry/workflow_engine/models/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sentry.db.models.fields.hybrid_cloud_foreign_key import HybridCloudForeignKey
from sentry.models.owner_base import OwnerModel
from sentry.workflow_engine.models.data_condition import DataCondition, is_slow_condition
from sentry.workflow_engine.types import WorkflowEventData
from sentry.workflow_engine.types import DeletionStatus, WorkflowEventData

from .json_config import JSONConfigBase

Expand All @@ -30,6 +30,9 @@ class Workflow(DefaultFieldsModel, OwnerModel, JSONConfigBase):
# If the workflow is not enabled, it will not be evaluated / invoke actions. This is how we "snooze" a workflow
enabled = models.BooleanField(db_default=True)

# The workflow's status - used for tracking deletion state
status = models.SmallIntegerField(default=DeletionStatus.ACTIVE)

# Required as the 'when' condition for the workflow, this evalutes states emitted from the detectors
when_condition_group = FlexibleForeignKey(
"workflow_engine.DataConditionGroup", null=True, blank=True
Expand Down
6 changes: 6 additions & 0 deletions src/sentry/workflow_engine/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ class DetectorSettings:
handler: type[DetectorHandler] | None = None
validator: type[BaseDetectorTypeValidator] | None = None
config_schema: dict[str, Any] = field(default_factory=dict)


class DeletionStatus(IntEnum):
ACTIVE = 0
PENDING_DELETION = 1
DELETION_IN_PROGRESS = 2
Loading