Skip to content
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

feat(issues): Add ability to query issues by hash #76701

Merged
merged 8 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
16 changes: 16 additions & 0 deletions src/sentry/api/endpoints/project_group_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from sentry.api.serializers.models.group_stream import StreamGroupSerializer
from sentry.models.environment import Environment
from sentry.models.group import QUERY_STATUS_LOOKUP, Group, GroupStatus
from sentry.models.grouphash import GroupHash
from sentry.search.events.constants import EQUALITY_OPERATORS
from sentry.signals import advanced_search
from sentry.types.ratelimit import RateLimit, RateLimitCategory
Expand Down Expand Up @@ -77,6 +78,7 @@ def get(self, request: Request, project) -> Response:
``"is:unresolved"`` is assumed.)
:qparam string environment: this restricts the issues to ones containing
events from this environment
:qparam list hash: hashes of groups to return, overrides every other query parameter, only returning list of groups found from hashes
roggenkemper marked this conversation as resolved.
Show resolved Hide resolved
:pparam string organization_id_or_slug: the id or slug of the organization the
issues belong to.
:pparam string project_id_or_slug: the id or slug of the project the issues
Expand All @@ -99,6 +101,20 @@ def get(self, request: Request, project) -> Response:
stats_period=stats_period,
)

hashes = request.GET.getlist("hash", [])
if hashes:
roggenkemper marked this conversation as resolved.
Show resolved Hide resolved
groups_from_hashes = GroupHash.objects.filter(hash__in=hashes).values_list(
"group_id", flat=True
)
groups = list(Group.objects.filter(id__in=groups_from_hashes, project_id=project.id))
roggenkemper marked this conversation as resolved.
Show resolved Hide resolved

serialized_groups = serialize(
groups,
request.user,
serializer(),
)
return Response(serialized_groups)

query = request.GET.get("query", "").strip()
if query:
matching_group = None
Expand Down
30 changes: 30 additions & 0 deletions tests/snuba/api/endpoints/test_project_group_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,36 @@ def test_filter_not_unresolved(self):
assert response.status_code == 200
assert [int(r["id"]) for r in response.data] == [event.group.id]

def test_group_by_hash(self):
roggenkemper marked this conversation as resolved.
Show resolved Hide resolved
event = self.store_event(
data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
project_id=self.project.id,
)

self.login_as(user=self.user)

response = self.client.get(f"{self.path}?hash={event.get_primary_hash()}")
assert response.status_code == 200
assert len(response.data) == 1
roggenkemper marked this conversation as resolved.
Show resolved Hide resolved

def test_groups_by_hashes(self):
event = self.store_event(
data={"timestamp": iso_format(before_now(seconds=500)), "fingerprint": ["group-1"]},
project_id=self.project.id,
)

event2 = self.store_event(
data={"timestamp": iso_format(before_now(seconds=400)), "fingerprint": ["group-2"]},
project_id=self.project.id,
)
self.login_as(user=self.user)

response = self.client.get(
f"{self.path}?hash={event.get_primary_hash()}&hash={event2.get_primary_hash()}"
)
assert response.status_code == 200
assert len(response.data) == 2


class GroupUpdateTest(APITestCase, SnubaTestCase):
def setUp(self):
Expand Down
Loading