Skip to content
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

ref(workflow_engine): Add legacy_notification_product column to workflow_engine.Action #82117

Merged
merged 3 commits into from
Dec 17, 2024
Merged
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
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ social_auth: 0002_default_auto_field

uptime: 0018_add_trace_sampling_field_to_uptime

workflow_engine: 0015_create_rule_lookup_tables
workflow_engine: 0016_refactor_action_model
2 changes: 1 addition & 1 deletion src/sentry/testutils/helpers/backups.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def create_exhaustive_organization(
organization=org,
)

send_notification_action = self.create_action(type=Action.Type.NOTIFICATION, data="")
send_notification_action = self.create_action(type=Action.Type.SLACK, data="")
self.create_data_condition_group_action(
action=send_notification_action,
condition_group=notification_condition_group,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from sentry.workflow_engine.types import ActionHandler


@action_handler_registry.register(Action.Type.NOTIFICATION)
# TODO - Enable once the PR to allow for multiple of the same funcs is merged
# @action_handler_registry.register(Action.Type.PAGERDUTY)
@action_handler_registry.register(Action.Type.SLACK)
class NotificationActionHandler(ActionHandler):
@staticmethod
def execute(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 5.1.4 on 2024-12-17 03:31

from django.db import migrations, models

from sentry.new_migrations.migrations import CheckedMigration


class Migration(CheckedMigration):
# This flag is used to mark that a migration shouldn't be automatically run in production.
# This should only be used for operations where it's safe to run the migration after your
# code has deployed. So this should not be used for most operations that alter the schema
# of a table.
# Here are some things that make sense to mark as post deployment:
# - Large data migrations. Typically we want these to be run manually so that they can be
# monitored and not block the deploy for a long period of time while they run.
# - Adding indexes to large tables. Since this can take a long time, we'd generally prefer to
# run this outside deployments so that we don't block them. Note that while adding an index
# is a schema change, it's completely safe to run the operation after the code has deployed.
# Once deployed, run these manually via: https://develop.sentry.dev/database-migrations/#migration-deployment

is_post_deployment = False

dependencies = [
("workflow_engine", "0015_create_rule_lookup_tables"),
]

operations = [
migrations.AddField(
model_name="action",
name="legacy_notification_type",
field=models.TextField(null=True),
),
]
15 changes: 14 additions & 1 deletion src/sentry/workflow_engine/models/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ class Action(DefaultFieldsModel):
__repr__ = sane_repr("id", "type")

class Type(models.TextChoices):
NOTIFICATION = "notification"
EMAIL = "email"
SLACK = "slack"
PAGERDUTY = "pagerduty"
WEBHOOK = "webhook"

class LegacyNotificationType(models.TextChoices):
ISSUE_ALERT = "issue"
METRIC_ALERT = "metric"

# The type field is used to denote the type of action we want to trigger
type = models.TextField(choices=Type.choices)
data = models.JSONField(default=dict)
Expand All @@ -46,6 +52,13 @@ class Type(models.TextChoices):
"sentry.Integration", blank=True, null=True, on_delete="CASCADE"
)

# LEGACY: The legacy_notification_type is used to denote if this notification was for an issue alert, metric alert, etc.
# We need this because of how tightly coupled the notification system is with the legacy alert models
legacy_notification_type = models.TextField(
null=True,
choices=LegacyNotificationType.choices,
)

# LEGACY: The target_display is used to display the target's name in notifications
target_display = models.TextField(null=True)

Expand Down
6 changes: 3 additions & 3 deletions tests/sentry/workflow_engine/models/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestAction(TestCase):
def setUp(self):
self.mock_event = Mock(spec=GroupEvent)
self.mock_detector = Mock(name="detector")
self.action = Action(type=Action.Type.NOTIFICATION)
self.action = Action(type=Action.Type.SLACK)

def test_get_handler_notification_type(self):
with patch("sentry.workflow_engine.registry.action_handler_registry.get") as mock_get:
Expand All @@ -22,7 +22,7 @@ def test_get_handler_notification_type(self):

handler = self.action.get_handler()

mock_get.assert_called_once_with(Action.Type.NOTIFICATION)
mock_get.assert_called_once_with(Action.Type.SLACK)
assert handler == mock_handler

def test_get_handler_webhook_type(self):
Expand All @@ -49,7 +49,7 @@ def test_get_handler_unregistered_type(self):
self.action.get_handler()

# Verify the registry was queried with the correct action type
mock_get.assert_called_once_with(Action.Type.NOTIFICATION)
mock_get.assert_called_once_with(Action.Type.SLACK)

def test_trigger_calls_handler_execute(self):
mock_handler = Mock(spec=ActionHandler)
Expand Down
2 changes: 1 addition & 1 deletion tests/sentry/workflow_engine/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def create_workflow_action(
action_group = self.create_data_condition_group(logic_type="any-short")

action = self.create_action(
type=Action.Type.NOTIFICATION,
type=Action.Type.SLACK,
data={"message": "test"},
**kwargs,
)
Expand Down
Loading