From c2484ff41ec073a1d13bc8737c7132597bd3f4df Mon Sep 17 00:00:00 2001 From: Michelle Fu Date: Fri, 22 Nov 2024 12:07:31 -0800 Subject: [PATCH] replace validation error failures with halts --- src/sentry/integrations/on_call/metrics.py | 11 ++++++++++- src/sentry/integrations/opsgenie/actions/form.py | 6 ++++-- src/sentry/integrations/pagerduty/actions/form.py | 5 +++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/sentry/integrations/on_call/metrics.py b/src/sentry/integrations/on_call/metrics.py index 76f1b203c203b..9b5585906a9af 100644 --- a/src/sentry/integrations/on_call/metrics.py +++ b/src/sentry/integrations/on_call/metrics.py @@ -1,4 +1,4 @@ -from enum import Enum +from enum import Enum, StrEnum from attr import dataclass @@ -56,3 +56,12 @@ def get_integration_name(self) -> str: def get_interaction_type(self) -> str: return str(self.interaction_type) + + +class OnCallIntegrationsHaltReason(StrEnum): + """ + Reasons why on on call integration method may halt without success/failure. + """ + + INVALID_TEAM = "invalid_team" + INVALID_SERVICE = "invalid_service" diff --git a/src/sentry/integrations/opsgenie/actions/form.py b/src/sentry/integrations/opsgenie/actions/form.py index a6a29d9d20814..e99b04ac87d29 100644 --- a/src/sentry/integrations/opsgenie/actions/form.py +++ b/src/sentry/integrations/opsgenie/actions/form.py @@ -6,7 +6,7 @@ from django import forms from django.utils.translation import gettext_lazy as _ -from sentry.integrations.on_call.metrics import OnCallInteractionType +from sentry.integrations.on_call.metrics import OnCallIntegrationsHaltReason, OnCallInteractionType from sentry.integrations.opsgenie.metrics import record_event from sentry.integrations.opsgenie.utils import get_team from sentry.integrations.services.integration import integration_service @@ -65,7 +65,7 @@ def _get_team_status( return VALID_TEAM def _validate_team(self, team_id: str | None, integration_id: int | None) -> None: - with record_event(OnCallInteractionType.VERIFY_TEAM).capture(): + with record_event(OnCallInteractionType.VERIFY_TEAM).capture() as lifecyle: params = { "account": dict(self.fields["account"].choices).get(integration_id), "team": dict(self.fields["team"].choices).get(team_id), @@ -78,6 +78,7 @@ def _validate_team(self, team_id: str | None, integration_id: int | None) -> Non organization_id=self.org_id, ) if integration is None or org_integration is None: + lifecyle.record_halt(str(OnCallIntegrationsHaltReason.INVALID_TEAM)) raise forms.ValidationError( _("The Opsgenie integration does not exist."), code="invalid_integration", @@ -86,6 +87,7 @@ def _validate_team(self, team_id: str | None, integration_id: int | None) -> Non team_status = self._get_team_status(team_id=team_id, org_integration=org_integration) if team_status == INVALID_TEAM: + lifecyle.record_halt(str(OnCallIntegrationsHaltReason.INVALID_TEAM)) raise forms.ValidationError( _('The team "%(team)s" does not belong to the %(account)s Opsgenie account.'), code="invalid_team", diff --git a/src/sentry/integrations/pagerduty/actions/form.py b/src/sentry/integrations/pagerduty/actions/form.py index 3ac96179b5479..68e7dfd8f0a30 100644 --- a/src/sentry/integrations/pagerduty/actions/form.py +++ b/src/sentry/integrations/pagerduty/actions/form.py @@ -6,7 +6,7 @@ from django import forms from django.utils.translation import gettext_lazy as _ -from sentry.integrations.on_call.metrics import OnCallInteractionType +from sentry.integrations.on_call.metrics import OnCallIntegrationsHaltReason, OnCallInteractionType from sentry.integrations.pagerduty.metrics import record_event from sentry.integrations.services.integration import integration_service from sentry.integrations.types import ExternalProviders @@ -47,7 +47,7 @@ def __init__(self, *args, **kwargs): self.fields["service"].widget.choices = self.fields["service"].choices def _validate_service(self, service_id: int, integration_id: int) -> None: - with record_event(OnCallInteractionType.VALIDATE_SERVICE).capture(): + with record_event(OnCallInteractionType.VALIDATE_SERVICE).capture() as lifecycle: params = { "account": dict(self.fields["account"].choices).get(integration_id), "service": dict(self.fields["service"].choices).get(service_id), @@ -66,6 +66,7 @@ def _validate_service(self, service_id: int, integration_id: int) -> None: ): # We need to make sure that the service actually belongs to that integration, # meaning that it belongs under the appropriate account in PagerDuty. + lifecycle.record_halt(str(OnCallIntegrationsHaltReason.INVALID_SERVICE)) raise forms.ValidationError( _( 'The service "%(service)s" has not been granted access in the %(account)s Pagerduty account.'