Skip to content

fix(agent, observability): a caller's ended context no longer leaves a watch unanswered, binding lines are of the snapshot they name, and an unknown pin state has a gauge and an alert (#1509, #1616, #1619, #1620, #1621) - #1625

Merged
bpalermo merged 6 commits into
mainfrom
fix/snapshot-build-pin-alert-cohort
Oct 10, 2026

Conversation

@bpalermo

@bpalermo bpalermo commented Oct 10, 2026 •

Copy link
Copy Markdown
Owner

Closes #1509
Closes #1616

Refs #1619 (shown not to be reachable; no fix), #1620 (the reachable cause is fixed; the CNI caller's handling is left) and #1621 (fixed up to a bound that needs listener.go). None of the three is closed by this pull request.

Five issues about the snapshot build and the pin alerts, based on 7fd7fd5d.

#1619: one unread watch stalling every build. Not reachable with the pinned server

Read in the module source (go-control-plane v0.14.0) and held by tests that run the agent's cache under the library's own stream handlers.

SetSnapshot hands each open watch its response on a channel the stream owns and waits for room in it. There is always room:

  • Delta stream (pkg/server/delta/v3): one channel for all types, capacity 20 (twice the resource types the library knows). A watch is answered once and removed. The stream opens the next watch of a type only when it handles the proxy's next request for it, and it empties the channel before it handles any request. So the channel holds at most one response per type that had a watch open, plus the answer to the request being handled: 7 for the six types the agent serves, 11 for a stream that watched every type the library knows.
  • State-of-the-world stream (pkg/server/sotw/v3, the per-secret SDS streams): a new channel of capacity 1 for every request, and a watch is answered once. (The agent builds the server without the ordered-ADS option, whose stream shares one channel of capacity 10.)

A proxy that stops reading blocks the stream's goroutine in Send. That goroutine then takes no request, so it opens no new watch, and the build has nothing more to hand over.

The tests (snapshot_watch_test.go, all pass on 7fd7fd5d too, which is the point):

test state result
TestABuildDoesNotWaitOnAProxyThatStoppedReading delta ADS, a watch open for each of the six types, the proxy takes no response, 39 builds that each change every type the first build answers all six watches into the channel, the others find no watch; none waits, none errors
TestABuildDoesNotWaitWhenTheStreamIsBetweenARequestAndItsWatch the same, with the stream stopped in its request callback (after it emptied the channel, before it replaced the cluster watch) while a build runs 7 responses in the channel, the most it can hold here; 38 more builds, none waits
TestABuildDoesNotWaitOnAStuckSecretStream a state-of-the-world secret stream whose proxy takes no response the same

Send in these tests blocks from the first byte: stricter than a real proxy, which has a flow-control window to fill first.

What this does not cover. The 300 s hang seen while writing #1608 was a watch made by hand on an unbuffered channel, which no stream of the server makes. The argument is about v0.14.0: a later version that sizes or drains its channels differently fails these tests. Not run against a real Envoy.

No deadline counter and no cancelled-watch machinery was added for this. See #1620 for the one line that does bound the wait, and why.

#1620: a build reported as failed although the snapshot was installed. Real, with a different cause than the issue assumed

With #1619 unreachable, the error has one way to happen, and it does not need a stuck watch. SetSnapshot selects, for each open watch, between the watch's channel and the end of the context it was given. With a context that has already ended, both are ready and Go picks at random. The first watch that loses ends the set: the build returns an error for a snapshot that is installed, and that watch and the ones after it stay open and unanswered, so the proxy is not sent the change until the next build.

AddPod is called with the CNI ADD's RPC context (agent/internal/cni/server/pod.go), which ends when the plugin's call is abandoned.

Seen failing on 7fd7fd5d: TestACallersEndedContextDoesNotLeaveAWatchUnanswered (a real delta stream with six open watches whose proxy reads everything; a build under an ended context returned the error at the first build).

