Skip to content

Commit c80a36b

Browse files
authored
fix(middleware): Integration Fetching Logic for Gitlab Parser (#70402)
1 parent f0c8737 commit c80a36b

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

src/sentry/middleware/integrations/parsers/gitlab.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from django.http.response import HttpResponseBase
88
from django.urls import resolve
99

10+
from sentry import options
1011
from sentry.integrations.gitlab.webhooks import GitlabWebhookEndpoint, GitlabWebhookMixin
1112
from sentry.integrations.utils.scope import clear_tags_and_context
1213
from sentry.middleware.integrations.parsers.base import BaseRequestParser
@@ -15,7 +16,7 @@
1516
from sentry.models.outbox import WebhookProviderIdentifier
1617
from sentry.services.hybrid_cloud.util import control_silo_function
1718
from sentry.types.integrations import EXTERNAL_PROVIDERS, ExternalProviders
18-
from sentry.utils import json
19+
from sentry.utils import json, metrics
1920

2021
logger = logging.getLogger(__name__)
2122

@@ -24,6 +25,7 @@ class GitlabRequestParser(BaseRequestParser, GitlabWebhookMixin):
2425
provider = EXTERNAL_PROVIDERS[ExternalProviders.GITLAB]
2526
webhook_identifier = WebhookProviderIdentifier.GITLAB
2627
_integration: Integration | None = None
28+
_METRIC_CONTROL_PATH_FAILURE_KEY = "integrations.gitlab.get_integration_from_request.failure"
2729

2830
def _resolve_external_id(self) -> tuple[str, str] | HttpResponseBase:
2931
clear_tags_and_context()
@@ -43,14 +45,15 @@ def get_integration_from_request(self) -> Integration | None:
4345
if not self.is_json_request():
4446
return None
4547
try:
46-
_view, _args, kwargs = resolve(self.request.path)
47-
# Non-webhook endpoints
48-
if "integration_id" in kwargs and "organization_slug" in kwargs:
49-
self._integration = Integration.objects.filter(
50-
id=kwargs["integration_id"],
51-
organization_slug=kwargs["organization_slug"],
52-
).first()
53-
return self._integration
48+
if not options.get("api.remove-non-webhook-control-path-gitlab-parser"):
49+
_view, _args, kwargs = resolve(self.request.path)
50+
# Non-webhook endpoints
51+
if "integration_id" in kwargs and "organization_slug" in kwargs:
52+
self._integration = Integration.objects.filter(
53+
id=kwargs["integration_id"],
54+
organization_slug=kwargs["organization_slug"],
55+
).first()
56+
return self._integration
5457

5558
# Webhook endpoints
5659
result = self._resolve_external_id()
@@ -60,8 +63,12 @@ def get_integration_from_request(self) -> Integration | None:
6063
external_id=external_id, provider=self.provider
6164
).first()
6265
return self._integration
63-
except Exception:
64-
pass
66+
except Exception as e:
67+
metrics.incr(
68+
self._METRIC_CONTROL_PATH_FAILURE_KEY,
69+
tags={"integration": self.provider, "error": str(e)},
70+
)
71+
logger.exception("Failed to get integration from request")
6572

6673
return None
6774

src/sentry/options/defaults.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@
320320
flags=FLAG_ALLOW_EMPTY | FLAG_PRIORITIZE_DISK | FLAG_AUTOMATOR_MODIFIABLE,
321321
)
322322

323+
register(
324+
"api.remove-non-webhook-control-path-gitlab-parser",
325+
type=Bool,
326+
default=False,
327+
flags=FLAG_MODIFIABLE_BOOL | FLAG_AUTOMATOR_MODIFIABLE,
328+
)
329+
323330
# Controls the rate of using the hashed value of User API tokens for lookups when logging in
324331
# and also updates tokens which are not hashed
325332
register(

0 commit comments

Comments
 (0)