def test_unknown_project(self): event = self.store_event( data={ "message": "oh no!", "timestamp": iso_format(before_now(seconds=1)) }, project_id=self.project.id, ) ref = discover.ReferenceEvent(self.organization, "nope:{}".format(event.event_id), []) with pytest.raises(InvalidSearchQuery): discover.create_reference_event_conditions(ref)
def test_geo_field(self): event = self.store_event( data={ "message": "oh no!", "transaction": "/issues/{issue_id}", "user": { "id": 1, "geo": { "country_code": "US", "region": "CA", "city": "San Francisco" }, }, "timestamp": iso_format(before_now(seconds=1)), }, project_id=self.project.id, ) slug = "{}:{}".format(self.project.slug, event.event_id) ref = discover.ReferenceEvent( self.organization, slug, ["geo.city", "geo.region", "geo.country_code"]) result = discover.create_reference_event_conditions(ref) assert result == [ ["geo.city", "=", "San Francisco"], ["geo.region", "=", "CA"], ["geo.country_code", "=", "US"], ]
def test_issue_field(self): event = self.store_event( data={ "message": "oh no!", "timestamp": iso_format(before_now(seconds=1)), "contexts": { "os": { "version": "10.14.6", "type": "os", "name": "Mac OS X" }, "browser": { "type": "browser", "name": "Firefox", "version": "69" }, "gpu": { "type": "gpu", "name": "nvidia 8600", "vendor": "nvidia" }, }, }, project_id=self.project.id, ) slug = "{}:{}".format(self.project.slug, event.event_id) ref = discover.ReferenceEvent(self.organization, slug, ["issue.id"]) result = discover.create_reference_event_conditions(ref) assert result == [["issue.id", "=", event.group_id]]
def test_no_fields(self): event = self.store_event( data={ "message": "oh no!", "transaction": "/issues/{issue_id}", "timestamp": iso_format(before_now(seconds=1)), }, project_id=self.project.id, ) slug = "{}:{}".format(self.project.slug, event.event_id) ref = discover.ReferenceEvent(self.organization, slug, []) result = discover.create_reference_event_conditions(ref) assert len(result) == 0
def test_stack_field(self): data = load_data("php") data["timestamp"] = iso_format(before_now(seconds=1)) event = self.store_event(data=data, project_id=self.project.id) slug = "{}:{}".format(self.project.slug, event.event_id) ref = discover.ReferenceEvent(self.organization, slug, ["stack.filename", "stack.function"]) result = discover.create_reference_event_conditions(ref) assert result == [ [ "stack.filename", "=", "/Users/example/Development/raven-php/bin/raven" ], ["stack.function", "=", "raven_cli_test"], ]
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(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, status=ProjectStatus.VISIBLE ) except Project.DoesNotExist: return Response(status=404) # Check access to the project as this endpoint doesn't use membership checks done # get_filter_params(). if not request.access.has_project_access(project): return Response(status=404) # We return the requested event if we find a match regardless of whether # it occurred within the range specified event = eventstore.get_event_by_id(project.id, event_id) if event is None: return Response({"detail": "Event not found"}, status=404) # Scope the pagination related event ids to the current event # This ensure that if a field list/groupby conditions were provided # that we constrain related events to the query + current event values event_slug = u"{}:{}".format(project.slug, event_id) fields = request.query_params.getlist("field") if fields: reference = ReferenceEvent(organization, event_slug, fields) snuba_args["conditions"].extend(create_reference_event_conditions(reference)) data = serialize(event) data["nextEventID"] = self.next_event_id(snuba_args, event) data["previousEventID"] = self.prev_event_id(snuba_args, event) data["oldestEventID"] = self.oldest_event_id(snuba_args, event) data["latestEventID"] = self.latest_event_id(snuba_args, event) data["projectSlug"] = project_slug return Response(data)
def test_tag_value(self): event = self.store_event( data={ "message": "oh no!", "timestamp": iso_format(before_now(seconds=1)), "tags": { "customer_id": 1, "color": "red" }, }, project_id=self.project.id, ) slug = "{}:{}".format(self.project.slug, event.event_id) ref = discover.ReferenceEvent(self.organization, slug, ["nope", "color", "customer_id"]) result = discover.create_reference_event_conditions(ref) assert result == [["color", "=", "red"], ["customer_id", "=", "1"]]
def test_error_field(self): data = load_data("php") data["timestamp"] = iso_format(before_now(seconds=1)) event = self.store_event(data=data, project_id=self.project.id) slug = "{}:{}".format(self.project.slug, event.event_id) ref = discover.ReferenceEvent( self.organization, slug, ["error.value", "error.type", "error.handled"]) result = discover.create_reference_event_conditions(ref) assert result == [ [ "error.value", "=", "This is a test exception sent from the Raven CLI." ], ["error.type", "=", "Exception"], ]
def get_snuba_query_args(self, request, organization, params): query = request.GET.get("query") try: filter = get_filter(query, params) except InvalidSearchQuery as exc: raise OrganizationEventsError(exc.message) snuba_args = { "start": filter.start, "end": filter.end, "conditions": filter.conditions, "filter_keys": filter.filter_keys, } sort = request.GET.getlist("sort") if sort: snuba_args["orderby"] = sort # Deprecated. `sort` should be used as it is supported by # more endpoints. orderby = request.GET.getlist("orderby") if orderby and "orderby" not in snuba_args: snuba_args["orderby"] = orderby if request.GET.get("rollup"): try: snuba_args["rollup"] = int(request.GET.get("rollup")) except ValueError: raise OrganizationEventsError("rollup must be an integer.") fields = request.GET.getlist("field")[:] if fields: try: snuba_args.update(resolve_field_list(fields, snuba_args)) except InvalidSearchQuery as exc: raise OrganizationEventsError(exc.message) reference_event_id = request.GET.get("referenceEvent") if reference_event_id: reference = ReferenceEvent(organization, reference_event_id, fields) snuba_args["conditions"].extend( create_reference_event_conditions(reference)) return snuba_args
def test_sdk_field(self): event = self.store_event( data={ "message": "oh no!", "transaction": "/issues/{issue_id}", "sdk": { "name": "sentry-python", "version": "5.0.12" }, "timestamp": iso_format(before_now(seconds=1)), }, project_id=self.project.id, ) slug = "{}:{}".format(self.project.slug, event.event_id) ref = discover.ReferenceEvent(self.organization, slug, ["sdk.version", "sdk.name"]) result = discover.create_reference_event_conditions(ref) assert result == [["sdk.version", "=", "5.0.12"], ["sdk.name", "=", "sentry-python"]]
def test_unknown_event_and_no_fields(self): slug = "{}:deadbeef".format(self.project.slug) ref = discover.ReferenceEvent(self.organization, slug, []) result = discover.create_reference_event_conditions(ref) assert len(result) == 0
def test_unknown_event(self): with pytest.raises(InvalidSearchQuery): slug = "{}:deadbeef".format(self.project.slug) ref = discover.ReferenceEvent(self.organization, slug, ["message"]) discover.create_reference_event_conditions(ref)
def test_bad_slug_format(self): ref = discover.ReferenceEvent(self.organization, "lol", ["title"]) with pytest.raises(InvalidSearchQuery): discover.create_reference_event_conditions(ref)