Skip to content

Commit 4954bdc

Browse files
chore(opsgenie): instrument opsgenie installation slos (#94587)
1 parent 7c00178 commit 4954bdc

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

src/sentry/integrations/opsgenie/integration.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from sentry.integrations.base import (
1515
FeatureDescription,
1616
IntegrationData,
17+
IntegrationDomain,
1718
IntegrationFeatures,
1819
IntegrationInstallation,
1920
IntegrationMetadata,
@@ -26,6 +27,10 @@
2627
from sentry.integrations.opsgenie.tasks import migrate_opsgenie_plugin
2728
from sentry.integrations.pipeline import IntegrationPipeline
2829
from sentry.integrations.types import IntegrationProviderSlug
30+
from sentry.integrations.utils.metrics import (
31+
IntegrationPipelineViewEvent,
32+
IntegrationPipelineViewType,
33+
)
2934
from sentry.organizations.services.organization.model import RpcOrganization
3035
from sentry.pipeline.views.base import PipelineView
3136
from sentry.shared_integrations.exceptions import (
@@ -105,24 +110,30 @@ class InstallationForm(forms.Form):
105110

106111

107112
class InstallationConfigView:
108-
def dispatch(self, request: HttpRequest, pipeline: IntegrationPipeline) -> HttpResponseBase:
109-
if request.method == "POST":
110-
form = InstallationForm(request.POST)
111-
if form.is_valid():
112-
form_data = form.cleaned_data
113-
114-
pipeline.bind_state("installation_data", form_data)
115-
116-
return pipeline.next_step()
117-
else:
118-
form = InstallationForm()
119-
120-
return render_to_response(
121-
template="sentry/integrations/opsgenie-config.html",
122-
context={"form": form},
123-
request=request,
113+
def record_event(self, event: IntegrationPipelineViewType):
114+
return IntegrationPipelineViewEvent(
115+
event, IntegrationDomain.ON_CALL_SCHEDULING, OpsgenieIntegrationProvider.key
124116
)
125117

118+
def dispatch(self, request: HttpRequest, pipeline: IntegrationPipeline) -> HttpResponseBase:
119+
with self.record_event(IntegrationPipelineViewType.INSTALLATION_CONFIGURATION).capture():
120+
if request.method == "POST":
121+
form = InstallationForm(request.POST)
122+
if form.is_valid():
123+
form_data = form.cleaned_data
124+
125+
pipeline.bind_state("installation_data", form_data)
126+
127+
return pipeline.next_step()
128+
else:
129+
form = InstallationForm()
130+
131+
return render_to_response(
132+
template="sentry/integrations/opsgenie-config.html",
133+
context={"form": form},
134+
request=request,
135+
)
136+
126137

127138
class OpsgenieIntegration(IntegrationInstallation):
128139
def get_keyring_client(self, keyid: int | str) -> OpsgenieClient:

src/sentry/integrations/utils/metrics.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ class IntegrationPipelineViewType(StrEnum):
355355
# Jira Server
356356
WEBHOOK_CREATION = "webhook_creation"
357357

358+
# Opsgenie
359+
INSTALLATION_CONFIGURATION = "installation_configuration"
360+
358361

359362
class IntegrationPipelineErrorReason(StrEnum):
360363
# OAuth identity

tests/sentry/integrations/opsgenie/test_integration.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from sentry.integrations.types import EventLifecycleOutcome
1616
from sentry.models.rule import Rule
1717
from sentry.shared_integrations.exceptions import ApiRateLimitedError, ApiUnauthorized
18-
from sentry.testutils.asserts import assert_slo_metric
18+
from sentry.testutils.asserts import assert_slo_metric, assert_success_metric
1919
from sentry.testutils.cases import APITestCase, IntegrationTestCase
2020
from sentry.testutils.helpers.features import with_feature
2121
from sentry.testutils.silo import assume_test_silo_mode_of, control_silo_test
@@ -64,9 +64,13 @@ def assert_setup_flow(self, config):
6464
resp = self.client.post(self.init_path, data=config)
6565
assert resp.status_code == 200
6666

67-
def test_installation_no_key(self):
67+
@patch("sentry.integrations.utils.metrics.EventLifecycle.record_event")
68+
def test_installation_no_key(self, mock_record):
6869
self.assert_setup_flow(self.config_no_key)
6970

71+
# SLO assertions
72+
assert_success_metric(mock_record)
73+
7074
integration = Integration.objects.get(provider=self.provider.key)
7175
org_integration = OrganizationIntegration.objects.get(integration_id=integration.id)
7276

0 commit comments

Comments
 (0)