Skip to content

chore(snuba): Pass referrer to get_groups_user_counts #69056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/sentry/integrations/slack/message_builder/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from sentry.services.hybrid_cloud.actor import ActorType, RpcActor
from sentry.services.hybrid_cloud.identity import RpcIdentity, identity_service
from sentry.services.hybrid_cloud.user.model import RpcUser
from sentry.snuba.referrer import Referrer
from sentry.types.group import SUBSTATUS_TO_STR
from sentry.types.integrations import ExternalProviders
from sentry.utils import json
Expand Down Expand Up @@ -101,7 +102,9 @@ def get_approx_start_time(group: Group):
# pull things out into their own functions
SUPPORTED_CONTEXT_DATA = {
"Events": lambda group: get_group_global_count(group),
"Users Affected": lambda group: group.count_users_seen(),
"Users Affected": lambda group: group.count_users_seen(
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_SLACK_ISSUE_NOTIFICATION.value
),
"State": lambda group: SUBSTATUS_TO_STR.get(group.substatus, "").replace("_", " ").title(),
"First Seen": lambda group: time_since(group.first_seen),
"Approx. Start Time": get_approx_start_time,
Expand Down
5 changes: 4 additions & 1 deletion src/sentry/issues/ignored.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from sentry.services.hybrid_cloud.user.serial import serialize_generic_user
from sentry.services.hybrid_cloud.user.service import user_service
from sentry.signals import issue_archived
from sentry.snuba.referrer import Referrer
from sentry.types.group import GroupSubStatus
from sentry.utils import metrics

Expand Down Expand Up @@ -111,7 +112,9 @@ def handle_ignored(
if ignore_count and not ignore_window:
state["times_seen"] = group.times_seen
if ignore_user_count and not ignore_user_window:
state["users_seen"] = group.count_users_seen()
state["users_seen"] = group.count_users_seen(
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_IGNORED.value
)
GroupSnooze.objects.create_or_update(
group=group,
values={
Expand Down
4 changes: 3 additions & 1 deletion src/sentry/models/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
from sentry.models.organization import Organization
from sentry.services.hybrid_cloud.actor import RpcActor
from sentry.snuba.dataset import Dataset
from sentry.snuba.referrer import Referrer
from sentry.types.activity import ActivityType
from sentry.types.group import (
IGNORED_SUBSTATUS_CHOICES,
Expand Down Expand Up @@ -872,13 +873,14 @@ def checksum(self):
def get_email_subject(self):
return f"{self.qualified_short_id} - {self.title}"

def count_users_seen(self):
def count_users_seen(self, referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS.value):
return tagstore.backend.get_groups_user_counts(
[self.project_id],
[self.id],
environment_ids=None,
start=self.first_seen,
tenant_ids={"organization_id": self.project.organization_id},
referrer=referrer,
)[self.id]

@classmethod
Expand Down
9 changes: 8 additions & 1 deletion src/sentry/models/groupsnooze.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
sane_repr,
)
from sentry.issues.constants import get_issue_tsdb_group_model, get_issue_tsdb_user_group_model
from sentry.snuba.referrer import Referrer
from sentry.utils import metrics
from sentry.utils.cache import cache

Expand Down Expand Up @@ -87,7 +88,13 @@ def is_valid(self, group=None, test_rates=False, use_pending_data=False):
if self.user_window:
if not self.test_user_rates():
return False
elif self.user_count <= group.count_users_seen() - self.state["users_seen"]:
elif (
self.user_count
<= group.count_users_seen(
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_GROUP_SNOOZE.value
)
- self.state["users_seen"]
):
return False
return True

Expand Down
8 changes: 8 additions & 0 deletions src/sentry/snuba/referrer.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,14 @@ class Referrer(Enum):
TAGSTORE_GET_GROUP_LIST_TAG_VALUE = "tagstore.get_group_list_tag_value"
TAGSTORE_GET_GROUP_TAG_VALUE_ITER = "tagstore.get_group_tag_value_iter"
TAGSTORE_GET_GROUPS_USER_COUNTS = "tagstore.get_groups_user_counts"
TAGSTORE_GET_GROUPS_USER_COUNTS_OPEN_PR_COMMENT = (
"tagstore.get_groups_user_counts.open_pr_comment"
)
TAGSTORE_GET_GROUPS_USER_COUNTS_GROUP_SNOOZE = "tagstore.get_groups_user_counts.groupsnooze"
TAGSTORE_GET_GROUPS_USER_COUNTS_IGNORED = "tagstore.get_groups_user_counts.ignored"
TAGSTORE_GET_GROUPS_USER_COUNTS_SLACK_ISSUE_NOTIFICATION = (
"tagstore.get_groups_user_counts.slack_issue_notification"
)
TAGSTORE_GET_GENERIC_GROUP_LIST_TAG_VALUE = "tagstore.get_generic_group_list_tag_value"
TAGSTORE_GET_GENERIC_GROUPS_USER_COUNTS = "tagstore.get_generic_groups_user_counts"
TAGSTORE_GET_RELEASE_TAGS = "tagstore.get_release_tags"
Expand Down
9 changes: 8 additions & 1 deletion src/sentry/tagstore/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,14 @@ def get_group_tag_value_qs(self, project_id, group_id, environment_id, key, valu
raise NotImplementedError

def get_groups_user_counts(
self, project_ids, group_ids, environment_ids, start=None, end=None, tenant_ids=None
self,
project_ids,
group_ids,
environment_ids,
start=None,
end=None,
tenant_ids=None,
referrer=None,
):
"""
>>> get_groups_user_counts([1, 2], [2, 3], [4, 5])
Expand Down
14 changes: 11 additions & 3 deletions src/sentry/tagstore/snuba/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from sentry.search.events.fields import FIELD_ALIASES
from sentry.search.events.filter import _flip_field_sort
from sentry.snuba.dataset import Dataset
from sentry.snuba.referrer import Referrer
from sentry.tagstore.base import TOP_VALUES_DEFAULT_LIMIT, TagKeyStatus, TagStorage
from sentry.tagstore.exceptions import (
GroupTagKeyNotFound,
Expand Down Expand Up @@ -861,7 +862,7 @@ def __get_groups_user_counts(
end=None,
dataset=Dataset.Events,
extra_aggregations=None,
referrer="tagstore.__get_groups_user_counts",
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS.value,
tenant_ids=None,
):
filters = {"project_id": project_ids, "group_id": group_ids}
Expand All @@ -888,7 +889,14 @@ def __get_groups_user_counts(
return defaultdict(int, {k: v for k, v in result.items() if v})

def get_groups_user_counts(
self, project_ids, group_ids, environment_ids, start=None, end=None, tenant_ids=None
self,
project_ids,
group_ids,
environment_ids,
start=None,
end=None,
tenant_ids=None,
referrer="tagstore.get_groups_user_counts",
):
return self.__get_groups_user_counts(
project_ids,
Expand All @@ -898,7 +906,7 @@ def get_groups_user_counts(
end,
Dataset.Events,
[],
"tagstore.get_groups_user_counts",
referrer,
tenant_ids=tenant_ids,
)

Expand Down
4 changes: 3 additions & 1 deletion src/sentry/tasks/integrations/github/open_pr_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ def get_issue_table_contents(issue_list: list[dict[str, Any]]) -> list[PullReque
title=issue.title,
subtitle=issue.culprit,
url=issue.get_absolute_url(),
affected_users=issue.count_users_seen(),
affected_users=issue.count_users_seen(
referrer=Referrer.TAGSTORE_GET_GROUPS_USER_COUNTS_OPEN_PR_COMMENT.value
),
event_count=group_id_to_info[issue.id]["event_count"],
function_name=group_id_to_info[issue.id]["function_name"],
)
Expand Down
Loading