Skip to content

Commit 3379637

Browse files
roggenkemperIrene Liu
authored andcommitted
chore(detectors): Update experimental N+1 API detector to use rollout flag (#99556)
adds flag so we can roll out experimental n+1 api call detector.
1 parent 91b2faf commit 3379637

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/sentry/performance_issues/detectors/experiments/n_plus_one_api_calls_detector.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from typing import Any
77
from urllib.parse import urlparse
88

9-
from sentry.issues.grouptype import PerformanceNPlusOneAPICallsExperimentalGroupType
9+
from sentry import features
10+
from sentry.issues.grouptype import PerformanceNPlusOneAPICallsGroupType
1011
from sentry.issues.issue_occurrence import IssueEvidence
1112
from sentry.models.organization import Organization
1213
from sentry.models.project import Project
@@ -73,7 +74,9 @@ def visit_span(self, span: Span) -> None:
7374
self.spans = [span]
7475

7576
def is_creation_allowed_for_organization(self, organization: Organization) -> bool:
76-
return True
77+
return features.has(
78+
"organizations:experimental-n-plus-one-api-detector-rollout", organization
79+
)
7780

7881
def is_creation_allowed_for_project(self, project: Project) -> bool:
7982
return self.settings["detection_enabled"]
@@ -177,7 +180,7 @@ def _maybe_store_problem(self) -> None:
177180
fingerprint=fingerprint,
178181
op=last_span["op"],
179182
desc=problem_description,
180-
type=PerformanceNPlusOneAPICallsExperimentalGroupType,
183+
type=PerformanceNPlusOneAPICallsGroupType,
181184
cause_span_ids=[],
182185
parent_span_ids=[parent_span_id] if parent_span_id else [],
183186
offender_span_ids=offender_span_ids,
@@ -262,7 +265,7 @@ def _fingerprint(self) -> str | None:
262265

263266
fingerprint = fingerprint_http_spans([self.spans[0]])
264267

265-
return f"1-{PerformanceNPlusOneAPICallsExperimentalGroupType.type_id}-{fingerprint}"
268+
return f"1-{PerformanceNPlusOneAPICallsGroupType.type_id}-{fingerprint}"
266269

267270
def _spans_are_concurrent(self, span_a: Span, span_b: Span) -> bool:
268271
span_a_start = span_a["start_timestamp"]

src/sentry/performance_issues/detectors/n_plus_one_api_calls_detector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from django.utils.encoding import force_bytes
1212

13+
from sentry import features
1314
from sentry.issues.grouptype import PerformanceNPlusOneAPICallsGroupType
1415
from sentry.issues.issue_occurrence import IssueEvidence
1516
from sentry.models.organization import Organization
@@ -73,7 +74,9 @@ def visit_span(self, span: Span) -> None:
7374
self.spans = [span]
7475

7576
def is_creation_allowed_for_organization(self, organization: Organization) -> bool:
76-
return True
77+
return not features.has(
78+
"organizations:experimental-n-plus-one-api-detector-rollout", organization
79+
)
7780

7881
def is_creation_allowed_for_project(self, project: Project) -> bool:
7982
return self.settings["detection_enabled"]

tests/sentry/performance_issues/experiments/test_n_plus_one_api_calls_detector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import pytest
88

9-
from sentry.issues.grouptype import PerformanceNPlusOneAPICallsExperimentalGroupType
9+
from sentry.issues.grouptype import PerformanceNPlusOneAPICallsGroupType
1010
from sentry.performance_issues.base import DetectorType, parameterize_url
1111
from sentry.performance_issues.detectors.experiments.n_plus_one_api_calls_detector import (
1212
NPlusOneAPICallsExperimentalDetector,
@@ -26,7 +26,7 @@
2626

2727
@pytest.mark.django_db
2828
class NPlusOneAPICallsExperimentalDetectorTest(TestCase):
29-
type_id = PerformanceNPlusOneAPICallsExperimentalGroupType.type_id
29+
type_id = PerformanceNPlusOneAPICallsGroupType.type_id
3030

3131
def setUp(self) -> None:
3232
super().setUp()
@@ -79,7 +79,7 @@ def test_detects_problems_with_many_concurrent_calls_to_same_url(self) -> None:
7979
PerformanceProblem(
8080
fingerprint=f"1-{self.type_id}-d750ce46bb1b13dd5780aac48098d5e20eea682c",
8181
op="http.client",
82-
type=PerformanceNPlusOneAPICallsExperimentalGroupType,
82+
type=PerformanceNPlusOneAPICallsGroupType,
8383
desc="GET /api/0/organizations/sentry/events/?field=replayId&field=count%28%29&per_page=50&query=issue.id%3A",
8484
parent_span_ids=["a0c39078d1570b00"],
8585
cause_span_ids=[],
@@ -145,7 +145,7 @@ def test_detects_problems_with_many_concurrent_calls_to_same_url(self) -> None:
145145
evidence_display=[],
146146
)
147147
]
148-
assert problems[0].title == "N+1 API Call (Experimental)"
148+
assert problems[0].title == "N+1 API Call"
149149

150150
def test_does_not_detect_problems_with_low_total_duration_of_spans(self) -> None:
151151
event = get_event("n-plus-one-api-calls/n-plus-one-api-calls-in-issue-stream")

0 commit comments

Comments
 (0)