Repository navigation
feat(agent): persist the observed demand set so a replaced agent starts warm (#701) - #702
Merged
Merged
Conversation
…ts warm (#701) A full agent+proxy replacement (every Helm upgrade) on a node with no local replica of an observed-only upstream costs one bucket of 503s (~5s, +57/+65 prober http_error on w01/w03 at the rev195 roll): the fresh proxy holds no clusters for the #698 re-seed to read, and the fresh agent's observed demand set is empty, so the first requests take the cold ODCDS path. Persist the OBSERVED half of the node dependency set to the agent's local storage directory (state/observed-upstreams.json, protojson of the new aether.agent.v1.ObservedUpstreams, atomic write) on every change, debounced 1s, plus a synchronous flush on shutdown; restore it once in configureSnapshotCache, before the watch filter and the first snapshot, so a replaced agent's first push already carries the clusters its node was using. Restored entries keep their original expires_at (never a fresh TTL), are ordinary observations rather than live-subscription pins, count as observed but not as misses, and union with the proxy's held-cluster re-seed. A missing, corrupt or unreadable file falls back to the cold path and never fails the agent. New counter aether.agent.upstreams.restored; one INFO line naming the restored keys (count only past 50). The file sits in a state/ subdirectory because storage.loadAll parses every top-level *.json in that directory as a CNI pod record and the ghost sweep would prune it. Edition 2024 proto: no gRPC service, no dynamo annotations. No chart change: the directory is already mounted read-write. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
This was referenced Sep 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Option 2 of #701, complementing #698 (the proxy's held-cluster re-seed) and #691 (TTL-on-use).
Before-state (talos-main, rev195 upgrade roll, 2026-09-05 14:25:31Z → 14:27:33Z)
With #691 + #698 deployed an agent-only restart on a no-local-replica node costs nothing (0/0/0 on w01 and w03, counters byte-identical). A full agent+proxy replacement — every Helm upgrade — still costs one bucket per node whose upstream is observed-only:
http_error(auth / fwd)timeoutAetherProberHTTPErrorBurstfired 14:26:54Z → resolved 14:37:04Z. Nothing on w02/w04/w05 (they host an echo replica). Noobserved undeclared upstream (ODCDS miss)line on either agent.Why: a fresh proxy has no
initial_resource_versionsto re-seed from (#698 has nothing to read), and a fresh agent's OBSERVED demand set is empty, so the first requests forecho.aether-test.aether.internal:18081on that node go through the cold ODCDS path — the discovery round trip plus Envoy's request queueing, ~5s. echo is observed-only on w01/w03 because nothing there declares it: real tenants withconfig.aether.io/upstreamsnever pay this, the external prober does. The soak harness masks the path completely (the k6 DaemonSet declares echo on every node).The fix: persist the observed half of the demand set
The agent already persists node-local state (CNI pod records) in
--mounted-registry-dir. This writes the observed dependency-set entries there too and reads them back once at start, so a replaced agent's first snapshot already carries the clusters the node's traffic was using when the previous agent stopped.File format
<mounted-registry-dir>/state/observed-upstreams.json, protojson of a newaether.agent.v1.ObservedUpstreamsmessage (api/aether/agent/v1/observed_upstreams.proto), written atomically viacommon/file.WriteFileAtomic:{ "upstreams": [ { "service": "aether-test/echo", "observedAt": "…", "expiresAt": "…" } ] }Why a proto and not a Go struct:
agent/storageis generic overproto.Messageand stores only protojson — there is no non-proto precedent to follow, so the file rides the same convention as the pod records beside it. Why edition 2024 rather than 2023: the file defines no gRPC service and carries noprotoc-gen-dynamoannotations, which are the two toolchain-capped cases; it takes the same shape asapi/aether/config/v1(compilers = ["@rules_go//proto:go_proto"], opaque API,features.field_presence = IMPLICIT). Nobuf/validateannotations: the reader validates the two facts it needs (non-empty key, a deadline in the future) itself and skips per entry, and adding protovalidate for that would be dead weight. Why a subdirectory:storage.loadAllparses every top-level*.jsonin that directory as a CNI pod record and the ghost sweep prunes pod records it cannot match to a live container — a file dropped beside them would be parsed as an empty pod and then deleted.Persisted per entry: the service key,
observed_at, andexpires_atexactly as the cache computes it (observed_at + TTL). That is everything the cache holds for an observed entry — the:18081/ default-port aliases are rebuilt from the registry on the first reload, not stored. The live on-demand subscriptions (#691's TTL exemption) are deliberately not persisted: they are per-stream facts the proxy re-establishes from real demand on every reconnect.Semantics
time.AfterFunc, armed once per window) so a burst of misses is one write; and synchronously on shutdown (defer FlushObservedUpstreams()inrunAgent). Never on the read path: the flush runs on the timer's goroutine, copies the set underdepMu, encodes and writes outside it, and flushes are serialized so a slow earlier write can never land over a newer one.configureSnapshotCache— beforePreListen, so the restored entries are in the dependency set beforeAssertWatchFilterscopes the registry watch and before the firstLoadClustersFromRegistry. Entries pastexpires_atare skipped (and scrubbed from the file on the next write).expires_at − TTL, nevernow— a stale set cannot outlive its hour by riding across restarts. They are ordinary TTL'd observations, not pins: they count inaether.agent.upstreams.observed, not inupstreams.miss, and still age out.RestoreDependencyon an already-restored key is a plain timestamp refresh; a key only the proxy holds is added and persisted on the next write.restored N observed upstreams from local storage, withservicesnaming the keys up to 50 (count only beyond).aether.agent.upstreams.restored(counter, per restart) incachemetrics, nil-receiver-safe and a no-op forn <= 0like its siblings.No chart change:
/host/var/lib/aether/registryis already mounted read-write on the agent (agent-daemonset.yaml,cni-registry-dir); thestate/subdirectory is created on first write.Tests (
agent/internal/xds/cache)TestRestoreDependency_FromLocalStorage_AnsweredInTheFirstPushWithNoMiss— the cold ODCDS on full agent+proxy replacement: ~5s of echo errors per no-local-replica node on every Helm upgrade (observed-only upstreams); persist the observed demand set / annotate the prober #701 counterpart of fix(xds): alias the ODCDS authority on the mesh port, and re-seed the demand set on a fresh xDS stream (#682) #698's restore test: fresh cache, empty in-memory set, persisted file → the firstLoadClustersFromRegistrypush carriesecho.aether-test.aether.internal:18081and the portless name, with no miss logged, miss counter 0, restored counter 1, not a pin, deadline carried over.TestObservedUpstreamsStore_PersistsOnMiss— the file lands after the debounce withexpires_at == observed_at + TTL.TestObservedUpstreamsStore_RestoreCarriesTheDeadlineOver— original deadline preserved (last + TTL == expires_at), expired and malformed entries skipped and scrubbed, counted as observed not as a miss, INFO line names the key.TestObservedUpstreamsStore_RestoreLogsCountOnlyPastTheCap— 51 keys → count only.TestObservedUpstreamsStore_CorruptFileStartsCold— WARN + empty set, and the next change overwrites the garbage.TestObservedUpstreamsStore_ShrinkRemovesTheEntry— an expired entry leaves the file after the debounce.TestObservedUpstreamsStore_UnionsWithResumeHeldClusters— file +RestoreDependencyunion, both persisted in key order.TestObservedUpstreamsStore_FlushShortCircuitsTheDebounce— the shutdown flush; a second flush with nothing dirty does not rewrite.TestObservedUpstreamsStore_DisabledWritesNothing— no store path → no timer, no file (the edge, and every test that does not opt in).TestCacheMetrics_UpstreamsRestored(cachemetrics).make format,make gazelle,bazel test --test_output=errors //..., lint with--config=lint --@aspect_rules_lint//lint:fail_on_violationon the touched packages (gocognit included), and the cache tests under--@rules_go//go/config:race— all green.Validation recipe (talos-main)
After the agent image is deployed:
aether_probe_requests_total{tier="mesh_dns",result="http_error"}delta = 0 on w01 and w03 across the roll (the before-state above is +57/+58 and +65/+65), and that each new agent on those nodes logsrestored N observed upstreams from local storagewithservicesnamingaether-test/echo. Noobserved undeclared upstream (ODCDS miss)line for echo on either.kubectl -n aether-system delete pod -l app.kubernetes.io/name=aether-agent --field-selector spec.nodeName=…): still 0 — that is fix(xds): alias the ODCDS authority on the mesh port, and re-seed the demand set on a fresh xDS stream (#682) #698's path, and the two sources must union, not fight.persisted observed upstreamswith the count and path (/host/var/lib/aether/registry/state/observed-upstreams.json).Refs #682, #691, #698, #687.
Closes #701
🤖 Generated with Claude Code
https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr