Browse Source

feat(issues): Remove coverage from stacktrace-link endpoint (#63368)

Scott Cooper 1 year ago
parent
commit
d84c84cc97

+ 0 - 27
src/sentry/api/endpoints/project_stacktrace_link.py

@@ -14,10 +14,8 @@ from sentry.api.api_publish_status import ApiPublishStatus
 from sentry.api.base import region_silo_endpoint
 from sentry.api.bases.project import ProjectEndpoint
 from sentry.api.serializers import IntegrationSerializer, serialize
-from sentry.api.utils import Timer
 from sentry.integrations import IntegrationFeatures
 from sentry.integrations.utils.code_mapping import get_sorted_code_mapping_configs
-from sentry.integrations.utils.codecov import codecov_enabled, fetch_codecov_data
 from sentry.integrations.utils.stacktrace_link import StacktraceLinkOutcome, get_stacktrace_config
 from sentry.models.project import Project
 from sentry.services.hybrid_cloud.integration import integration_service
@@ -138,7 +136,6 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint):
 
         attempted_url = None
         error = None
-        codecov_data = None
         serialized_config = None
 
         with configure_scope() as scope:
@@ -158,27 +155,6 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint):
                     # When no code mapping have been matched we have not attempted a URL
                     if result["current_config"]["outcome"].get("attemptedUrl"):
                         attempted_url = result["current_config"]["outcome"]["attemptedUrl"]
-
-                should_get_coverage = codecov_enabled(project.organization)
-                scope.set_tag("codecov.enabled", should_get_coverage)
-                if should_get_coverage:
-                    with Timer() as t:
-                        codecov_data = fetch_codecov_data(
-                            config={
-                                "repository": result["current_config"]["repository"],
-                                "config": serialized_config,
-                                "outcome": result["current_config"]["outcome"],
-                            }
-                        )
-                        analytics.record(
-                            "function_timer.timed",
-                            function_name="fetch_codecov_data",
-                            duration=t.duration,
-                            organization_id=project.organization_id,
-                            project_id=project.id,
-                            group_id=ctx.get("group_id"),
-                            frame_abs_path=ctx.get("abs_path"),
-                        )
             try:
                 set_tags(scope, result, serialized_integrations)
             except Exception:
@@ -197,13 +173,11 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint):
             )
             return Response(
                 {
-                    # TODO(scttcper): Remove error in success case
                     "error": error,
                     "config": serialized_config,
                     "sourceUrl": result["source_url"],
                     "attemptedUrl": attempted_url,
                     "integrations": serialized_integrations,
-                    "codecov": codecov_data,
                 }
             )
 
@@ -214,6 +188,5 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint):
                 "sourceUrl": None,
                 "attemptedUrl": attempted_url,
                 "integrations": serialized_integrations,
-                "codecov": codecov_data,
             }
         )

+ 0 - 131
tests/sentry/api/endpoints/test_project_stacktrace_link.py

@@ -1,11 +1,6 @@
-import logging
 from typing import Any, Mapping
 from unittest.mock import PropertyMock, patch
 
-import pytest
-import responses
-
-from sentry import options
 from sentry.integrations.example.integration import ExampleIntegration
 from sentry.models.integrations.integration import Integration
 from sentry.models.integrations.organization_integration import OrganizationIntegration
@@ -409,132 +404,6 @@ class ProjectStacktraceLinkTestMobile(BaseProjectStacktraceLink):
         assert response.data["sourceUrl"] == f"{example_base_url}/{file_path}"
 
 
