Просмотр исходного кода

ref: Remove legacy events behavior (#13939)

Removes the "snuba.events-queries.enabled" option and legacy events
code. We no longer need this switch since running Sentry / master
without Snuba is no longer an option.
Lyn Nagara 5 лет назад
Родитель
Сommit
23b61d0703

+ 1 - 9
src/sentry/api/endpoints/event_apple_crash_report.py

@@ -9,7 +9,6 @@ try:
 except ImportError:
     from django.http import HttpResponse, StreamingHttpResponse
 
-from sentry import options
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.exceptions import ResourceDoesNotExist
 from sentry.models import Event, SnubaEvent
@@ -25,16 +24,9 @@ class EventAppleCrashReportEndpoint(ProjectEndpoint):
         `````````````````````````````````````````````
 
         This endpoint returns the an apple crash report for a specific event.
-        The event ID is either the event as it appears in the Sentry database
-        or the event ID that is reported by the client upon submission.
         This works only if the event.platform == cocoa
         """
-
-        use_snuba = options.get('snuba.events-queries.enabled')
-
-        event_cls = event_cls = SnubaEvent if use_snuba else Event
-
-        event = event_cls.objects.from_event_id(event_id, project_id=project.id)
+        event = SnubaEvent.objects.from_event_id(event_id, project_id=project.id)
         if event is None:
             raise ResourceDoesNotExist
 

+ 3 - 7
src/sentry/api/endpoints/event_attachment_details.py

@@ -8,12 +8,12 @@ try:
 except ImportError:
     from django.http import StreamingHttpResponse
 
-from sentry import features, options, roles
+from sentry import features, roles
 from sentry.api.bases.project import ProjectEndpoint, ProjectPermission
 from sentry.api.serializers.models.organization import ATTACHMENTS_ROLE_DEFAULT
 from sentry.auth.superuser import is_active_superuser
 from sentry.auth.system import is_system_auth
-from sentry.models import Event, SnubaEvent, EventAttachment, OrganizationMember
+from sentry.models import SnubaEvent, EventAttachment, OrganizationMember
 
 
 class EventAttachmentDetailsPermission(ProjectPermission):
@@ -80,11 +80,7 @@ class EventAttachmentDetailsEndpoint(ProjectEndpoint):
                             project.organization, actor=request.user):
             return self.respond(status=404)
 
-        use_snuba = options.get('snuba.events-queries.enabled')
-
-        event_cls = event_cls = SnubaEvent if use_snuba else Event
-
-        event = event_cls.objects.from_event_id(event_id, project.id)
+        event = SnubaEvent.objects.from_event_id(event_id, project.id)
         if event is None:
             return self.respond({'detail': 'Event not found'}, status=404)
 

+ 3 - 7
src/sentry/api/endpoints/event_attachments.py

@@ -1,10 +1,10 @@
 from __future__ import absolute_import
 
-from sentry import features, options
+from sentry import features
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.paginator import OffsetPaginator
 from sentry.api.serializers import serialize
-from sentry.models import Event, SnubaEvent, EventAttachment
+from sentry.models import SnubaEvent, EventAttachment
 
 
 class EventAttachmentsEndpoint(ProjectEndpoint):
@@ -24,11 +24,7 @@ class EventAttachmentsEndpoint(ProjectEndpoint):
                             project.organization, actor=request.user):
             return self.respond(status=404)
 
-        use_snuba = options.get('snuba.events-queries.enabled')
-
-        event_cls = event_cls = SnubaEvent if use_snuba else Event
-
-        event = event_cls.objects.from_event_id(event_id, project.id)
+        event = SnubaEvent.objects.from_event_id(event_id, project.id)
         if event is None:
             return self.respond({'detail': 'Event not found'}, status=404)
 

+ 1 - 7
src/sentry/api/endpoints/event_file_committers.py

@@ -2,7 +2,6 @@ from __future__ import absolute_import
 
 from rest_framework.response import Response
 
-from sentry import options
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.models import Commit, Event, SnubaEvent, Release
 from sentry.utils.committers import get_serialized_event_file_committers
@@ -22,12 +21,7 @@ class EventFileCommittersEndpoint(ProjectEndpoint):
                                  retrieve (as reported by the raven client).
         :auth: required
         """
-
-        use_snuba = options.get('snuba.events-queries.enabled')
-
-        event_cls = event_cls = SnubaEvent if use_snuba else Event
-
-        event = event_cls.objects.from_event_id(event_id, project.id)
+        event = SnubaEvent.objects.from_event_id(event_id, project.id)
         if event is None:
             return Response({'detail': 'Event not found'}, status=404)
 

+ 1 - 7
src/sentry/api/endpoints/event_grouping_info.py

@@ -4,7 +4,6 @@ import six
 
 from django.http import HttpResponse
 
-from sentry import options
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.exceptions import ResourceDoesNotExist
 from sentry.grouping.api import GroupingConfigNotFound
@@ -21,12 +20,7 @@ class EventGroupingInfoEndpoint(ProjectEndpoint):
         This endpoint returns a JSON dump of the metadata that went into the
         grouping algorithm.
         """
-
-        use_snuba = options.get('snuba.events-queries.enabled')
-
-        event_cls = event_cls = SnubaEvent if use_snuba else Event
-
-        event = event_cls.objects.from_event_id(event_id, project_id=project.id)
+        event = SnubaEvent.objects.from_event_id(event_id, project_id=project.id)
         if event is None:
             raise ResourceDoesNotExist
 

+ 1 - 7
src/sentry/api/endpoints/event_owners.py

@@ -2,7 +2,6 @@ from __future__ import absolute_import
 
 from rest_framework.response import Response
 
-from sentry import options
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.fields.actor import Actor
 from sentry.api.serializers import serialize
@@ -21,12 +20,7 @@ class EventOwnersEndpoint(ProjectEndpoint):
         :pparam string event_id: the id of the event.
         :auth: required
         """
-
-        use_snuba = options.get('snuba.events-queries.enabled')
-
-        event_cls = SnubaEvent if use_snuba else Event
-
-        event = event_cls.objects.from_event_id(event_id, project.id)
+        event = SnubaEvent.objects.from_event_id(event_id, project.id)
         if event is None:
             return Response({'detail': 'Event not found'}, status=404)
 

+ 4 - 69
src/sentry/api/endpoints/group_events.py

@@ -3,13 +3,12 @@ from __future__ import absolute_import
 import six
 
 from datetime import timedelta
-from django.db.models import Q
 from django.utils import timezone
 from rest_framework.response import Response
 from functools import partial
 
 
-from sentry import features, options, quotas, tagstore
+from sentry import features
 from sentry.api.base import DocSection, EnvironmentMixin
 from sentry.api.bases import GroupEndpoint
 from sentry.api.event_search import get_snuba_query_args
@@ -17,15 +16,14 @@ from sentry.api.exceptions import ResourceDoesNotExist
 from sentry.api.helpers.environments import get_environments
 from sentry.api.helpers.events import get_direct_hit_response
 from sentry.api.serializers import EventSerializer, serialize, SimpleEventSerializer
-from sentry.api.paginator import DateTimePaginator, GenericOffsetPaginator
+from sentry.api.paginator import GenericOffsetPaginator
 from sentry.api.utils import get_date_range_from_params
-from sentry.models import Event, Group, SnubaEvent
+from sentry.models import Group, SnubaEvent
 from sentry.search.utils import (
     InvalidQuery,
     parse_query,
 )
 from sentry.utils.apidocs import scenario, attach_scenarios
-from sentry.utils.validators import normalize_event_id
 from sentry.utils.snuba import raw_query
 
 
@@ -70,16 +68,10 @@ class GroupEventsEndpoint(GroupEndpoint, EnvironmentMixin):
         except (NoResults, ResourceDoesNotExist):
             return Response([])
 
-        use_snuba = (
-            request.GET.get('enable_snuba') == '1'
-            or options.get('snuba.events-queries.enabled')
-        )
-
-        backend = self._get_events_snuba if use_snuba else self._get_events_legacy
         start, end = get_date_range_from_params(request.GET, optional=True)
 
         try:
-            return backend(request, group, environments, query, tags, start, end)
+            return self._get_events_snuba(request, group, environments, query, tags, start, end)
         except GroupEventsError as exc:
             return Response({'detail': six.text_type(exc)}, status=400)
 
@@ -132,63 +124,6 @@ class GroupEventsEndpoint(GroupEndpoint, EnvironmentMixin):
             paginator=GenericOffsetPaginator(data_fn=data_fn)
         )
 
-    def _get_events_legacy(
-        self,
-        request,
-        group,
-        environments,
-        query,
-        tags,
-        start,
-        end,
-    ):
-        events = Event.objects.filter(group_id=group.id)
-
-        if query:
-            q = Q(message__icontains=query)
-
-            event_id = normalize_event_id(query)
-            if event_id:
-                q |= Q(event_id__exact=event_id)
-
-            events = events.filter(q)
-
-        if tags:
-            event_filter = tagstore.get_group_event_filter(
-                group.project_id,
-                group.id,
-                [env.id for env in environments],
-                tags,
-                start,
-                end,
-            )
-
-            if not event_filter:
-                return Response([])
-
-            events = events.filter(**event_filter)
-
-        # Filter start/end here in case we didn't filter by tags at all
-        if start:
-            events = events.filter(datetime__gte=start)
-        if end:
-            events = events.filter(datetime__lte=end)
-
-        # filter out events which are beyond the retention period
-        retention = quotas.get_event_retention(organization=group.project.organization)
-        if retention:
-            events = events.filter(
-                datetime__gte=timezone.now() - timedelta(days=retention)
-            )
-
-        return self.paginate(
-            request=request,
-            queryset=events,
-            order_by='-datetime',
-            on_results=lambda x: serialize(x, request.user),
-            paginator_cls=DateTimePaginator,
-        )
-
     def _get_search_query_and_tags(self, request, group, environments=None):
         raw_query = request.GET.get('query')
 

+ 1 - 24
src/sentry/api/endpoints/project_event_details.py

@@ -3,11 +3,10 @@ from __future__ import absolute_import
 from datetime import datetime
 from rest_framework.response import Response
 
-from sentry import options
 from sentry.api.base import DocSection
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.serializers import DetailedEventSerializer, serialize
-from sentry.models import Event, SnubaEvent
+from sentry.models import SnubaEvent
 
 from sentry.utils.apidocs import scenario, attach_scenarios
 
@@ -42,11 +41,6 @@ class ProjectEventDetailsEndpoint(ProjectEndpoint):
         :auth: required
         """
 
-        use_snuba = options.get('snuba.events-queries.enabled')
-
-        if not use_snuba:
-            return self.get_legacy(request, project, event_id)
-
         snuba_event = SnubaEvent.objects.from_event_id(event_id, project.id)
 
         if snuba_event is None:
@@ -63,23 +57,6 @@ class ProjectEventDetailsEndpoint(ProjectEndpoint):
 
         return Response(data)
 
-    def get_legacy(self, request, project, event_id):
-        event = Event.objects.from_event_id(event_id, project.id)
-        if event is None:
-            return Response({'detail': 'Event not found'}, status=404)
-
-        Event.objects.bind_nodes([event], 'data')
-
-        data = serialize(event, request.user, DetailedEventSerializer())
-        next_event_id = event.next_event_id()
-        prev_event_id = event.prev_event_id()
-        # TODO this is inconsistent with the event_details API which uses the
-        # `id` instead of the `event_id`
-        data['nextEventID'] = next_event_id
-        data['previousEventID'] = prev_event_id
-
-        return Response(data)
-
 
 class EventJsonEndpoint(ProjectEndpoint):
 

+ 12 - 48
src/sentry/api/endpoints/project_events.py

@@ -4,7 +4,6 @@ from datetime import timedelta
 from django.utils import timezone
 from functools import partial
 
-from sentry import options
 from sentry.api.base import DocSection
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.serializers import EventSerializer, serialize, SimpleEventSerializer
@@ -22,37 +21,21 @@ def list_project_available_samples_scenario(runner):
 class ProjectEventsEndpoint(ProjectEndpoint):
     doc_section = DocSection.EVENTS
 
-    def _get_events_legacy(self, request, project):
-        from sentry import quotas
-        from sentry.api.paginator import DateTimePaginator
-        from sentry.models import Event
-
-        events = Event.objects.filter(
-            project_id=project.id,
-        )
-
-        query = request.GET.get('query')
-        if query:
-            events = events.filter(
-                message__icontains=query,
-            )
+    @attach_scenarios([list_project_available_samples_scenario])
+    def get(self, request, project):
+        """
+        List a Project's Events
+        ```````````````````````
 
-        # filter out events which are beyond the retention period
-        retention = quotas.get_event_retention(organization=project.organization)
-        if retention:
-            events = events.filter(
-                datetime__gte=timezone.now() - timedelta(days=retention)
-            )
+        Return a list of events bound to a project.
 
-        return self.paginate(
-            request=request,
-            queryset=events,
-            order_by='-datetime',
-            on_results=lambda x: serialize(x, request.user),
-            paginator_cls=DateTimePaginator,
-        )
+        Note: This endpoint is experimental and may be removed without notice.
 
-    def _get_events_snuba(self, request, project):
+        :pparam string organization_slug: the slug of the organization the
+                                          groups belong to.
+        :pparam string project_slug: the slug of the project the groups
+                                     belong to.
+        """
         from sentry.api.paginator import GenericOffsetPaginator
         from sentry.models import SnubaEvent
         from sentry.utils.snuba import raw_query
@@ -85,22 +68,3 @@ class ProjectEventsEndpoint(ProjectEndpoint):
                 [SnubaEvent(row) for row in results], request.user, serializer),
             paginator=GenericOffsetPaginator(data_fn=data_fn)
         )
-
-    @attach_scenarios([list_project_available_samples_scenario])
-    def get(self, request, project):
-        """
-        List a Project's Events
-        ```````````````````````
-
-        Return a list of events bound to a project.
-
-        Note: This endpoint is experimental and may be removed without notice.
-
-        :pparam string organization_slug: the slug of the organization the
-                                          groups belong to.
-        :pparam string project_slug: the slug of the project the groups
-                                     belong to.
-        """
-        use_snuba = options.get('snuba.events-queries.enabled')
-        backend = self._get_events_snuba if use_snuba else self._get_events_legacy
-        return backend(request, project)

+ 0 - 1
src/sentry/options/defaults.py

@@ -152,7 +152,6 @@ register('snuba.search.chunk-growth-rate', default=1.5)
 register('snuba.search.max-chunk-size', default=2000)
 register('snuba.search.max-total-chunk-time-seconds', default=30.0)
 register('snuba.search.hits-sample-size', default=100)
-register('snuba.events-queries.enabled', type=Bool, default=True)
 register('snuba.track-outcomes-sample-rate', default=0.0)
 
 # Kafka Publisher

Некоторые файлы не были показаны из-за большого количества измененных файлов