Skip to content

Commit 80f9de5

Browse files
authored
chore(snuba): Pass referrer to get_groups_user_counts (#69056)
The group model's method `count_users_seen` is called by a few different features but `get_groups_user_counts` hard codes the referrer so we can't tell who is actually calling it. This PR passes the referrer in with a description of where it's coming from.
1 parent 6bcfc87 commit 80f9de5

File tree

8 files changed

+49
-9
lines changed

8 files changed

+49
-9
lines changed

src/sentry/integrations/slack/message_builder/issues.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from sentry.services.hybrid_cloud.actor import ActorType, RpcActor
5656
from sentry.services.hybrid_cloud.identity import RpcIdentity, identity_service
5757
from sentry.services.hybrid_cloud.user.model import RpcUser
58+
from sentry.snuba.referrer import Referrer
5859
from sentry.types.group import SUBSTATUS_TO_STR
5960
from sentry.types.integrations import ExternalProviders
6061
from sentry.utils import json
@@ -100,7 +101,9 @@ def get_approx_start_time(group: Group):
100101
# pull things out into their own functions
101102
SUPPORTED_CONTEXT_DATA = {
102103
"Events": lambda group: get_group_global_count(group),
103-
"Users Affected": lambda group: group.count_users_seen(),
104+
"Users Affected": lambda group: group.count_users_seen(
105+
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_SLACK_ISSUE_NOTIFICATION.value
106+
),
104107
"State": lambda group: SUBSTATUS_TO_STR.get(group.substatus, "").replace("_", " ").title(),
105108
"First Seen": lambda group: time_since(group.first_seen),
106109
"Approx. Start Time": get_approx_start_time,

src/sentry/issues/ignored.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from sentry.services.hybrid_cloud.user.serial import serialize_generic_user
2020
from sentry.services.hybrid_cloud.user.service import user_service
2121
from sentry.signals import issue_archived
22+
from sentry.snuba.referrer import Referrer
2223
from sentry.types.group import GroupSubStatus
2324
from sentry.utils import metrics
2425

@@ -111,7 +112,9 @@ def handle_ignored(
111112
if ignore_count and not ignore_window:
112113
state["times_seen"] = group.times_seen
113114
if ignore_user_count and not ignore_user_window:
114-
state["users_seen"] = group.count_users_seen()
115+
state["users_seen"] = group.count_users_seen(
116+
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_IGNORED.value
117+
)
115118
GroupSnooze.objects.create_or_update(
116119
group=group,
117120
values={

src/sentry/models/group.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from sentry.models.organization import Organization
4848
from sentry.services.hybrid_cloud.actor import RpcActor
4949
from sentry.snuba.dataset import Dataset
50+
from sentry.snuba.referrer import Referrer
5051
from sentry.types.activity import ActivityType
5152
from sentry.types.group import (
5253
IGNORED_SUBSTATUS_CHOICES,
@@ -872,13 +873,14 @@ def checksum(self):
872873
def get_email_subject(self):
873874
return f"{self.qualified_short_id} - {self.title}"
874875

875-
def count_users_seen(self):
876+
def count_users_seen(self, referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS.value):
876877
return tagstore.backend.get_groups_user_counts(
877878
[self.project_id],
878879
[self.id],
879880
environment_ids=None,
880881
start=self.first_seen,
881882
tenant_ids={"organization_id": self.project.organization_id},
883+
referrer=referrer,
882884
)[self.id]
883885

884886
@classmethod

src/sentry/models/groupsnooze.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
sane_repr,
1919
)
2020
from sentry.issues.constants import get_issue_tsdb_group_model, get_issue_tsdb_user_group_model
21+
from sentry.snuba.referrer import Referrer
2122
from sentry.utils import metrics
2223
from sentry.utils.cache import cache
2324

@@ -87,7 +88,13 @@ def is_valid(self, group=None, test_rates=False, use_pending_data=False):
8788
if self.user_window:
8889
if not self.test_user_rates():
8990
return False
90-
elif self.user_count <= group.count_users_seen() - self.state["users_seen"]:
91+
elif (
92+
self.user_count
93+
<= group.count_users_seen(
94+
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_GROUP_SNOOZE.value
95+
)
96+
- self.state["users_seen"]
97+
):
9198
return False
9299
return True
93100

src/sentry/snuba/referrer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,14 @@ class Referrer(Enum):
689689
TAGSTORE_GET_GROUP_LIST_TAG_VALUE = "tagstore.get_group_list_tag_value"
690690
TAGSTORE_GET_GROUP_TAG_VALUE_ITER = "tagstore.get_group_tag_value_iter"
691691
TAGSTORE_GET_GROUPS_USER_COUNTS = "tagstore.get_groups_user_counts"
692+
TAGSTORE_GET_GROUPS_USER_COUNTS_OPEN_PR_COMMENT = (
693+
"tagstore.get_groups_user_counts.open_pr_comment"
694+
)
695+
TAGSTORE_GET_GROUPS_USER_COUNTS_GROUP_SNOOZE = "tagstore.get_groups_user_counts.groupsnooze"
696+
TAGSTORE_GET_GROUPS_USER_COUNTS_IGNORED = "tagstore.get_groups_user_counts.ignored"
697+
TAGSTORE_GET_GROUPS_USER_COUNTS_SLACK_ISSUE_NOTIFICATION = (
698+
"tagstore.get_groups_user_counts.slack_issue_notification"
699+
)
692700
TAGSTORE_GET_GENERIC_GROUP_LIST_TAG_VALUE = "tagstore.get_generic_group_list_tag_value"
693701
TAGSTORE_GET_GENERIC_GROUPS_USER_COUNTS = "tagstore.get_generic_groups_user_counts"
694702
TAGSTORE_GET_RELEASE_TAGS = "tagstore.get_release_tags"

src/sentry/tagstore/base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,14 @@ def get_group_tag_value_qs(self, project_id, group_id, environment_id, key, valu
256256
raise NotImplementedError
257257

258258
def get_groups_user_counts(
259-
self, project_ids, group_ids, environment_ids, start=None, end=None, tenant_ids=None
259+
self,
260+
project_ids,
261+
group_ids,
262+
environment_ids,
263+
start=None,
264+
end=None,
265+
tenant_ids=None,
266+
referrer=None,
260267
):
261268
"""
262269
>>> get_groups_user_counts([1, 2], [2, 3], [4, 5])

src/sentry/tagstore/snuba/backend.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from sentry.search.events.fields import FIELD_ALIASES
3434
from sentry.search.events.filter import _flip_field_sort
3535
from sentry.snuba.dataset import Dataset
36+
from sentry.snuba.referrer import Referrer
3637
from sentry.tagstore.base import TOP_VALUES_DEFAULT_LIMIT, TagKeyStatus, TagStorage
3738
from sentry.tagstore.exceptions import (
3839
GroupTagKeyNotFound,
@@ -861,7 +862,7 @@ def __get_groups_user_counts(
861862
end=None,
862863
dataset=Dataset.Events,
863864
extra_aggregations=None,
864-
referrer="tagstore.__get_groups_user_counts",
865+
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS.value,
865866
tenant_ids=None,
866867
):
867868
filters = {"project_id": project_ids, "group_id": group_ids}
@@ -888,7 +889,14 @@ def __get_groups_user_counts(
888889
return defaultdict(int, {k: v for k, v in result.items() if v})
889890

890891
def get_groups_user_counts(
891-
self, project_ids, group_ids, environment_ids, start=None, end=None, tenant_ids=None
892+
self,
893+
project_ids,
894+
group_ids,
895+
environment_ids,
896+
start=None,
897+
end=None,
898+
tenant_ids=None,
899+
referrer="tagstore.get_groups_user_counts",
892900
):
893901
return self.__get_groups_user_counts(
894902
project_ids,
@@ -898,7 +906,7 @@ def get_groups_user_counts(
898906
end,
899907
Dataset.Events,
900908
[],
901-
"tagstore.get_groups_user_counts",
909+
referrer,
902910
tenant_ids=tenant_ids,
903911
)
904912

src/sentry/tasks/integrations/github/open_pr_comment.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ def get_issue_table_contents(issue_list: list[dict[str, Any]]) -> list[PullReque
149149
title=issue.title,
150150
subtitle=issue.culprit,
151151
url=issue.get_absolute_url(),
152-
affected_users=issue.count_users_seen(),
152+
affected_users=issue.count_users_seen(
153+
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_OPEN_PR_COMMENT.value
154+
),
153155
event_count=group_id_to_info[issue.id]["event_count"],
154156
function_name=group_id_to_info[issue.id]["function_name"],
155157
)

0 commit comments

Comments
 (0)