Skip to content

fix(agent): say out loud what the UDP capture listener discards (#873) - #874

Merged
bpalermo merged 1 commit into
mainfrom
fix/873-udp-fail-loudly
Sep 20, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/873-udp-fail-loudly

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Refs #873 — the half that stops the silent case. Full weighted UDP support is the other half.

The problem

GenerateUDPCaptureListener sets a bare Cluster route specifier taken from backends[0] of the first sorted service key, so three UDPRoute inputs are silently dropped:

  1. backend weights beyond the first — udp_proxy carries one cluster, so a 90/10 UDPRoute sends 100 % to one backend;
  2. a second UDPRoute-backed service on the same pod — there is one UDP listener per pod and it is already bound to the first;
  3. weight 0 on the chosen backend — that means drain for TCP and TLS (fix(l4route): honor weight:0 as drain, don't normalize to 1 #492), and UDP forwards to it anyway.

What makes this worth fixing now is that the failure is silent from both ends: the route is accepted by the API, common/l4project resolves and weights the backends correctly, and the data plane quietly ignores them. No NACK, no warning, no stat. The first symptom is datagrams arriving somewhere unintended, and the only way to discover the limit today is to read the generator.

What this does

Nothing changes about what is generated. It makes the gap visible:

  • proxy.UnsupportedUDPRouteShapes() reports the discards as human-readable reasons. Pure and exported — the proxy package builds config and does not log, so the caller decides what to do with them.
  • aether.agent.l4route.udp_unsupported counts them per snapshot generation.
  • The cache logs one WARN per reason, naming the pod and the issue.

The risk this introduces, and how it's handled

The detector duplicates the generator's selection logic, so the two can drift — and a drifted detector is worse than no warning, because it would confidently name the wrong cluster.

TestUnsupportedUDPRouteShapesTracksTheGenerator pins them together: it generates a real listener and asserts it bound to the service the detector named.

Seen red. Reversing only the detector's key order, leaving the generator's alone:

--- FAIL: TestUnsupportedUDPRouteShapesTracksTheGenerator
    reason should say ns/z was dropped because the listener is bound to
    udp:a.mesh, got: service "ns/a" is dropped entirely: the pod has ONE UDP
    capture listener and it is already bound to "udp:z.mesh" (service "ns/z")

Restored, green again.

The table test covers all three shapes plus the two cases that must stay silent (a single weighted backend, and empty backend lists being skipped rather than chosen) — a detector that never fires and a detector with nothing to report look identical from the outside, so both directions are asserted.

bazel test //agent/internal/xds/proxy:all //agent/internal/xds/cache:all //agent/internal/xds/cache/cachemetrics:all passes; --config=lint clean on //agent/internal/xds/....

No charts/ change, so no Chart.yaml bump.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

GenerateUDPCaptureListener sets a bare Cluster route specifier taken from
backends[0] of the first sorted service key, so three UDPRoute inputs are
silently dropped:

  1. backend weights beyond the first -- udp_proxy carries one cluster, so a
     90/10 UDPRoute sends 100% to one backend;
  2. a second UDPRoute-backed service on the same pod -- there is one UDP
     listener per pod and it is already bound to the first;
  3. weight 0 on the chosen backend -- that means DRAIN for TCP and TLS
     (#492) and UDP forwards to it anyway.

The failure is silent from both ends: the route is accepted by the API,
common/l4project resolves and weights the backends correctly, and the data
plane quietly ignores them. No NACK, no warning, no stat -- so the first
symptom is datagrams arriving somewhere unintended, and the only way to
discover the limit today is to read the generator.

This does not change what is generated. It makes the gap visible:

  - proxy.UnsupportedUDPRouteShapes() reports the discards as reasons. Pure
    and exported -- the proxy package builds config and does not log, so the
    caller decides what to do with them.
  - aether.agent.l4route.udp_unsupported counts them per snapshot generation.
  - the cache logs one WARN per reason, naming the pod and the issue.

Full support is the other half of #873 and needs a matcher-based
RouteSpecifier; this is the half that stops the silent case.

The detector duplicates the generator's selection, so it can drift from it --
which would be worse than no warning, since it would name the wrong cluster.
TestUnsupportedUDPRouteShapesTracksTheGenerator pins them together by
generating a real listener and asserting it bound to the service the detector
named. Seen red: reversing ONLY the detector's key order (leaving the
generator's alone) fails with

  reason should say ns/z was dropped because the listener is bound to
  udp:a.mesh, got: service "ns/a" is dropped entirely: ... bound to
  "udp:z.mesh" (service "ns/z")

No charts/ change, so no Chart.yaml bump.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit bf2acf7 into main Sep 20, 2026
22 checks passed
@bpalermo
bpalermo deleted the fix/873-udp-fail-loudly branch September 20, 2026 19:14
bpalermo added a commit that referenced this pull request Sep 23, 2026
… (#905)

`aether.agent.l4route.udp_unsupported` — the counter #874 added to stop
#873's silent discard — was registered but never seeded at zero. The OTel
SDK exports a counter only after its first Add, so the series did not
exist in Prometheus at all: a dashboard or alert built on it reads "no
data" forever, which is indistinguishable from a healthy zero. Only the
log half of #874 ever worked.

Confirmed on talos-main (helm rev231): all four seeded siblings are
present and no `aether_agent_l4route_*` metric is returned at all.

The seed block's own comment said "the healthy case for all four" — it
was written for four counters and the fifth was added to registration
without being added to the list. That is the second time (the comment
records the first, #638 on rev200), so the fix is not just the missing
line:

- seed `udpRouteUnsupported` at zero alongside the other four anomaly
  counters, and rewrite the comment for five;
- `TestEveryRegisteredCounterDeclaresItsSeedPolicy` parses this package's
  own source (go:embed + go/ast) for every `meter.Int64Counter`
  registration and requires each one to be either exported-at-zero before
  any increment or listed as deliberately-not-seeded with a written
  reason. A counter added to `New()` with neither now fails here instead
  of in production.

Also in the same registration: it returned a bare `err` where every
sibling wraps, so a failure to register this one counter produced an
unattributed error. And the doc comment for `StaleNetnsSkipped` had been
orphaned above `UDPRouteUnsupported`, so godoc attached both to the
wrong function.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Opus 5 <[email protected]>
bpalermo added a commit that referenced this pull request Sep 23, 2026
… (#914)

udp_proxy carries ONE cluster, and the per-pod UDP capture listener was
choosing it with `backends[0]` of the lexicographically first service. Two
of the three things that discarded were bugs, not limits:

  - an explicit weight 0 is a Gateway API DRAIN (#492, shipped for TCP and
    TLS) and the UDP path forwarded to the drained backend anyway;
  - which backend won depended on backendRef ORDER, so a 10/90 split written
    canary-first sent 100% to the canary.

Both are fixed: drained backends are never bound, a service whose every
backend is drained contributes nothing rather than capturing the listener,
and among what is left the heaviest backend wins with ties broken by cluster
name (#135 — a selection that varies between rebuilds of identical input
re-hashes the listener on every push).

A genuine traffic SPLIT stays unrepresentable, and this states why instead of
faking it. Verified against Envoy v1.39.0: udp_proxy's route action registry
is keyed on its own private RouteActionContext and holds exactly one action,
`Route`, whose only field is `cluster`. tcp_proxy's weighted_clusters has no
counterpart.

So does per-service selection, for a reason #873 does not mention and which
rules out its suggested fix direction. The capture path REDIRECTs UDP, which
rewrites the destination before delivery; a datagram listener's only
addressing cmsg is IP_PKTINFO, so a matcher's DestinationIPInput reads the
post-DNAT header and the ClusterIP is gone. Envoy never reads IP_ORIGDSTADDR
anywhere and original_dst is structurally TCP-only. DestinationPortInput is
not packet-derived at all — the port is stamped from the listening socket's
own port. A udp_proxy matcher therefore has nothing to discriminate on; that
needs TPROXY capture or a listener per service, which is a CNI change.

Also closes a dangling-cluster hole found on the way, of the same class as
proposal 037 Risk 1 and #877: captureUDPClusters skips a backend service the
cluster cache does not hold, but the generator would still name its cluster,
and udp_proxy has no on-demand cluster path — the datagrams are accepted and
dropped in silence. Both sides now consult one predicate
(udpClusterForLocked), so the listener and CDS cannot disagree, and
reconcileUDPCaptureListeners rebuilds on snapshot push when the bindable
cluster changes, so a UDPRoute landing before its backend registers does not
stay dark until the next UDPRoute event.

The detector #874 added is no longer a duplicate of the selection it reports
on: both call selectUDPRoute, so the drift that test was pinning is now
unrepresentable. The test stays as the end-to-end pin.


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Opus 5 <[email protected]>
bpalermo added a commit that referenced this pull request Sep 26, 2026
…937)

Fifth of the #931 series. The fix landed in #936; this makes the failure it
fixed detectable if it ever returns in another form.

WHY THERE WAS NOTHING TO SEE

A published udp: cluster in which no endpoint is routable is a silent blackhole.
udp_proxy takes the datagram, finds an empty healthy set (NewUDPServiceCluster
sets HealthyPanicThreshold: 0, so it will not spray to unhealthy hosts), and
discards it. Nothing reports that:

  - no NACK: the config is valid
  - no "UDPRoute input discarded": nothing was dropped at projection time, so
    the #874 path stays quiet
  - no udp_proxy counter either. downstream_sess_rx_datagrams counts per
    SESSION and a session needs a host, so it does not move. Measured on a live
    cluster: it read 1 after FOUR datagrams had reached the socket.

captureUDPClusters is the only place that holds both the cluster and its
endpoints' health, so it is the only place the condition can be named.

Reported rather than skipped. Skipping would remove the listener and trade one
blackhole for another; leaving the cluster published means the service recovers
by itself the moment an endpoint goes healthy.

WHAT COUNTS AS ROUTABLE IS ENVOY'S DEFINITION, NOT OURS

HEALTHY and UNKNOWN are both load balanced -- UNKNOWN is the default for an
endpoint nobody has said anything about -- while UNHEALTHY, DRAINING and TIMEOUT
are not. Reading UNKNOWN as unhealthy would fire on every healthy service whose
endpoints carry no explicit status, which is most of them.

An empty load assignment reports nothing: that is a cold start, not a blackhole,
and firing there would make the counter ring for every service between its
cluster appearing and its endpoints arriving.

THE COUNTER IS SEEDED, AND THE GATE HAS A RED STATE

Seeded at zero, because an unseeded counter has no Prometheus series at all and
"no series" is indistinguishable from "zero" to a grading query. That has been
forgotten twice here (rev200, then rev231/#882) --
TestEveryRegisteredCounterDeclaresItsSeedPolicy now caught it a third time,
before it shipped.

TestUnroutableUDPEndpoints drives the detector red, including the exact shape
#931 shipped in (#853: a gate never shown to fire is not a gate).

INCIDENTAL REFACTOR

New() was one flat run of `if ... err != nil` registrations sitting one
registration below the gocognit limit, so adding this counter failed the lint.
Split into registerActivityInstruments / registerAnomalyCounters /
seedAnomalyCounters -- groups that match the seeding distinction rather than an
arbitrary cut. The seed-policy test parses this file's AST, so it reads the
registrations from the helpers unchanged.

Refs #931


Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant