Skip to content

perf(control): Drop unconsumed check_suite webhook actions at the parser - #121434

Merged
vaind merged 3 commits into
masterfrom
perf/drop-unconsumed-check-suite-webhooks
Aug 10, 2026
Merged

vaind merged 3 commits into
masterfrom
perf/drop-unconsumed-check-suite-webhooks

Conversation

@vaind

@vaind vaind commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

check_suite is the single highest-volume GitHub webhook we deliver to cells — ~13.6M/day, ahead of check_run at 12.1M/day and roughly 36% of all WebhookPayload rows written across every provider (37.7M/day). Unlike check_run, none of its actions were filtered in control.

Only completed has a consumer. Both consumer paths agree on this:

  • pr_metrics.handle_check_suite, the sole entry in CheckSuiteWebhook.WEBHOOK_EVENT_PROCESSORS, returns unless action == "completed"
  • pr_iteration_from_check_suite_listener on the SCM event stream does the same

So every requested and rerequested delivery was stored as a WebhookPayload, POSTed cross-silo, HMAC-verified, JSON-parsed, dispatched through the per-org handler loop, and republished to Kafka with its full body — then dropped on the floor.

Changes

Generalize the action filter. check_run has had one since #119829. This replaces the two loose check_run constants with CELL_PROCESSED_ACTIONS, where an event type declares which of its actions a cell consumes (consumed) and which actions GitHub documents for it (known, which bounds metric tag cardinality — the body is not signature-verified in control). check_suite is added with consumed={"completed"}.

Add the missing half of the funnel. github.webhook.forwarded_event counts what survives the filter, opposite the existing github.webhook.drop_unprocessed_event. Until now only drops were measured, so the forwarded share of each event type was invisible in Datadog.

On completed check events the counter carries has_own_repo_pr. check_run/check_suite payloads list PRs that merely share a head sha, including PRs based in other repositories; the cell's _prs_from_check_payload resolves only entries whose base.repo is this webhook's repo, so a payload matching none of them is a guaranteed no-op there. Both sides of that comparison are already in the payload, which makes the share measurable from control. That number sizes a further drop — check_run.completed is the largest remaining line at 12.1M/day and 110ms avg — that shouldn't be shipped on a guess.

Behavior

No functional change beyond the check_suite drop, and that drop is a strict no-op: it removes deliveries every consumer already discarded.

One second-order effect worth naming. GitHubWebhook.__call__ auto-creates missing Repository rows and calls update_repo_data() for any event carrying a repository key, independent of the processors. Dropped check_suite deliveries no longer trigger that. This is safe — push, pull_request, check_run.completed and issue_comment all still flow through the same path, and a push necessarily precedes any check suite — but it is the non-obvious part of the change.

Follow-up

Dropping check_run.completed deliveries that reference no pull request based in this repo. It is the largest remaining line — 12.1M/day at ~110ms average, roughly 370 CPU-hours/day in the cell handler alone — and the payload-only predicate is already implemented here as _references_own_repo_pull_request, currently used only to tag the counter.

Deliberately not in this PR. Unlike the check_suite filter, this one keys off payload shape rather than a header, so it needs its own review and an options kill switch — a wrong predicate loses events silently, and the existing drops have no escape hatch. It also needs a number that does not exist yet. Once this counter has run for a day:

sum:sentry.github.webhook.forwarded_event{event_type:check_run,action:completed} by {has_own_repo_pr}

The false share is what the drop would reclaim. check_suite.completed is measured by the same tag and would follow the same predicate.

Before narrowing further, re-check both consumer paths: WEBHOOK_EVENT_PROCESSORS on the endpoint, and the sentry.scm.stream listeners. check_run has only a stub listener on the stream today, but that can change.

Fixes CW-1838

check_suite is the highest-volume GitHub webhook we deliver (~13.6M/day, more than check_run), but its only consumers — pr_metrics' handle_check_suite and the SCM stream's pr_iteration listener — both return immediately unless the action is "completed". Every "requested" and "rerequested" delivery was still stored as a WebhookPayload, sent cross-silo, signature-verified, parsed, dispatched, and republished to Kafka before being discarded.

check_run has had this filter since #119829; generalize it into CELL_PROCESSED_ACTIONS so an event type declares which of its actions a cell actually consumes, and apply it to check_suite as well.

Also add github.webhook.forwarded_event, the counter for what survives the filter, to sit opposite the existing drop counter — until now only drops were measured, so the forwarded share of each event type was invisible. On completed check events it carries has_own_repo_pr, which reports whether the payload references a pull request based in this repo. Checks that reference none are a guaranteed no-op in the cell, so that tag sizes a further drop we cannot justify without the number.
@vaind
vaind requested review from a team as code owners August 6, 2026 12:02
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 6, 2026
@linear-code

