From 32b9853be2d2d2fab73c9753f6b53797aec2236b Mon Sep 17 00:00:00 2001 From: Colleen O'Rourke Date: Mon, 6 Jan 2025 15:14:38 -0800 Subject: [PATCH] chore(alerts): Remove activated alerts from notifications (#81283) Another chunk of https://github.com/getsentry/sentry/pull/81095 that removes the notification code for activated alerts. This can't be merged until https://github.com/getsentry/sentry/pull/81218 is merged. --- src/sentry/incidents/action_handlers.py | 6 -- src/sentry/integrations/metric_alerts.py | 2 - .../templates/sentry/debug/mail/preview.html | 1 - .../sentry/emails/incidents/trigger.html | 11 --- .../sentry/emails/incidents/trigger.txt | 7 -- src/sentry/web/debug_urls.py | 7 -- ..._incident_trigger_email_activated_alert.py | 77 ------------------- .../incidents/action_handlers/test_email.py | 66 ---------------- 8 files changed, 177 deletions(-) delete mode 100644 src/sentry/web/frontend/debug/debug_incident_trigger_email_activated_alert.py diff --git a/src/sentry/incidents/action_handlers.py b/src/sentry/incidents/action_handlers.py index 190ffdaebea093..a17219ed67ff7e 100644 --- a/src/sentry/incidents/action_handlers.py +++ b/src/sentry/incidents/action_handlers.py @@ -346,7 +346,6 @@ def generate_incident_trigger_email_context( ): trigger = alert_rule_trigger alert_rule = trigger.alert_rule - activation = incident.activation assert alert_rule.snuba_query is not None snuba_query = alert_rule.snuba_query is_active = trigger_status == TriggerStatus.ACTIVE @@ -445,9 +444,4 @@ def generate_incident_trigger_email_context( "timezone": tz, "snooze_alert": snooze_alert, "snooze_alert_url": snooze_alert_url, - "monitor_type": alert_rule.monitor_type, # 0 = continuous, 1 = activated - "activator": (activation.activator if activation else ""), - "condition_type": ( - activation.condition_type if activation else None - ), # 0 = release creation, 1 = deploy creation } diff --git a/src/sentry/integrations/metric_alerts.py b/src/sentry/integrations/metric_alerts.py index fb544a6bd9b951..1a3ad9d87d7a38 100644 --- a/src/sentry/integrations/metric_alerts.py +++ b/src/sentry/integrations/metric_alerts.py @@ -231,7 +231,6 @@ def metric_alert_attachment_info( if latest_incident: last_triggered_date = latest_incident.date_started - # TODO: determine whether activated alert data is useful for integration messages return { "title": title, "text": text, @@ -240,7 +239,6 @@ def metric_alert_attachment_info( "date_started": date_started, "last_triggered_date": last_triggered_date, "title_link": title_link, - "monitor_type": alert_rule.monitor_type, # 0 = continuous, 1 = activated "activator": (activation.activator if activation else ""), "condition_type": ( activation.condition_type if activation else None diff --git a/src/sentry/templates/sentry/debug/mail/preview.html b/src/sentry/templates/sentry/debug/mail/preview.html index 096ec3f904151a..8f7b686f4f2380 100644 --- a/src/sentry/templates/sentry/debug/mail/preview.html +++ b/src/sentry/templates/sentry/debug/mail/preview.html @@ -29,7 +29,6 @@ - diff --git a/src/sentry/templates/sentry/emails/incidents/trigger.html b/src/sentry/templates/sentry/emails/incidents/trigger.html index ef846494819361..8a768c28454568 100644 --- a/src/sentry/templates/sentry/emails/incidents/trigger.html +++ b/src/sentry/templates/sentry/emails/incidents/trigger.html @@ -50,17 +50,6 @@
Environment {{ environment }} - {% if monitor_type == 1 %} - - {% if condition_type == 0 %} - New Release - {{activator}} - {% elif condition_type == 1 %} - New Deploy - {{activator}} - {% endif %} - - {% endif %} Threshold diff --git a/src/sentry/templates/sentry/emails/incidents/trigger.txt b/src/sentry/templates/sentry/emails/incidents/trigger.txt index ee65a6ce23a875..f59a1698cbefac 100644 --- a/src/sentry/templates/sentry/emails/incidents/trigger.txt +++ b/src/sentry/templates/sentry/emails/incidents/trigger.txt @@ -10,13 +10,6 @@ controls are enabled. For more details about this alert alert, view on Sentry: Alert: {{ link }} Status: {{ status }} Project: {{ project_slug }} -{% if monitor_type == 1 %} - {% if condition_type == 0 %} -New Release: {{activator}} - {% elif condition_type == 1 %} -New Deploy: {{activator}} - {% endif %} -{% endif %} Metric: {{ aggregate }} Environment: {{ environment }} Threshold: {{ threshold_prefix_string }} {{ threshold }} diff --git a/src/sentry/web/debug_urls.py b/src/sentry/web/debug_urls.py index 5afc8bcdb669a3..598646c4fa59e8 100644 --- a/src/sentry/web/debug_urls.py +++ b/src/sentry/web/debug_urls.py @@ -22,9 +22,6 @@ from sentry.web.frontend.debug.debug_feedback_issue import DebugFeedbackIssueEmailView from sentry.web.frontend.debug.debug_generic_issue import DebugGenericIssueEmailView from sentry.web.frontend.debug.debug_incident_trigger_email import DebugIncidentTriggerEmailView -from sentry.web.frontend.debug.debug_incident_trigger_email_activated_alert import ( - DebugIncidentActivatedAlertTriggerEmailView, -) from sentry.web.frontend.debug.debug_invalid_identity_email import DebugInvalidIdentityEmailView from sentry.web.frontend.debug.debug_mfa_added_email import DebugMfaAddedEmailView from sentry.web.frontend.debug.debug_mfa_removed_email import DebugMfaRemovedEmailView @@ -148,10 +145,6 @@ r"^debug/mail/sso-unlinked/no-password/$", DebugSsoUnlinkedNoPasswordEmailView.as_view() ), re_path(r"^debug/mail/incident-trigger/$", DebugIncidentTriggerEmailView.as_view()), - re_path( - r"^debug/mail/activated-incident-trigger/$", - DebugIncidentActivatedAlertTriggerEmailView.as_view(), - ), re_path(r"^debug/mail/setup-2fa/$", DebugSetup2faEmailView.as_view()), re_path(r"^debug/embed/error-page/$", DebugErrorPageEmbedView.as_view()), re_path(r"^debug/trigger-error/$", DebugTriggerErrorView.as_view()), diff --git a/src/sentry/web/frontend/debug/debug_incident_trigger_email_activated_alert.py b/src/sentry/web/frontend/debug/debug_incident_trigger_email_activated_alert.py deleted file mode 100644 index 09c54ebae4c284..00000000000000 --- a/src/sentry/web/frontend/debug/debug_incident_trigger_email_activated_alert.py +++ /dev/null @@ -1,77 +0,0 @@ -from unittest import mock -from uuid import uuid4 - -from django.utils import timezone - -from sentry.incidents.action_handlers import generate_incident_trigger_email_context -from sentry.incidents.models.alert_rule import AlertRule, AlertRuleMonitorTypeInt, AlertRuleTrigger -from sentry.incidents.models.alert_rule_activations import AlertRuleActivations -from sentry.incidents.models.incident import Incident, IncidentStatus, TriggerStatus -from sentry.incidents.utils.types import AlertRuleActivationConditionType -from sentry.models.organization import Organization -from sentry.models.project import Project -from sentry.snuba.models import SnubaQuery -from sentry.users.models.user import User - -from .mail import MailPreviewView - - -class MockedIncidentTrigger: - date_added = timezone.now() - - -class DebugIncidentActivatedAlertTriggerEmailView(MailPreviewView): - @mock.patch( - "sentry.incidents.models.incident.IncidentTrigger.objects.get", - return_value=MockedIncidentTrigger(), - ) - @mock.patch( - "sentry.users.models.user_option.UserOption.objects.get_value", return_value="US/Pacific" - ) - def get_context(self, request, incident_trigger_mock, user_option_mock): - organization = Organization(slug="myorg") - project = Project(slug="myproject", organization=organization) - user = User() - - query = SnubaQuery( - time_window=60, query="transaction:/some/transaction", aggregate="count()" - ) - alert_rule = AlertRule( - id=1, - organization=organization, - name="My Alert", - snuba_query=query, - monitor_type=AlertRuleMonitorTypeInt.ACTIVATED, - ) - activation = AlertRuleActivations( - alert_rule=alert_rule, - condition_type=AlertRuleActivationConditionType.DEPLOY_CREATION.value, - ) - incident = Incident( - id=2, - identifier=123, - organization=organization, - title="Something broke", - alert_rule=alert_rule, - status=IncidentStatus.CRITICAL.value, - activation=activation, - ) - trigger = AlertRuleTrigger(alert_rule=alert_rule) - - return generate_incident_trigger_email_context( - project, - incident, - trigger, - TriggerStatus.ACTIVE, - IncidentStatus(incident.status), - user, - notification_uuid=str(uuid4()), - ) - - @property - def html_template(self): - return "sentry/emails/incidents/trigger.html" - - @property - def text_template(self): - return "sentry/emails/incidents/trigger.txt" diff --git a/tests/sentry/incidents/action_handlers/test_email.py b/tests/sentry/incidents/action_handlers/test_email.py index e84b1f6cf20eb1..8fba74fbac4473 100644 --- a/tests/sentry/incidents/action_handlers/test_email.py +++ b/tests/sentry/incidents/action_handlers/test_email.py @@ -18,14 +18,12 @@ from sentry.incidents.logic import CRITICAL_TRIGGER_LABEL, WARNING_TRIGGER_LABEL from sentry.incidents.models.alert_rule import ( AlertRuleDetectionType, - AlertRuleMonitorTypeInt, AlertRuleSeasonality, AlertRuleSensitivity, AlertRuleThresholdType, AlertRuleTriggerAction, ) from sentry.incidents.models.incident import INCIDENT_STATUS, IncidentStatus, TriggerStatus -from sentry.incidents.utils.types import AlertRuleActivationConditionType from sentry.notifications.models.notificationsettingoption import NotificationSettingOption from sentry.seer.anomaly_detection.types import StoreDataResponse from sentry.sentry_metrics import indexer @@ -278,67 +276,6 @@ def test_simple(self): "timezone": settings.SENTRY_DEFAULT_TIME_ZONE, "snooze_alert": True, "snooze_alert_url": alert_link + "&mute=1", - "monitor_type": 0, - "activator": "", - "condition_type": None, - } - assert expected == generate_incident_trigger_email_context( - self.project, - incident, - action.alert_rule_trigger, - trigger_status, - IncidentStatus(incident.status), - ) - - def test_with_activated_alert(self): - trigger_status = TriggerStatus.ACTIVE - alert_rule = self.create_alert_rule(monitor_type=AlertRuleMonitorTypeInt.ACTIVATED) - alert_rule.subscribe_projects( - projects=[self.project], - monitor_type=AlertRuleMonitorTypeInt.ACTIVATED, - activation_condition=AlertRuleActivationConditionType.DEPLOY_CREATION, - activator="testing", - ) - activations = alert_rule.activations.all() - incident = self.create_incident(alert_rule=alert_rule, activation=activations[0]) - alert_rule_trigger = self.create_alert_rule_trigger(alert_rule=alert_rule) - action = self.create_alert_rule_trigger_action( - alert_rule_trigger=alert_rule_trigger, triggered_for_incident=incident - ) - aggregate = action.alert_rule_trigger.alert_rule.snuba_query.aggregate - alert_link = self.organization.absolute_url( - reverse( - "sentry-metric-alert", - kwargs={ - "organization_slug": incident.organization.slug, - "incident_id": incident.identifier, - }, - ), - query="referrer=metric_alert_email", - ) - expected = { - "link": alert_link, - "incident_name": incident.title, - "aggregate": aggregate, - "query": action.alert_rule_trigger.alert_rule.snuba_query.query, - "threshold": action.alert_rule_trigger.alert_threshold, - "status": INCIDENT_STATUS[IncidentStatus(incident.status)], - "status_key": INCIDENT_STATUS[IncidentStatus(incident.status)].lower(), - "environment": "All", - "is_critical": False, - "is_warning": False, - "threshold_prefix_string": ">", - "time_window": "10 minutes", - "triggered_at": timezone.now(), - "project_slug": self.project.slug, - "unsubscribe_link": None, - "chart_url": None, - "timezone": settings.SENTRY_DEFAULT_TIME_ZONE, - "snooze_alert": True, - "snooze_alert_url": alert_link + "&mute=1", - "monitor_type": AlertRuleMonitorTypeInt.ACTIVATED, - "activator": "testing", - "condition_type": AlertRuleActivationConditionType.DEPLOY_CREATION.value, } assert expected == generate_incident_trigger_email_context( self.project, @@ -402,9 +339,6 @@ def test_dynamic_alert(self, mock_seer_request): "timezone": settings.SENTRY_DEFAULT_TIME_ZONE, "snooze_alert": True, "snooze_alert_url": alert_link + "&mute=1", - "monitor_type": 0, - "activator": "", - "condition_type": None, } assert expected == generate_incident_trigger_email_context( self.project,