|
8 | 8 | from django.http import HttpRequest, HttpResponse |
9 | 9 | from django.http.response import HttpResponseBase |
10 | 10 |
|
| 11 | +import sentry.options as options |
11 | 12 | from sentry.hybridcloud.outbox.category import WebhookProviderIdentifier |
12 | 13 | from sentry.integrations.github.webhook import ( |
13 | 14 | GitHubIntegrationsWebhookEndpoint, |
14 | 15 | get_github_external_id, |
15 | 16 | ) |
16 | 17 | from sentry.integrations.github.webhook_types import ( |
17 | 18 | GITHUB_WEBHOOK_TYPE_HEADER, |
| 19 | + REGION_PROCESSED_GITHUB_EVENTS, |
18 | 20 | GithubWebhookType, |
19 | 21 | ) |
20 | 22 | from sentry.integrations.middleware.hybrid_cloud.parser import BaseRequestParser |
21 | 23 | from sentry.integrations.models.integration import Integration |
22 | 24 | from sentry.integrations.services.integration.model import RpcIntegration |
23 | 25 | from sentry.integrations.types import IntegrationProviderSlug |
24 | 26 | from sentry.silo.base import control_silo_function |
| 27 | +from sentry.utils import metrics |
25 | 28 |
|
26 | 29 | logger = logging.getLogger(__name__) |
27 | 30 |
|
@@ -115,6 +118,22 @@ def get_response(self) -> HttpResponseBase: |
115 | 118 | if len(regions) == 0: |
116 | 119 | return self.get_default_missing_integration_response() |
117 | 120 |
|
| 121 | + github_event = self.request.META.get(GITHUB_WEBHOOK_TYPE_HEADER) |
| 122 | + |
| 123 | + # Only drop when we have a known unprocessed event type. Missing or empty |
| 124 | + # X-GitHub-Event is malformed; let the request be forwarded so the region |
| 125 | + # returns 400 and GitHub is notified of the delivery failure. |
| 126 | + if ( |
| 127 | + github_event |
| 128 | + and github_event not in REGION_PROCESSED_GITHUB_EVENTS |
| 129 | + and options.get("github.webhook.drop-unprocessed-events.enabled") |
| 130 | + ): |
| 131 | + metrics.incr( |
| 132 | + "github.webhook.drop_unprocessed_event", |
| 133 | + tags={"event_type": github_event or "unknown"}, |
| 134 | + ) |
| 135 | + return HttpResponse(status=202) |
| 136 | + |
118 | 137 | response = self.get_response_from_webhookpayload( |
119 | 138 | regions=regions, |
120 | 139 | identifier=self.get_mailbox_identifier(integration, event), |
|
0 commit comments