linear-code Bot commented Aug 7, 2026

Copy link
Copy Markdown

INC-2429

vaind added 2 commits August 7, 2026 19:37
The local _as_mapping helper reimplemented what sentry.utils.safe.get_path
already does for untrusted nested data, and the base.repo.id lookup needed
three nested calls to stay safe against a malformed payload.
@vaind
vaind enabled auto-merge (squash) August 10, 2026 09:06
@vaind
vaind merged commit 675af0c into master Aug 10, 2026
67 checks passed
@vaind
vaind deleted the perf/drop-unconsumed-check-suite-webhooks branch August 10, 2026 09:14
vaind added a commit that referenced this pull request Aug 10, 2026
## Problem

The mailbox gauges from #121506 report the backlog per provider — who
sent the queued webhooks, not what they are. Sizing a parser-side drop
needs the latter.

#121434 dropped 13.6M unconsumed `check_suite` deliveries a day. The
follow-up it names — dropping `check_run.completed` payloads that
reference no pull request based in their own repo, the largest remaining
line at 12.1M/day — has an inflow number
(`github.webhook.forwarded_event`) and a latency number
(`delivery_time_ms{github_event_and_action}`), but nothing that says
what is actually *sitting* in the mailboxes. That is the
INC-2324/INC-2421 question, and today it is only answerable per
provider.

## Changes

`hybridcloud.webhookpayload.mailbox.pending_count` gains an `event_type`
tag.

GitHub mailboxes already carry the answer.
`GithubRequestParser.get_mailbox_identifier` appends the event type to
the mailbox name so deliveries of different types don't queue behind
each other (`GithubEnterpriseRequestParser` inherits it), and the
aggregate already groups by `mailbox_name`. So this is a re-key of rows
that are in memory either way — **no extra query, no change to the
statement-timeout envelope**.

Two things the derivation has to get right:

