Skip to content

fix(hybridcloud): Stop counting rejected webhooks as successful deliveries - #121606

Merged
vaind merged 1 commit into
masterfrom
fix/webhook-dropped-outcomes
Aug 10, 2026
Merged

vaind merged 1 commit into
masterfrom
fix/webhook-dropped-outcomes

Conversation

@vaind

@vaind vaind commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The problem

perform_cell_request handles a 409 conflict and a 400/401/403/404 by incrementing deliver_webhooks.failure and then returning normally instead of raising. Control falls back to deliver_message, which proceeds straight through payload.delete() → _record_delivery_time_metrics() → metrics.incr(outcome="ok"). The parallel drain does the same, since deliver_message_parallel returns a null error and _handle_parallel_delivery_result reads that as success.

So a webhook the cell refused is reported as delivered.

Measured over 24h in production, that is 379,521 payloads:

reason per day
conflict 213,606
unauthorized 162,729
bad_request 2,916
not_found 261
forbidden 9

About 1.5% of the 25.6M outcome:ok. Their latency is also folded into delivery_time_ms, biased low because a rejection returns faster than a real delivery. The only trace of them is the failure counter, which no dashboard widget plots — which is why this went unnoticed.

The change

Both paths now raise DeliveryDropped, distinct from the retryable DeliveryFailed, carrying the outcome tag. Callers delete the payload exactly as before, but record outcome:conflict or outcome:dropped_4xx instead of ok, and skip the delivery-time distribution.

Per-reason detail stays on failure{reason:*} rather than being duplicated onto outcome, keeping that tag low-cardinality.

deliver_message now returns whether the payload reached the cell, so the sequential drain's delivered counter stops including discards — the parallel drain already excluded them.

Not changed

What gets retried or deleted is identical. A drop is terminal rather than a failure, so ordering-sensitive providers continue past it just as they did when the 4xx fell through as success; there is a regression test for that.

After deploy

outcome:ok drops by ~1.5% and two new series appear on the Delivery Outcomes widget of the Hybrid Cloud Webhook Forwarding dashboard. delivery_time_ms percentiles may tick up slightly as the fast rejections stop being counted.

@vaind
vaind requested a review from a team as a code owner August 10, 2026 11:57
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Aug 10, 2026
…eries

`perform_cell_request` handles a 409 conflict and a 400/401/403/404 by
incrementing `deliver_webhooks.failure` and then returning normally rather than
raising. Control falls back to `deliver_message`, which deletes the payload,
records `delivery_time_ms` and increments `delivery{outcome:ok}` — so a webhook
the cell refused is reported as delivered. The parallel drain does the same, via
`deliver_message_parallel` returning a null error.

Measured over 24h that is 379,521 payloads: 213,606 conflict, 162,729
unauthorized, 2,916 bad_request, 261 not_found and 9 forbidden. About 1.5% of
the 25.6M `outcome:ok` never reached a cell, and their latency is folded into
`delivery_time_ms` — biased low, since a rejection returns faster than a real
delivery. The only trace of them is the `failure` counter, which no dashboard
widget plots.

Both paths now raise `DeliveryDropped`, distinct from the retryable
`DeliveryFailed`, carrying the outcome tag. Callers delete the payload as before
but record `outcome:conflict` or `outcome:dropped_4xx` instead of `ok`, and skip
the delivery-time distribution. Per-reason detail stays on the `failure` metric
rather than being duplicated onto `outcome`.

`deliver_message` now returns whether the payload reached the cell, so the
sequential drain's `delivered` counter stops including discards. The parallel
drain already excluded them.

No behaviour change to what is retried or deleted: a drop is terminal, so
ordering-sensitive providers continue past it exactly as they did when the 4xx
fell through as success.
@vaind
vaind force-pushed the fix/webhook-dropped-outcomes branch from a7ba690 to f12606a Compare August 10, 2026 12:11
@vaind
vaind requested a review from joseph-sentry August 10, 2026 13:38
@vaind
vaind merged commit 5c2da4a into master Aug 10, 2026
65 checks passed
@vaind
vaind deleted the fix/webhook-dropped-outcomes branch August 10, 2026 17:02
vaind added a commit that referenced this pull request Aug 10, 2026
### Why

The [Hybrid Cloud Webhook
Forwarding](https://app.datadoghq.com/dashboard/tqt-8cb-xmj/hybrid-cloud-webhook-forwarding)
dashboard has a `provider` template variable, but
`deliver_webhooks.{delivery,saved,failure}` carry no such tag — only the
`webhookpayload.mailbox.*` gauges do. Verified against Datadog:
`sum:...delivery{*} by {provider}` returns zero series.

So selecting a provider does not filter those widgets, it **blanks**
them, which reads as "no traffic" rather than "this metric cannot answer
that question".

It also makes per-provider delivery health answerable at all. The 401s
and 409s behind `failure` are ~376k/day between them and there is
currently no way to see which integration they belong to.

### Where provider comes from

From the payload column wherever a row is loaded. Two paths have no row:

- **the push trigger** — `maybe_trigger_drain` only receives a mailbox
name
- **the DoesNotExist race** — the row is already gone

Both read the first segment of the mailbox name. Mailboxes are
`<provider>:<identifier>`, and it is the *identifier* that later gains
bucket and event-type suffixes, so the first segment stays the provider.
The column is nullable and rows predating it still drain through, hence
the `unknown` fallback — matching what `record_mailbox_depth_metrics`
already does.

### Rebased onto #121606

That PR added two new `delivery` outcomes — `conflict` and `dropped_4xx`
— for payloads a cell permanently rejects. Both are tagged here too, so
every `delivery` emission carries `provider`; otherwise those two would
have been the only outcomes to vanish when a provider is selected, which
is the exact failure this PR exists to remove.

### Deliberately left untagged

Following the cardinality restraint in #121601 ("every tag value costs a
series per worker"):

- **`send_request` timer** — a timer is seven series, so this would be 7
× cells × providers, for a latency question `delivery_time_ms` already
answers.
- **`schedule_webhook_delivery.mailbox_count`** — aggregates across
every mailbox in a scheduler run, so there is no single provider to
attribute it to.

### Cost

`delivery` goes to outcome × provider, `failure` to reason × cell ×
provider. Provider values are bounded by the integration list — Datadog
currently sees 10 distinct values on the mailbox gauges.
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.

2 participants