-class ProjectStracktraceLinkTestCodecov(BaseProjectStacktraceLink):
-    def setUp(self):
-        BaseProjectStacktraceLink.setUp(self)
-        options.set("codecov.client-secret", "supersecrettoken")
-        self.code_mapping1 = self.create_code_mapping(
-            organization_integration=self.oi,
-            project=self.project,
-            repo=self.repo,
-            stack_root="",
-            source_root="",
-        )
-        self.filepath = "src/path/to/file.py"
-        self.organization.flags.codecov_access = True
-
-        self.expected_codecov_url = (
-            "https://app.codecov.io/gh/getsentry/sentry/commit/master/blob/src/path/to/file.py"
-        )
-        self.expected_line_coverage = [[1, 0], [3, 1], [4, 0]]
-        self.organization.save()
-
-    @pytest.fixture(autouse=True)
-    def inject_fixtures(self, caplog):
-        self._caplog = caplog
-
-    @patch.object(
-        ExampleIntegration,
-        "get_stacktrace_link",
-        return_value="https://github.com/repo/blob/a67ea84967ed1ec42844720d9daf77be36ff73b0/src/path/to/file.py",
-    )
-    @responses.activate
-    def test_codecov_line_coverage_success(self, mock_integration):
-        responses.add(
-            responses.GET,
-            "https://api.codecov.io/api/v2/example/getsentry/repos/sentry/file_report/src/path/to/file.py",
-            status=200,
-            json={
-                "line_coverage": self.expected_line_coverage,
-                "commit_file_url": self.expected_codecov_url,
-                "commit_sha": "a67ea84967ed1ec42844720d9daf77be36ff73b0",
-            },
-            content_type="application/json",
-        )
-
-        response = self.get_success_response(
-            self.organization.slug,
-            self.project.slug,
-            qs_params={
-                "file": self.filepath,
-                "absPath": "abs_path",
-                "module": "module",
-                "package": "package",
-                "commitId": "a67ea84967ed1ec42844720d9daf77be36ff73b0",
-            },
-        )
-
-        assert response.data["codecov"]["lineCoverage"] == self.expected_line_coverage
-        assert response.data["codecov"]["status"] == 200
-
-    @patch.object(
-        ExampleIntegration,
-        "get_stacktrace_link",
-        return_value="https://github.com/repo/blob/master/src/path/to/file.py",
-    )
-    @responses.activate
-    def test_codecov_line_coverage_with_branch_success(self, mock_integration):
-        responses.add(
-            responses.GET,
-            "https://api.codecov.io/api/v2/example/getsentry/repos/sentry/file_report/src/path/to/file.py",
-            status=200,
-            json={
-                "line_coverage": self.expected_line_coverage,
-                "commit_file_url": self.expected_codecov_url,
-                "commit_sha": "a67ea84967ed1ec42844720d9daf77be36ff73b0",
-            },
-            content_type="application/json",
-        )
-
-        response = self.get_success_response(
-            self.organization.slug,
-            self.project.slug,
-            qs_params={
-                "file": self.filepath,
-                "absPath": "abs_path",
-                "module": "module",
-                "package": "package",
-            },
-        )
-        assert response.data["codecov"]["lineCoverage"] == self.expected_line_coverage
-        assert response.data["codecov"]["status"] == 200
-
-    @patch.object(
-        ExampleIntegration,
-        "get_stacktrace_link",
-        return_value="https://github.com/repo/blob/a67ea84967ed1ec42844720d9daf77be36ff73b0/src/path/to/file.py",
-    )
-    @responses.activate
-    def test_codecov_line_coverage_exception(self, mock_integration):
-        self._caplog.set_level(logging.ERROR, logger="sentry")
-        responses.add(
-            responses.GET,
-            "https://api.codecov.io/api/v2/example/getsentry/repos/sentry/file_report/src/path/to/file.py",
-            status=500,
-            content_type="application/json",
-        )
-
-        self.get_success_response(
-            self.organization.slug,
-            self.project.slug,
-            qs_params={
-                "file": self.filepath,
-                "absPath": "abs_path",
-                "module": "module",
-                "package": "package",
-                "commitId": "a67ea84967ed1ec42844720d9daf77be36ff73b0",
-            },
-        )
-
-        assert self._caplog.record_tuples == [
-            (
-                "sentry.integrations.utils.codecov",
-                logging.ERROR,
-                "Codecov HTTP error: 500. Continuing execution.",
-            )
-        ]
-
-
 class ProjectStacktraceLinkTestMultipleMatches(BaseProjectStacktraceLink):
     def setUp(self):
         BaseProjectStacktraceLink.setUp(self)