-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
chore(alerts): Remove legacy metric alert handlers #115850
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
Merged
ceorourke
merged 1 commit into
master
from
ceorourke/rm-metric-alert-messaging-handlers
May 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| import logging | ||
| from abc import ABC, abstractmethod | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
@@ -7,34 +6,12 @@ | |
| from django.views.generic import View | ||
|
|
||
| from sentry import analytics | ||
| from sentry.api.serializers import serialize | ||
| from sentry.incidents.action_handlers import ActionHandler, DefaultActionHandler | ||
| from sentry.incidents.endpoints.serializers.alert_rule import ( | ||
| AlertRuleSerializer, | ||
| AlertRuleSerializerResponse, | ||
| ) | ||
| from sentry.incidents.endpoints.serializers.incident import ( | ||
| DetailedIncidentSerializer, | ||
| DetailedIncidentSerializerResponse, | ||
| ) | ||
| from sentry.incidents.models.alert_rule import ActionHandlerFactory, AlertRuleTriggerAction | ||
| from sentry.incidents.models.incident import Incident, IncidentStatus | ||
| from sentry.incidents.typings.metric_detector import ( | ||
| AlertContext, | ||
| MetricIssueContext, | ||
| NotificationContext, | ||
| OpenPeriodContext, | ||
| ) | ||
| from sentry.integrations.base import IntegrationProvider | ||
| from sentry.integrations.metric_alerts import get_metric_count_from_incident | ||
| from sentry.models.organization import Organization | ||
| from sentry.models.project import Project | ||
| from sentry.notifications.models.notificationaction import ActionService, ActionTarget | ||
| from sentry.rules import rules | ||
| from sentry.rules.actions import IntegrationEventAction | ||
|
|
||
| logger = logging.getLogger("sentry.integrations.messaging.spec") | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class MessagingIdentityLinkViewSet: | ||
|
|
@@ -145,20 +122,6 @@ def build_path(operation_slug: str, view_cls: type[View]) -> URLPattern: | |
| if view_cls is not None | ||
| ] | ||
|
|
||
| @abstractmethod | ||
| def send_incident_alert_notification( | ||
| self, | ||
| organization: Organization, | ||
| alert_context: AlertContext, | ||
| notification_context: NotificationContext, | ||
| metric_issue_context: MetricIssueContext, | ||
| open_period_context: OpenPeriodContext, | ||
| alert_rule_serialized_response: AlertRuleSerializerResponse, | ||
| incident_serialized_response: DetailedIncidentSerializerResponse, | ||
| notification_uuid: str | None = None, | ||
| ) -> bool: | ||
| raise NotImplementedError | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def notify_service_action(self) -> type[IntegrationEventAction] | None: | ||
|
|
@@ -180,63 +143,6 @@ def notification_sent(self) -> type[analytics.Event] | None: | |
| raise NotImplementedError | ||
|
|
||
|
|
||
| class MessagingActionHandler(DefaultActionHandler): | ||
| def __init__(self, spec: MessagingIntegrationSpec): | ||
| super().__init__() | ||
| self._spec = spec | ||
|
|
||
| @property | ||
| def provider(self) -> str: | ||
| return self._spec.provider_slug | ||
|
|
||
| def send_alert( | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The modern equivalent is https://github.com/getsentry/sentry/blob/master/src/sentry/notifications/notification_action/types.py#L469 in the |
||
| self, | ||
| action: AlertRuleTriggerAction, | ||
| incident: Incident, | ||
| project: Project, | ||
| metric_value: int | float | None, | ||
| new_status: IncidentStatus, | ||
| notification_uuid: str | None = None, | ||
| ) -> None: | ||
| if metric_value is None: | ||
| metric_value = get_metric_count_from_incident(incident) | ||
|
|
||
| alert_rule_serialized_response: AlertRuleSerializerResponse = serialize( | ||
| incident.alert_rule, None, AlertRuleSerializer() | ||
| ) | ||
| incident_serialized_response: DetailedIncidentSerializerResponse = serialize( | ||
| incident, None, DetailedIncidentSerializer() | ||
| ) | ||
| open_period_context = OpenPeriodContext.from_incident(incident=incident) | ||
|
|
||
| notification_context = NotificationContext.from_alert_rule_trigger_action(action) | ||
| alert_context = AlertContext.from_alert_rule_incident(incident.alert_rule) | ||
| metric_issue_context = MetricIssueContext.from_legacy_models( | ||
| incident=incident, | ||
| new_status=new_status, | ||
| metric_value=metric_value, | ||
| ) | ||
|
|
||
| success = self._spec.send_incident_alert_notification( | ||
| organization=incident.organization, | ||
| alert_context=alert_context, | ||
| notification_context=notification_context, | ||
| metric_issue_context=metric_issue_context, | ||
| open_period_context=open_period_context, | ||
| alert_rule_serialized_response=alert_rule_serialized_response, | ||
| incident_serialized_response=incident_serialized_response, | ||
| notification_uuid=notification_uuid, | ||
| ) | ||
| if success: | ||
| self.record_alert_sent_analytics( | ||
| organization_id=incident.organization.id, | ||
| project_id=project.id, | ||
| alert_id=incident.alert_rule.id, | ||
| external_id=action.target_identifier, | ||
| notification_uuid=notification_uuid, | ||
| ) | ||
|
|
||
|
|
||
| class _MessagingHandlerFactory(ActionHandlerFactory): | ||
| def __init__(self, spec: MessagingIntegrationSpec) -> None: | ||
| super().__init__( | ||
|
|
@@ -245,7 +151,3 @@ def __init__(self, spec: MessagingIntegrationSpec) -> None: | |
| supported_target_types=[ActionTarget.SPECIFIC], | ||
| integration_provider=spec.provider_slug, | ||
| ) | ||
| self.spec = spec | ||
|
|
||
| def build_handler(self) -> ActionHandler: | ||
| return MessagingActionHandler(self.spec) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still used by the legacy APIs for stuff like
organization_alert_rule_available_action_index