Esempio n. 1
0
    def get(self, request: Request, project, version) -> Response:
        """
        List issues to be resolved in a particular release
        ``````````````````````````````````````````````````

        Retrieve a list of issues to be resolved in a given release.

        :pparam string organization_slug: the slug of the organization the
                                          release belongs to.
        :pparam string project_slug: the slug of the project associated with the release.
        :pparam string version: the version identifier of the release.
        :auth: required
        """
        group_ids = get_group_ids_resolved_in_release(project.organization,
                                                      version)
        groups = Group.objects.filter(project=project, id__in=group_ids)

        context = serialize(
            list(groups),
            request.user,
            GroupSerializer(environment_func=self._get_environment_func(
                request, project.organization_id)),
        )

        return Response(context)
Esempio n. 2
0
    def get(self, request, organization):
        with sentry_sdk.start_span(op="discover.endpoint", description="filter_params") as span:
            span.set_data("organization", organization)
            try:
                params = self.get_filter_params(request, organization)
            except NoProjects:
                return Response([])

            possible_keys = ["transaction"]
            lookup_keys = {key: request.query_params.get(key) for key in possible_keys}

            if not any(lookup_keys.values()):
                return Response(
                    {
                        "detail": "Must provide one of {} in order to find related events".format(
                            possible_keys
                        )
                    },
                    status=400,
                )

        try:
            with sentry_sdk.start_span(op="discover.endpoint", description="filter_creation"):
                projects = self.get_projects(request, organization)
                query_kwargs = build_query_params_from_request(
                    request, organization, projects, params.get("environment")
                )
                query_kwargs["limit"] = 5
                try:
                    # Need to escape quotes in case some "joker" has a transaction with quotes
                    transaction_name = UNESCAPED_QUOTE_RE.sub('\\"', lookup_keys["transaction"])
                    parsed_terms = parse_search_query('transaction:"{}"'.format(transaction_name))
                except ParseError:
                    return Response({"detail": "Invalid transaction search"}, status=400)

                if query_kwargs.get("search_filters"):
                    query_kwargs["search_filters"].extend(parsed_terms)
                else:
                    query_kwargs["search_filters"] = parsed_terms

            with sentry_sdk.start_span(op="discover.endpoint", description="issue_search"):
                results = search.query(**query_kwargs)
        except discover.InvalidSearchQuery as err:
            raise ParseError(detail=six.text_type(err))

        with sentry_sdk.start_span(op="discover.endpoint", description="serialize_results") as span:
            results = list(results)
            span.set_data("result_length", len(results))
            context = serialize(
                results,
                request.user,
                GroupSerializer(
                    environment_func=self._get_environment_func(request, organization.id)
                ),
            )

        return Response(context)
Esempio n. 3
0
    def get(self, request, organization):
        try:
            # events-meta is still used by events v1 which doesn't require global views
            params = self.get_snuba_params(request, organization, check_global_views=False)
        except NoProjects:
            return Response([])

        with sentry_sdk.start_span(op="discover.endpoint", description="find_lookup_keys") as span:
            possible_keys = ["transaction"]
            lookup_keys = {key: request.query_params.get(key) for key in possible_keys}

            if not any(lookup_keys.values()):
                return Response(
                    {
                        "detail": f"Must provide one of {possible_keys} in order to find related events"
                    },
                    status=400,
                )

        with self.handle_query_errors():
            with sentry_sdk.start_span(op="discover.endpoint", description="filter_creation"):
                projects = self.get_projects(request, organization)
                query_kwargs = build_query_params_from_request(
                    request, organization, projects, params.get("environment")
                )
                query_kwargs["limit"] = 5
                try:
                    # Need to escape quotes in case some "joker" has a transaction with quotes
                    transaction_name = UNESCAPED_QUOTE_RE.sub('\\"', lookup_keys["transaction"])
                    parsed_terms = parse_search_query(f'transaction:"{transaction_name}"')
                except ParseError:
                    return Response({"detail": "Invalid transaction search"}, status=400)

                if query_kwargs.get("search_filters"):
                    query_kwargs["search_filters"].extend(parsed_terms)
                else:
                    query_kwargs["search_filters"] = parsed_terms

            with sentry_sdk.start_span(op="discover.endpoint", description="issue_search"):
                results = search.query(**query_kwargs)

        with sentry_sdk.start_span(op="discover.endpoint", description="serialize_results") as span:
            results = list(results)
            span.set_data("result_length", len(results))
            context = serialize(
                results,
                request.user,
                GroupSerializer(
                    environment_func=self._get_environment_func(request, organization.id)
                ),
            )

        return Response(context)
