-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(events-v2): Add an organization event details endpoint #13553
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4d88a44
feat(events-v2): Add an organization event details endpoint
lynnagara 4111f5d
fix referrer naming
lynnagara d0bafc8
remove unused file
lynnagara f3b31bd
remove invalid comment
lynnagara f0f7234
add some tests
lynnagara a18724f
fix event not found status
lynnagara aba444b
add projectSlug to responses
lynnagara d2b17b6
add test for passing an issue.id query
lynnagara c14e2e9
refactor
lynnagara f3628ba
refactor latest/oldest
lynnagara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
from __future__ import absolute_import | ||
|
||
from rest_framework.response import Response | ||
import six | ||
from enum import Enum | ||
|
||
from sentry.api.bases import OrganizationEventsEndpointBase, OrganizationEventsError, NoProjects | ||
from sentry import features | ||
from sentry.models import SnubaEvent | ||
from sentry.models.project import Project | ||
from sentry.api.serializers import serialize | ||
from sentry.utils.snuba import raw_query | ||
|
||
|
||
class EventOrdering(Enum): | ||
LATEST = 0 | ||
OLDEST = 1 | ||
|
||
|
||
class OrganizationEventDetailsEndpoint(OrganizationEventsEndpointBase): | ||
def get(self, request, organization, project_slug, event_id): | ||
if not features.has('organizations:events-v2', organization, actor=request.user): | ||
return Response(status=404) | ||
|
||
try: | ||
params = self.get_filter_params(request, organization) | ||
snuba_args = self.get_snuba_query_args_v2(request, organization, params) | ||
except OrganizationEventsError as exc: | ||
return Response({'detail': exc.message}, status=400) | ||
except NoProjects: | ||
return Response(status=404) | ||
|
||
try: | ||
project = Project.objects.get( | ||
slug=project_slug, | ||
organization_id=organization.id | ||
) | ||
except Project.DoesNotExist: | ||
return Response(status=404) | ||
|
||
# We return the requested event if we find a match regardless of whether | ||
# it occurred within the range specified | ||
event = SnubaEvent.objects.from_event_id(event_id, project.id) | ||
|
||
if event is None: | ||
return Response({'detail': 'Event not found'}, status=404) | ||
|
||
data = serialize(event) | ||
|
||
data['nextEventID'] = self.next_event_id(request, organization, snuba_args, event) | ||
data['previousEventID'] = self.prev_event_id(request, organization, snuba_args, event) | ||
data['projectSlug'] = project_slug | ||
|
||
return Response(data) | ||
|
||
|
||
class OrganizationEventsLatestOrOldest(OrganizationEventsEndpointBase): | ||
def get(self, latest_or_oldest, request, organization): | ||
if not features.has('organizations:events-v2', organization, actor=request.user): | ||
return Response(status=404) | ||
|
||
try: | ||
params = self.get_filter_params(request, organization) | ||
snuba_args = self.get_snuba_query_args_v2(request, organization, params) | ||
except OrganizationEventsError as exc: | ||
return Response({'detail': exc.message}, status=400) | ||
except NoProjects: | ||
return Response(status=404) | ||
|
||
if latest_or_oldest == EventOrdering.LATEST: | ||
orderby = ['-timestamp', '-event_id'] | ||
else: | ||
orderby = ['timestamp', 'event_id'] | ||
|
||
result = raw_query( | ||
start=snuba_args['start'], | ||
end=snuba_args['end'], | ||
selected_columns=SnubaEvent.selected_columns, | ||
conditions=snuba_args['conditions'], | ||
filter_keys=snuba_args['filter_keys'], | ||
orderby=orderby, | ||
limit=2, | ||
referrer='api.organization-event-details-latest-or-oldest', | ||
) | ||
|
||
if 'error' in result or len(result['data']) == 0: | ||
return Response({'detail': 'Event not found'}, status=404) | ||
|
||
try: | ||
project_id = result['data'][0]['project_id'] | ||
project_slug = Project.objects.get( | ||
organization=organization, id=project_id).slug | ||
except Project.DoesNotExist: | ||
project_slug = None | ||
|
||
data = serialize(SnubaEvent(result['data'][0])) | ||
data['previousEventID'] = None | ||
data['nextEventID'] = None | ||
data['projectSlug'] = project_slug | ||
|
||
if latest_or_oldest == EventOrdering.LATEST and len(result['data']) == 2: | ||
data['previousEventID'] = six.text_type(result['data'][1]['event_id']) | ||
|
||
if latest_or_oldest == EventOrdering.OLDEST and len(result['data']) == 2: | ||
data['nextEventID'] = six.text_type(result['data'][1]['event_id']) | ||
|
||
return Response(data) | ||
|
||
|
||
class OrganizationEventDetailsLatestEndpoint(OrganizationEventsLatestOrOldest): | ||
def get(self, request, organization): | ||
return super(OrganizationEventDetailsLatestEndpoint, self).get( | ||
EventOrdering.LATEST, request, organization) | ||
|
||
|
||
class OrganizationEventDetailsOldestEndpoint(OrganizationEventsLatestOrOldest): | ||
def get(self, request, organization): | ||
return super(OrganizationEventDetailsOldestEndpoint, self).get( | ||
EventOrdering.OLDEST, request, organization) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@markstory Is this the groupSlug value you were thinking about passing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this, or we could use a
/
instead of a:
. I was using:
in the frontendeventSlug
query parameter as it was a simple way to pack two values into a single query string argument making back/forward navigation simpler.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched this to a
/
in #13568There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to stick with the
:
./
implies a subresource to me and since we can't have an eventId without a projectSlug I think it might be a bit unexpected.