Skip to content

fix(agent): seed the UDPRoute-discard counter so it has a series (#882) - #905

Merged
bpalermo merged 1 commit into
mainfrom
fix/882-seed-udp-unsupported
Sep 23, 2026
Merged

bpalermo merged 1 commit into
mainfrom
fix/882-seed-udp-unsupported

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Fixes #882.

The problem

aether.agent.l4route.udp_unsupported — the counter #874 added so #873's UDPRoute discards would stop being silent — is registered and then never seeded. The OTel SDK exports a counter only after its first Add, so until the first real discard the counter has no Prometheus series at all. A grading query reads "no data", which is indistinguishable from "healthy zero", "renamed", or "code path dead". Only the WARN-log half of #874 ever worked.

Confirmed on the currently-deployed build (talos-main, helm rev231), listing every aether_agent_(l4route|identity|snapshot)_* metric name:

aether_agent_identity_cluster_unpinned_total            <- seeded, present
aether_agent_identity_inbound_binding_mismatch_total    <- seeded, present
aether_agent_identity_outbound_binding_mismatch_total   <- seeded, present
aether_agent_snapshot_stale_netns_skipped_total         <- seeded, present
aether_agent_l4route_udp_unsupported_total              <- ABSENT

No l4route metric is returned at all. Same class as #853 (a shellcheck gate that linted zero files) and #880: a control that is configured, looks correct, and cannot report.

What this changes

1. The seed. m.udpRouteUnsupported.Add(ctx, 0) joins the four anomaly counters already seeded, and the block comment — which still said "the healthy case for all four" — is rewritten for five. That comment is the evidence this is a repeat: it was written for four counters after #638's two were found missing on rev200, and the fifth was added to registration without being added to the list.

2. A gate that catches the next one. Per #882's acceptance criterion, the test asserts against the exported metric set rather than against the field list, and derives the expectation from the code instead of from a second hand-maintained list:

TestEveryRegisteredCounterDeclaresItsSeedPolicy embeds cachemetrics.go (go:embed) and walks it with go/ast for every meter.Int64Counter("…") registration. It then collects a fresh Metrics through a ManualReader with nothing incremented, and requires every registered counter to be either:

  • exported at zero (it is in seededCounters, asserted separately at value 0), or
  • named in countersDeliberatelyNotSeeded with a written reason.

A counter added to New() with neither fails here. A stale entry in either list fails too, so the two cannot silently cancel out.

3. Two things found in the same registration. It returned a bare err where every sibling wraps (fmt.Errorf("stale netns skipped: %w", err)), so failing to register this one counter produced an unattributed error. And the doc comment for StaleNetnsSkipped had been orphaned above UDPRouteUnsupported, so godoc attached the stale-netns text to the UDP function and left StaleNetnsSkipped undocumented.

Labels: there are none

The counter takes no attributes — Add(ctx, n) with no metric.WithAttributes, deliberately, because the things it would carry (pod, service, cluster name) are unbounded cardinality and are logged at WARN instead. So there is exactly one series and it is fully seeded; nothing is left unseeded for lack of enumerability.

The counters deliberately left unseeded

Five of the ten registered counters are not seeded, each with the reason recorded in the test:

counter why not
aether.agent.snapshot.builds increments on the first snapshot generation, which every live agent performs
aether.agent.snapshot.errors paired with builds; TestCacheMetrics_GeneratedFailure asserts its absence alongside a build
aether.agent.upstreams.miss traffic-driven, not an always-on invariant
aether.agent.upstreams.ttl_refreshed prune-pass activity; a zero before the first prune pass is not a health signal
aether.agent.upstreams.restored a cold start legitimately restores nothing, and TestCacheMetrics_UpstreamsRestored asserts that absence

snapshot.errors is arguably a seed candidate on the same reasoning as the anomaly counters, but seeding it changes behaviour an existing test asserts, so it is out of scope for #882 rather than quietly bundled in.

How the seeding was verified to produce a series

Seeding means recording a zero-valued observation, not merely declaring the instrument — so the assertion is made against the SDK's exported metric set (ManualReader.Collect, the same aggregation the OTLP exporter reads), not against the instrument's existence. metricValue returns found = false precisely when the metric has no data points, which is the bug's shape.

The OTLP→Prometheus rename (aether.agent.l4route.udp_unsupported → aether_agent_l4route_udp_unsupported_total) is out of the agent's hands, but the mechanism is already proven end-to-end by the four seeded siblings above: they are seeded the identical way and all four report a live series on rev231, while the one unseeded counter reports nothing. That is exactly the difference this PR removes.

Negative controls — seen red, seen green

1. Remove the seeding

Deleting m.udpRouteUnsupported.Add(ctx, 0) leaves the field still used by UDPRouteUnsupported(), so the package still compiles and the test is what fails — not the build:

--- FAIL: TestCacheMetrics_AnomalyCountersSeededAtZero (0.00s)
    cachemetrics_test.go:181: aether.agent.l4route.udp_unsupported not exported before first increment
--- FAIL: TestEveryRegisteredCounterDeclaresItsSeedPolicy (0.00s)
    cachemetrics_test.go:265: aether.agent.l4route.udp_unsupported is registered but has no data point before its first increment: seed it at zero in New(), or add it to countersDeliberatelyNotSeeded with the reason
FAIL

2. The actual recurring defect: a new counter registered without a seed decision

This is the case that matters, since #882 is the second occurrence. Registering aether.agent.snapshot.next_counter in New() and touching it nowhere else (_ = m.nextCounter, so it still compiles):

--- FAIL: TestEveryRegisteredCounterDeclaresItsSeedPolicy (0.00s)
    cachemetrics_test.go:257: aether.agent.snapshot.next_counter is registered but has no data point before its first increment: seed it at zero in New(), or add it to countersDeliberatelyNotSeeded with the reason
    cachemetrics_test.go:265: parsed 11 Int64Counter registrations ([... aether.agent.snapshot.next_counter ...]), want 10; update seededCounters or countersDeliberatelyNotSeeded
FAIL

Restored, green

=== RUN   TestCacheMetrics_NilReceiverSafe
--- PASS: TestCacheMetrics_NilReceiverSafe (0.00s)
=== RUN   TestCacheMetrics_UpstreamsRestored
--- PASS: TestCacheMetrics_UpstreamsRestored (0.00s)
=== RUN   TestCacheMetrics_UpstreamTTLRefreshed
--- PASS: TestCacheMetrics_UpstreamTTLRefreshed (0.00s)
=== RUN   TestCacheMetrics_GeneratedSuccess
--- PASS: TestCacheMetrics_GeneratedSuccess (0.00s)
=== RUN   TestCacheMetrics_GeneratedFailure
--- PASS: TestCacheMetrics_GeneratedFailure (0.00s)
=== RUN   TestCacheMetrics_AnomalyCountersSeededAtZero
--- PASS: TestCacheMetrics_AnomalyCountersSeededAtZero (0.00s)
=== RUN   TestEveryRegisteredCounterDeclaresItsSeedPolicy
--- PASS: TestEveryRegisteredCounterDeclaresItsSeedPolicy (0.00s)
PASS

The green run is itself the anti-vacuity proof for the new gate: its last assertion requires the source parse to have found exactly 10 Int64Counter registrations, so a parse that matched nothing — or that stopped matching because the registration shape changed — fails rather than passing empty. That is the #853 failure mode, checked directly.

Checks

  • bazel test //agent/internal/xds/cache/... //agent/internal/l4route/... //agent/internal/xds/proxy/... — 5/5 pass.
  • bazel build --config=lint --@aspect_rules_lint//lint:fail_on_violation //agent/internal/xds/cache/... — clean.
  • make gazelle run; it picked up the go:embed and added embedsrcs = ["cachemetrics.go"] to the go_test. No module change, so no make tidy.
  • No charts/ change, so no Chart.yaml bump.

Note, unrelated: make format also wants to reformat e2e/multiprotocol.sh (landed in #901). Reverted here to keep this diff to one package — worth a separate look at whether format-check is green on main.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

`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.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
@bpalermo
bpalermo merged commit db8f29c into main Sep 23, 2026
22 checks passed
@bpalermo
bpalermo deleted the fix/882-seed-udp-unsupported branch September 23, 2026 10:12
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.

agent: udp_unsupported counter is never seeded, so it has no Prometheus series (#873/#874 observability half is inert)

1 participant