Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/sentry/integrations/github/webhook_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

class GithubWebhookType(StrEnum):
INSTALLATION = "installation"
INSTALLATION_REPOSITORIES = "installation_repositories"
ISSUE = "issues"
ISSUE_COMMENT = "issue_comment"
PULL_REQUEST = "pull_request"
PULL_REQUEST_REVIEW_COMMENT = "pull_request_review_comment"
PULL_REQUEST_REVIEW = "pull_request_review"
PUSH = "push"
15 changes: 5 additions & 10 deletions src/sentry/middleware/integrations/parsers/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,13 @@ def get_response(self) -> HttpResponseBase:
if codecov_regions:
self.try_forward_to_codecov(event=event)

logger.info(
"overwatch.debug.forward_if_applicable.begin",
extra={
"headers_keys": list(self.request.headers.keys()),
"integration_id": integration.id,
},
response = self.get_response_from_webhookpayload(
regions=regions, identifier=integration.id, integration_id=integration.id
)

# The overwatch forwarder implements its own region-based checks
OverwatchGithubWebhookForwarder(integration=integration).forward_if_applicable(
event=event, headers=self.request.headers
event=event, headers=self.request.META
)

return self.get_response_from_webhookpayload(
regions=regions, identifier=integration.id, integration_id=integration.id
)
return response
26 changes: 8 additions & 18 deletions src/sentry/overwatch_webhooks/webhook_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from sentry import options
from sentry.constants import ObjectStatus
from sentry.integrations.github.webhook_types import GITHUB_WEBHOOK_TYPE_HEADER, GithubWebhookType
from sentry.integrations.models.integration import Integration
from sentry.integrations.models.organization_integration import OrganizationIntegration
from sentry.models.organizationmapping import OrganizationMapping
Expand All @@ -16,12 +17,12 @@

# TODO: Double check that this includes all of the events you care about.
GITHUB_EVENTS_TO_FORWARD_OVERWATCH = {
"installation",
"installation_repositories",
"issue_comment",
"pull_request",
"pull_request_review_comment",
"pull_request_review",
GithubWebhookType.INSTALLATION,
GithubWebhookType.INSTALLATION_REPOSITORIES,
GithubWebhookType.ISSUE_COMMENT,
GithubWebhookType.PULL_REQUEST,
GithubWebhookType.PULL_REQUEST_REVIEW_COMMENT,
GithubWebhookType.PULL_REQUEST_REVIEW,
}


Expand All @@ -45,7 +46,7 @@ def __init__(self, integration: Integration):
self.integration = integration

def should_forward_to_overwatch(self, headers: Mapping[str, str]) -> bool:
return headers.get("HTTP_X_GITHUB_EVENT") in GITHUB_EVENTS_TO_FORWARD_OVERWATCH
return headers.get(GITHUB_WEBHOOK_TYPE_HEADER) in GITHUB_EVENTS_TO_FORWARD_OVERWATCH

def _get_org_summaries_by_region_for_integration(
self, integration: Integration
Expand Down Expand Up @@ -108,12 +109,8 @@ def forward_if_applicable(self, event: Mapping[str, Any], headers: Mapping[str,
region_name = None
try:
enabled_regions = options.get("overwatch.enabled-regions")
logger.info(
"overwatch.debug.enabled_regions", extra={"enabled_regions": enabled_regions}
)
if not enabled_regions:
# feature isn't enabled, no work to do
logger.info("overwatch.debug.excluded.feature_not_enabled", extra={})
return

orgs_by_region = self._get_org_summaries_by_region_for_integration(
Expand Down Expand Up @@ -177,10 +174,6 @@ def forward_if_applicable(self, event: Mapping[str, Any], headers: Mapping[str,
region=region_name,
app_id=app_id,
)
logger.info(
"overwatch.debug.webhook_detail.created",
extra={"region_name": region_name, "app_id": app_id},
)

publisher = OverwatchWebhookPublisher(
integration_provider=self.integration.provider,
Expand All @@ -193,9 +186,6 @@ def forward_if_applicable(self, event: Mapping[str, Any], headers: Mapping[str,
sample_rate=1.0,
tags={"forward_region": region_name},
)
logger.info(
"overwatch.debug.metrics_incr.success", extra={"region_name": region_name}
)
except Exception:
metrics.incr(
"overwatch.forward-webhooks.forward-error",
Expand Down
Loading