- A delivery that arrives with no `X-GitHub-Event` header mailboxes
*without* the suffix, leaving a bucket number where this reads. Tagging
that verbatim would put unbounded ints in a tag, so only names in
`CELL_PROCESSED_GITHUB_EVENTS` are trusted; anything else is `unknown`.
- `none` (provider doesn't mailbox by event type) is kept distinct from
`unknown` (it does, but this mailbox has none to read). Conflating them
would hide the header-less deliveries.

It reads the `provider` column rather than the mailbox prefix, so legacy
rows predating that column report `none` even when they are GitHub
mailboxes. Those are draining out, and deriving a provider two different
ways is worse than under-reporting them.

## Why only `pending_count`

Every emission is host-tagged by the Datadog backend, so each tag value
costs a series per worker that runs the task. Tagging all four gauges
would take this from `4 × 7 providers` to `4 × 25` combinations;
confining it to `pending_count` makes that `3 × 7 + 25`.

The other three read fine per provider:

- `max_depth` — GitHub mailboxes are per-event-type by construction, so
this is *already* one event type's mailbox. The tag would only name
which one, and `pending_count` names it.
- `active_count` — a routing/fan-out signal, not a composition one.
- `oldest_pending_age_seconds` — a single stalled event type does hide
inside the provider-wide age. That is an alerting concern for INC-2421
and a one-line addition if that work wants it; not worth paying for
speculatively.

Kept the full 9-event set rather than a hardcoded high-volume subset
with an `other` bucket. That would be cheaper, but the list would go
stale silently and hide the next `check_suite` — the exact thing this
exists to catch. The 9 are bounded and grow only when someone adds a
`GithubWebhookType`.

## Compatibility

Summing `pending_count` over `event_type` reproduces the provider-only
value, so anything built on the existing series keeps working. No
in-repo consumers reference these metric names.
vaind added a commit that referenced this pull request Aug 11, 2026
Trim the shared-module and resolver docstrings to the reasoning that is not
already evident from the code, and drop the restatement in
_prs_from_check_payload now that the rule has one home.

Also fixes an inverted clause inherited from #121434: the predicate drops on
False, so the hazard is a False for a payload a consumer would act on, not a
True for one it would ignore.
vaind added a commit that referenced this pull request Aug 11, 2026
…est in their own repo (#121719)

## Problem

`check_run.completed` and `check_suite.completed` are the two largest
remaining lines at the control parser — **11.8M and 9.9M/day**, the
former at ~110ms average, roughly 370 CPU-hours/day in the cell handler
alone — and about a third of each does no work when it lands.

GitHub lists a PR on a check whenever the two share a head sha, which
includes PRs based in *other* repositories. The cell's
`_prs_from_check_payload` resolves only entries whose `base.repo` is
this webhook's repo, so a payload carrying none of those resolves zero
PRs and writes nothing. Today every one of them is still stored as a
`WebhookPayload`, POSTed cross-silo, HMAC-verified, JSON-parsed,
dispatched through the per-org handler loop, and republished to Kafka
with its full body.

Both sides of that comparison are in the payload, so control can make
the call without the cell's database. The predicate is not an
approximation of the cell's filter — it is the same comparison:
`GitHubWebhook.__call__` looks the `Repository` row up by
`external_id=str(event["repository"]["id"])`, which is exactly what the
parser compares `base.repo.id` against.

Measured over a full 24h window:

| event | total/day | no own-repo PR | share |
| --- | --- | --- | --- |
| `check_run.completed` | 11.83M | 3.75M | 31.7% |
| `check_suite.completed` | 9.87M | 3.73M | 37.8% |

**~7.5M requests/day** combined (~8.5M rows after the 1.13× cell
fan-out), against a peak-hour backlog surplus of 110–140K rows/h.

## Changes

**The drop.** `ActionFilter` gains `own_repo_pr_actions` — the actions
where *every* cell-side consumer resolves PRs through the payload's own
repo. `references_own_repo_pull_request` was already implemented in
#121434 to tag the forwarded counter; it now decides.

For `check_run.completed` all three processors were re-checked:
`handle_preprod_check_run_event` returns unless `requested_action`, code
review's `handle_check_run_event` returns unless `rerequested`, and only
`pr_metrics_handle_check_run` reads `pull_requests`. The SCM stream's
`listen_for_check_run` is still a no-op stub.

**`check_suite.completed` has a second consumer** — Seer's
`pr_iteration_from_check_suite_listener`, via the SCM stream — so the
predicate rests on two filters there rather than one. Both resolve
through the shared `is_own_repo_pull_request` as of
#121724 (merged), which also fixed a foreign-base entry
shadowing the own-repo one. So `check_suite` takes exactly `check_run`'s
rule, with no carve-out, and the drop is a subset of both consumers'
no-op sets.

**The kill switch.** Unlike the existing parser drops, this one keys off
payload shape rather than a header, so it ships behind
`hybridcloud.webhookpayload.github_drop_checks_without_own_repo_pr`,
**default off**. As merged this is a strict no-op. One option covers
both event types.

**The signal that makes the switch usable.** A switch is only worth
having if a wrong predicate is detectable, and it was not:
`_write_activity_row` is a bare insert, so silently losing these events
would move no counter anywhere and GitHub — already 202'd — never
redelivers. `pr_metrics.check.activity_recorded` closes that gap. It
must stay **flat** when the option is enabled; any dip is the predicate
being wrong, visible within the hour instead of never.

`drop_unprocessed_event` also gains a `reason` tag
(`unprocessed_event_type` / `unconsumed_action` / `no_own_repo_pr`) so
the new drop is separable from the two existing ones. The metric is in
Datadog exclude-tags mode, so the tag indexes with no dashboard-side
config.

## Rollout

Enable the option, then watch two things together, per event type:

```
sum:sentry.github.webhook.drop_unprocessed_event{reason:no_own_repo_pr} by {event_type}.as_count()
sum:sentry.pr_metrics.check.activity_recorded{*} by {github_event}.as_count()
```

The first should climb toward ~3.75M/day for `check_run` and ~3.73M/day
for `check_suite` while the second does not move.
`forwarded_event{action:completed,has_own_repo_pr:false}` should fall to
zero for both over the same window — the tag and the drop now use the
same predicate, so there is no expected residual on either event type.

The option is a rollout control, not a permanent feature — it should be
removed once a week of flat activity volume confirms the predicate.

## Risk

Most of the reclaimed volume is not the subtle case. The cell's
`pr_metrics.check.foreign_pull_request` counter — one increment per
entry skipped for a non-matching `base.repo` — runs at 759K/day across
*both* check event types, counting entries rather than payloads, and
including payloads that also carried an own-repo entry and were
processed normally. So **at least ~79% of the drop is the empty
`pull_requests: []` case**: CI on a commit with no PR, where "the cell
does nothing" is `for ref in ()`, not an inference about repo identity.

One second-order effect, the same one #121434 called out
for `check_suite`: `GitHubWebhook.__call__` auto-creates missing
`Repository` rows and calls `update_repo_data()` for any event carrying
a `repository` key, independent of the processors, and dropped
deliveries no longer trigger that. Safe for the same reason — `push`,
`pull_request` and `issue_comment` all still flow through that path.

Minor observability change: code review's `record_webhook_received` /
`record_webhook_filtered(UNSUPPORTED_ACTION)` counters stop firing for
dropped `check_run.completed`. No behavior attached.

Fixes [CW-1838](https://linear.app/getsentry/issue/CW-1838)

This branch was successfully deployed

1 active deployment
Preview — 06ec5418 Deployed Aug 10, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants