Skip to content

Commit 5a4b25c

Browse files
authored
ref(codeowners): Add analytics for issue owners rate limiting (#44929)
Creates an analytic event to track the events getting ratelimited by the Issue Owners ratelimit WOR-2682
1 parent 9db534d commit 5a4b25c

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

src/sentry/tasks/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from .analytics import * # NOQA
2+
13
"""Celery tasks.
24
35
Celery tasks are used to create asynchronous workers which communicate their tasks via a

src/sentry/tasks/analytics.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from sentry import analytics
2+
3+
4+
class IssueOwnersEventRatelimited(analytics.Event):
5+
type = "issue_owners_event.ratelimited"
6+
7+
attributes = (
8+
analytics.Attribute("event_id"),
9+
analytics.Attribute("group_id"),
10+
analytics.Attribute("project_id"),
11+
analytics.Attribute("organization_id"),
12+
)
13+
14+
15+
analytics.register(IssueOwnersEventRatelimited)

src/sentry/tasks/post_process.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from django.conf import settings
99
from django.utils import timezone
1010

11-
from sentry import features
11+
from sentry import analytics, features
1212
from sentry.exceptions import PluginError
1313
from sentry.issues.grouptype import GroupCategory
1414
from sentry.issues.issue_occurrence import IssueOccurrence
@@ -180,6 +180,13 @@ def handle_owner_assignment(job):
180180
"reason": "ratelimited",
181181
},
182182
)
183+
analytics.record(
184+
"issue_owners_event.ratelimited",
185+
event_id=event.event_id,
186+
group_id=event.group_id,
187+
project_id=event.project_id,
188+
organization_id=event.project.organization_id,
189+
)
183190
return
184191

185192
with sentry_sdk.start_span(

tests/sentry/tasks/test_post_process.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,9 @@ def test_debounces_handle_owner_assignments(self, logger):
989989
},
990990
)
991991

992+
@patch("sentry.analytics.record")
992993
@patch("sentry.tasks.post_process.logger")
993-
def test_issue_owners_should_ratelimit(self, logger):
994+
def test_issue_owners_should_ratelimit(self, logger, record_mock):
994995
cache.set(
995996
f"issue_owner_assignment_ratelimit:{self.project.id}",
996997
(ISSUE_OWNERS_PER_PROJECT_PER_MIN_RATELIMIT, datetime.now()),
@@ -1020,6 +1021,13 @@ def test_issue_owners_should_ratelimit(self, logger):
10201021
"reason": "ratelimited",
10211022
},
10221023
)
1024+
record_mock.assert_called_with(
1025+
"issue_owners_event.ratelimited",
1026+
event_id=event.event_id,
1027+
group_id=event.group_id,
1028+
project_id=event.project_id,
1029+
organization_id=event.project.organization_id,
1030+
)
10231031

10241032

10251033
class ProcessCommitsTestMixin(BasePostProgressGroupMixin):

0 commit comments

Comments
 (0)