Esempio n. 4
0
    def get(self, request, project, version):
        """
        List issues to be resolved in a particular release
        ``````````````````````````````````````````````````

        Retrieve a list of issues to be resolved in a given release.

        :pparam string organization_slug: the slug of the organization the
                                          release belongs to.
        :pparam string project_slug: the slug of the project associated with the release.
        :pparam string version: the version identifier of the release.
        :auth: required
        """
        try:
            release = Release.objects.get(version=version,
                                          organization=project.organization)
        except Release.DoesNotExist:
            raise ResourceDoesNotExist

        group_ids = set()
        group_ids |= set(
            GroupResolution.objects.filter(release=release, ).values_list(
                'group_id', flat=True))
        group_ids |= set(
            GroupLink.objects.filter(
                linked_type=GroupLink.LinkedType.commit,
                linked_id__in=ReleaseCommit.objects.filter(
                    release=release, ).values_list(
                        'commit_id',
                        flat=True,
                    )).values_list(
                        'group_id',
                        flat=True,
                    ))

        groups = Group.objects.filter(project=project, id__in=group_ids)

        context = serialize(
            list(groups), request.user,
            GroupSerializer(environment_func=self._get_environment_func(
                request, project.organization_id)))

        return Response(context)
Esempio n. 5
0
    def get(self, request, organization):
        email = request.GET.get("email")

        if email is None:
            return Response(status=400)

        limit = int(request.GET.get("limit", 100))

        # limit to only teams user has opted into
        project_ids = list(
            Project.objects.filter(
                teams__in=OrganizationMemberTeam.objects.filter(
                    organizationmember__user=request.user,
                    organizationmember__organization=organization,
                    is_active=True,
                ).values("team")
            ).values_list("id", flat=True)[:1000]
        )

        event_users = list(EventUser.objects.filter(email=email, project_id__in=project_ids)[:1000])

        if event_users:
            groups = Group.objects.filter(
                id__in=tagstore.get_group_ids_for_users(
                    project_ids=list(set([e.project_id for e in event_users])),
                    event_users=event_users,
                    limit=limit,
                )
            ).order_by("-last_seen")[:limit]
        else:
            groups = []

        context = serialize(
            list(groups),
            request.user,
            GroupSerializer(environment_func=self._get_environment_func(request, organization.id)),
        )

        return Response(context)
Esempio n. 6
0
    def get(self, request, organization):
        email = request.GET.get('email')

        if email is None:
            return Response(status=400)

        limit = request.GET.get('limit', 100)

        # limit to only teams user has opted into
        project_ids = list(
            Project.objects.filter(
                team__in=OrganizationMemberTeam.objects.filter(
                    organizationmember__user=request.user,
                    organizationmember__organization=organization,
                    is_active=True,
                ).values('team'),
            ).values_list('id', flat=True)[:1000]
        )

        event_users = EventUser.objects.filter(
            email=email,
            project_id__in=project_ids,
        )[:1000]

        project_ids = list(set([e.project_id for e in event_users]))

        group_ids = tagstore.get_group_ids_for_users(project_ids, event_users, limit=limit)

        groups = Group.objects.filter(
            id__in=group_ids,
        ).order_by('-last_seen')[:limit]

        context = serialize(list(groups), request.user, GroupSerializer(
            environment_id_func=self._get_environment_id_func(
                request, organization.id)
        ))

        return Response(context)