The change, in snapshot.go:

  • SetSnapshot is called under context.WithoutCancel(ctx) with a timeout (defaultWatchAnswerTimeout, 5 s). What the proxy is sent no longer depends on the caller's context. The timeout replaces the caller's context as the only way out of a wait; per agent: one unread xDS watch can stall every snapshot build on the node #1619 it is not expected to elapse.
  • If it does elapse, the build returns ErrWatchNotAnswered (wrapped, with the library's error), so a caller can tell "installed, a watch not answered" from "not built" with errors.Is.
  • Per caller: the four callers inside the package that only log a build error (regenerateAllHTTPListeners, rebuildIdentityDerived, regenerateAllAppDeliveryClusters, the QUIC publisher) no longer log an installed snapshot as failed to regenerate snapshot; the build has already logged the unanswered watch at WARN. The mutators that return the error (AddPod, RemovePod, the cluster and secret setters) return it wrapped, unchanged otherwise.

What this does for #1620, and what is left (review round 2). Done: a caller's ended context no longer leaves a watch unanswered or makes the build return an error, and a caller can tell "installed, a watch not answered" with errors.Is(err, cache.ErrWatchNotAnswered). Left: the CNI ADD path (agent/internal/cni/server/pod.go) still turns every AddPod error into codes.Internal, so if the 5 s bound does expire, a pod whose snapshot is installed is reported as failed and retried. That false failure now needs the bound to expire, which #1619 shows no stream of the pinned server causes; it is still the one #1620 describes, and it stays open until the CNI caller treats ErrWatchNotAnswered as installed. agent/internal/cni/server/ is not touched here.

#1621: identity-binding lines under the wrong snapshot version. Fixed for what a line names; one bound stated

The two logs read the cache's maps after SetSnapshot. Seen failing on 7fd7fd5d: TestBindingLinesAreOfTheSnapshotTheyName stops a build inside SetSnapshot, adds a pod, a cluster and a secret meanwhile, and lets it go. The first version's lines named the late pod and the late cluster and said the late secret was served; the build that published them logged nothing.

Now the lines are made from the snapshot's own resources:

  • Inbound: the snapshot's listener slice and its secret slice. The pod of a listener comes from a view of the listener map taken during the build (bindingView), joined by identity: a pod is named only when the very listener proto its entry held is one of the snapshot's listeners.
  • Outbound: the clusters are the mTLS-injected cluster resources the build published from its read of the cluster map (the read the pin report comes from), by resource name. A source pod is named only when its outbound or capture listener is in the snapshot.

So no line names a pod, a cluster or a served secret that the snapshot of its version does not carry.

What is not exact, and why this says Refs:

  • The view and Listeners() are two reads of the listener map, a few statements apart. An entry written between them is in the snapshot and is first named by the next build. A pod that was already named and is rebuilt in that gap is left out of this build's table and named again by the next one. Closing it needs meshListeners() to return the owners under its own lock, which is in listener.go.
  • The netns → identity index (localWorkloads) is not a resource of any snapshot. It is read during the build instead of after the set.

Behaviour changes:

  • A pod whose netns is gone (the build skips its listeners) is no longer named in binding lines while it is skipped. It was named before although nothing of it was published.
  • The cluster attribute of an outbound binding line is the cluster's resource name. It was the entry's map key, which for a service's default entry is the service key and not the FQDN the cluster is published under (review round 1). The TCP floor clusters are not named, as before: floor entries hold no mTLS-injected cluster.

#1509: the divergence alert goes silent when the agent restarts while the proxy rejects. Still applied after #1528; fixed with a gauge and a rule

Checked first: the promtool case on main asserted the silence (…silences the divergence rule), and TestAckedPinGaugeWhenTheAgentRestartsWhileTheProxyRejects shows the gauge withdrawn. #1528 made the agent stop writing a wrong count there; it did not make the state visible to a rule.

  • New gauge aether.agent.xds.acked_tls_clusters_unknown (stored aether_agent_xds_acked_tls_clusters_unknown, one series per agent, no attribute): the number of mesh clusters the proxy holds whose pin state the agent cannot determine. Zero while the acknowledged gauge is written, the count while it is withdrawn for that reason, absent until a proxy has answered a cluster response of this agent process.
  • New rule AetherProxyPinStateUnknown: above zero for 15 minutes, warning. It says the agent cannot classify what the proxy holds and that the divergence rule is blind for that node. It does not say the proxy holds an unpinned cluster, and it does not say the proxy is rejecting updates: a proxy that accepted a version whose pin class the agent had already dropped from its bounded record produces the same state, with no NACK (review round 1).
  • The two gauges are observed by one callback from one read of the state, so one collection never has the acknowledged series beside a positive unknown count.
  • No expression of an existing rule changed. No acknowledged state is persisted across an agent restart.

Seen failing before the fix: the cache test (the withdrawal is a sample) and the promtool case (AetherProxyPinStateUnknown at 35m: expected one alert, got none).

#1616: the pin alerts' $value. The premise did not ship; the same holds through pod; documented

The edge control plane sets no service.instance.id (only the edge proxy container does), so there is no instance label separating two replicas. But docs/observability/metric-labels.md recommends promoting k8s.pod.name to pod for aether-edge, and in such a pipeline two co-located edge replicas are two sets of series that sum by (job, node, reason) adds up. The rule file's header and the README now say what the figure is, and a promtool case holds it (two replicas, one unpinned cluster each: one alert, figure 2). No expression changed.

Contract

The external-harness contract gains one entry; version stays 2 (a new entry needs no bump, per the README's table). agent.xds_acked_tls_clusters_unknown is added to external-harness.yaml and to the ids //agent/internal/xds/cache/cachemetrics:cachemetrics_test owns and checks. No existing entry is edited: agent.xds_acked_tls_clusters is written and absent under the same conditions as before.

#1566 (the contract lock file) is not merged. When it is, this entry needs its line in the lock file.

Red, then green

Seen failing on 7fd7fd5d (production files of the package checked out at that commit, new tests kept):

  • TestBindingLinesAreOfTheSnapshotTheyName (all four assertions).
  • TestACallersEndedContextDoesNotLeaveAWatchUnanswered (build 1).
  • TestAckedPinGaugeWhenTheAgentRestartsWhileTheProxyRejects and the promtool case, before the gauge and the rule existed.

The three #1619 tests pass on 7fd7fd5d: they show the stall cannot happen.

Mutations, one at a time, each run against the tests and reverted (30 in all):

mutation result
SetSnapshot under the caller's context again caught, TestACallersEndedContext…
the bound ignores its field; no bound at all caught, TestABuildThatCouldNotAnswerAWatchSaysSo
the error is not the sentinel; the error is swallowed caught, four and three tests
snapshotInstalled is err == nil; is always true caught
each of the four log-only callers logs a failure again caught, TestCallersThatOnlyLog… (four mutations)
the view AND the listeners are read when the lines are written (the old behaviour) caught, TestBindingLinesAreOfTheSnapshotTheyName
a source, or an inbound chain, is named whatever the snapshot carries caught, two tests each
served from the cache's secret map; mTLS entries from the cluster map of now caught
every entry is an mTLS entry; none is; the buffer is not reset caught (the first and the last survived at first; TestBindingLinesNameTheMTLSEntriesTheBuildRead was added for them)
unknown gauge: count not passed; known does not reset it; known is not a sample; observed before settled; withdrawal is not a sample caught, cache and metrics tests
rule: for 14m, 16m, 1m; >= 0 caught, promtool
only the view is read late (listeners still the snapshot's) survived
only the listeners are read late (view still the build's) survived

The two survivors are each one half of the old behaviour. The identity join makes either half alone name nothing the snapshot lacks; what each loses is an omission in the race (a pod removed during the set), which no test here drives.

With the change: //agent/internal/..., //agent/test/..., //:observability_rules_test and //test/harnesscontract/... pass; --config=race --build_tests_only passes on //agent/internal/xds/cache:all and cachemetrics:all; the new and changed tests pass 50 runs at 4 wide; lint with fail_on_violation on //agent/internal/xds/cache/..., make format-check and make go-build-plain are clean.

Review round 1

Six threads on fe4c13f5, all fixed, in the head commit. origin/main is merged in.

  • The two gauges were collected by a callback each. True: a change between the two callbacks of one collection could export both, or neither. One RegisterCallback for both instruments, one read under the mutex. TestAckedGaugesAreCollectedTogether (red first: each gauge had a callback of its own).
  • The binding log named entry keys, not cluster resources. True for a default entry keyed by the service (red first: TestBindingLinesNameClusterResources, the line said aether-test/echo where the snapshot carries echo.aether-test.aether.internal). The names are now those of the mTLS-injected clusters appended in the pass. The floor half of the point cannot happen today (a floor entry holds no mTLS-injected cluster), and the name is now taken after the floor branch, so it cannot start to.
  • The new gauge was not in the contract. Added (above).
  • A test could hang. The receive on the callback signal is bounded and the callback is released by a cleanup that runs before the stream's; the three unbounded receives in bindinglog_test.go are bounded too. The other tests of the file already receive through bounded helpers.
  • "The proxy is not accepting cluster updates" was more than the gauge knows (two threads). True. The rule comment, the annotation, the runbook, the README and this description now say what the state is and name both ways into it.
  • Four mutations for this round (acknowledged series observed while unknown; unknown observed before settled; names are entry keys; the contract entry not owned), all caught and reverted.
  • Re-read against the code: the rule comment no longer says an ordinary restart cannot produce the state, and the runbook no longer says an unanswered-watch line proves a library change.

Review round 2

One thread on 5aca6816: the CNI ADD path still fails a pod for ErrWatchNotAnswered. True, and that package is out of this pull request's reach, so #1620 is Refs, not Closes, and the section above says what is done and what is left. No code change.

Tests of #1608 whose setup changed

TestAckedPinsKnowASnapshotWhoseSetReturnedAnError and TestASnapshotWhoseSetReturnedAnErrorIsReportedAsTheOneServed made SetSnapshot fail with an ended context and an unbuffered watch. An ended context no longer does that, so they set a 50 ms bound and assert ErrWatchNotAnswered. No other assertion changed.

Not verified

  • Nothing was run on a cluster or against a real Envoy.
  • The 5 s bound is a choice, not a measurement.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

…a watch unanswered, binding lines are of the snapshot they name, and an unknown pin state has a gauge and an alert (#1509, #1616, #1619, #1620, #1621)

#1619: with go-control-plane v0.14.0 no stream can leave its response
channel full, so a proxy that stops reading cannot stall a snapshot build.
Held by tests that run the cache under the library's stream handlers.

#1620: SetSnapshot is called under a context that keeps the caller's values
and not its cancellation, bounded by 5 s. With the caller's context, one that
had already ended made the answer to each open watch a random choice. A build
that could not answer a watch returns ErrWatchNotAnswered.

#1621: the identity-binding lines are made from the snapshot's own listeners
and secrets and from the build's read of the cluster map, joined to the
owning pods by listener identity.

#1509: aether.agent.xds.acked_tls_clusters_unknown counts the clusters the
proxy holds whose pin state the agent cannot determine, and
AetherProxyPinStateUnknown fires on it after 15 minutes.

#1616: the rule file and the README say what the figure in an annotation
adds up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
Copilot AI balanced review requested due to automatic review settings October 10, 2026 00:46
@bpalermo bpalermo added proxy Envoy data plane and the hot-restart supervisor observability Metrics, logs, profiles, alerts labels Oct 10, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Binding logs can name unpublished clusters, and metric callbacks can emit mutually inconsistent gauge states.

2 open findings
What changed in this PR

Hardens xDS snapshot publication, identity-binding logs, and unknown pin-state observability.

Changes:

  • Decouples watch delivery from caller cancellation and adds a bounded timeout.
  • Logs bindings from snapshot-associated resources.
  • Adds an unknown pin-state gauge, alert, documentation, and tests.
File Description
docs/​runbook.md Documents snapshot and metric behavior.
docs/​observability/​README.md Documents the new gauge and alert.
docs/​observability/​agent-pin-alerts.yml Adds the unknown-state alert.
docs/​observability/​agent-pin-alerts_test.yml Tests alert behavior and aggregation.
agent/​internal/​xds/​cache/​udspolicy.go Handles installed-snapshot errors correctly.
agent/​internal/​xds/​cache/​snapshot.go Adds bounded watch delivery and snapshot-based reporting.
agent/​internal/​xds/​cache/​snapshot_watch_test.go Tests watch delivery behavior.
agent/​internal/​xds/​cache/​quicpublish.go Avoids misreporting installed snapshots as failures.
agent/​internal/​xds/​cache/​pinreport.go Tracks mTLS entries per build.
agent/​internal/​xds/​cache/​inboundidentitybinding.go Uses snapshot-associated inbound resources.
agent/​internal/​xds/​cache/​identitybinding.go Accepts build-derived outbound bindings.
agent/​internal/​xds/​cache/​gamma.go Handles installed-snapshot errors correctly.
agent/​internal/​xds/​cache/​cluster.go Collects mTLS entry names during cluster reads.
agent/​internal/​xds/​cache/​cachemetrics/​cachemetrics.go Adds the unknown pin-state gauge.
agent/​internal/​xds/​cache/​cachemetrics/​cachemetrics_test.go Tests unknown-gauge lifecycle.
agent/​internal/​xds/​cache/​cache.go Adds reusable tracking buffers and timeout state.
agent/​internal/​xds/​cache/​BUILD.bazel Registers new sources, tests, and dependency.
agent/​internal/​xds/​cache/​bindingview.go Introduces snapshot-listener binding views.
agent/​internal/​xds/​cache/​bindinglog_test.go Tests binding-log snapshot attribution.
agent/​internal/​xds/​cache/​ackedpins.go Reports the unknown-cluster count.
agent/​internal/​xds/​cache/​ackedpins_test.go Tests unknown state and timeout errors.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread agent/internal/xds/cache/cluster.go Resolved
Copilot AI balanced review requested due to automatic review settings October 10, 2026 00:49

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new metric lacks the required external contract, its paired gauges can produce inconsistent scrapes, and one regression test can hang indefinitely.

6 open findings

🧠 Review effort: Balanced

Comment thread docs/observability/agent-pin-alerts.yml Resolved
Comment thread docs/runbook.md Resolved
bpalermo and others added 4 commits October 9, 2026 22:09
…ines name cluster resources, the unknown gauge is a contract entry, bounded test receives, the unknown state claims no rejection

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
…ermo/aether into fix/snapshot-build-pin-alert-cohort
Copilot AI balanced review requested due to automatic review settings October 10, 2026 01:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread agent/internal/xds/cache/snapshot.go Resolved
@bpalermo
bpalermo merged commit 01ed9ff into main Oct 10, 2026
31 checks passed
@bpalermo
bpalermo deleted the fix/snapshot-build-pin-alert-cohort branch October 10, 2026 01:28
bpalermo added a commit that referenced this pull request Oct 10, 2026
…n open watch was not answered from it (#1620) (#1631)

Since #1625 a snapshot build that could not hand a response to an open watch
within its bound returns cache.ErrWatchNotAnswered: the snapshot is installed
and served. The CNI server still read it as a failed build.

Every caller of the snapshot cache in agent/internal/cni/server now passes the
mutator's error through one helper. For the sentinel it logs a WARN, adds one
to aether.agent.cni.snapshot_watch_unanswered{aether.snapshot.caller} and
returns nil; every other error is returned unchanged.

- CNI ADD: answered with success instead of Internal, so the runtime no
  longer tears down and retries a sandbox whose listeners are published.
- CNI DEL and the ghost sweep: already best-effort; they no longer log that
  the listener was not removed when it was.
- surge takeover: the step is no longer logged as failed for listeners that
  are installed.

The server holds the cache behind a three-method interface so a test can
return the sentinel without waiting out the cache's 5 s bound.

Closes #1620


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

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

Labels

observability Metrics, logs, profiles, alerts proxy Envoy data plane and the hot-restart supervisor

Projects

None yet

2 participants