Skip to content

feat(agent): persist the observed demand set so a replaced agent starts warm (#701) - #702

Merged
bpalermo merged 1 commit into
mainfrom
feat/701-persist-observed-upstreams
Sep 5, 2026
Merged

bpalermo merged 1 commit into
mainfrom
feat/701-persist-observed-upstreams

Conversation

@bpalermo

@bpalermo bpalermo commented Sep 5, 2026

Copy link
Copy Markdown
Owner

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:

node window prober http_error (auth / fwd) timeout correlates with
w01 14:26:15–14:26:30Z +57 / +58 +6 / +6 new proxy pod 14:26:24Z
w03 14:27:30–14:27:45Z +65 / +65 +8 / +9 new agent pod 14:27:01Z

AetherProberHTTPErrorBurst fired 14:26:54Z → resolved 14:37:04Z. Nothing on w02/w04/w05 (they host an echo replica). No observed undeclared upstream (ODCDS miss) line on either agent.

Why: a fresh proxy has no initial_resource_versions to re-seed from (#698 has nothing to read), and a fresh agent's OBSERVED demand set is empty, so the first requests for echo.aether-test.aether.internal:18081 on 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 with config.aether.io/upstreams never 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 new aether.agent.v1.ObservedUpstreams message (api/aether/agent/v1/observed_upstreams.proto), written atomically via common/file.WriteFileAtomic:

{
  "upstreams": [
    { "service": "aether-test/echo", "observedAt": "…", "expiresAt": "…" }
  ]
}

Why a proto and not a Go struct: agent/storage is generic over proto.Message and 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 no protoc-gen-dynamo annotations, which are the two toolchain-capped cases; it takes the same shape as api/aether/config/v1 (compilers = ["@rules_go//proto:go_proto"], opaque API, features.field_presence = IMPLICIT). No buf/validate annotations: 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.loadAll parses every top-level *.json in 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, and expires_at exactly 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

  • Write: on every change to the observed set — add on miss, drop on expiry, deadline moved by a refresh (fix(xds): unwedge ODCDS after a demand-set shrink and stop expiring in-use upstreams (#682) #691's in-use exemption at prune) — debounced 1s (time.AfterFunc, armed once per window) so a burst of misses is one write; and synchronously on shutdown (defer FlushObservedUpstreams() in runAgent). Never on the read path: the flush runs on the timer's goroutine, copies the set under depMu, encodes and writes outside it, and flushes are serialized so a slow earlier write can never land over a newer one.
  • Read: once, in configureSnapshotCache — before PreListen, so the restored entries are in the dependency set before AssertWatchFilter scopes the registry watch and before the first LoadClustersFromRegistry. Entries past expires_at are skipped (and scrubbed from the file on the next write).
  • Restored entries keep their original deadline. The idle TTL is measured from the observation timestamp, so the restore stores expires_at − TTL, never now — a stale set cannot outlive its hour by riding across restarts. They are ordinary TTL'd observations, not pins: they count in aether.agent.upstreams.observed, not in upstreams.miss, and still age out.
  • Union with fix(xds): alias the ODCDS authority on the mesh port, and re-seed the demand set on a fresh xDS stream (#682) #698: either source may add, neither removes. RestoreDependency on an already-restored key is a plain timestamp refresh; a key only the proxy holds is added and persisted on the next write.
  • Fail open: a missing file is a Debug line (the normal first boot); an unreadable or corrupt file is a WARN and the cold path — never an agent failure. The next change overwrites it.
  • Log: one INFO line, restored N observed upstreams from local storage, with services naming the keys up to 50 (count only beyond).
  • Metric: aether.agent.upstreams.restored (counter, per restart) in cachemetrics, nil-receiver-safe and a no-op for n <= 0 like its siblings.

No chart change: /host/var/lib/aether/registry is already mounted read-write on the agent (agent-daemonset.yaml, cni-registry-dir); the state/ 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 first LoadClustersFromRegistry push carries echo.aether-test.aether.internal:18081 and 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 with expires_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 + RestoreDependency union, 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_violation on 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:

  1. The Helm-roll shape. Baseline the prober counters on the two no-local-echo nodes, then roll both DaemonSets together:
    kubectl -n aether-system rollout restart ds/aether-agent ds/aether-proxy
    
    Assert 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 logs restored N observed upstreams from local storage with services naming aether-test/echo. No observed undeclared upstream (ODCDS miss) line for echo on either.
  2. Agent-only delete on the same nodes (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.
  3. The file is readable only through the agent's own log line on talos (no exec): the restore INFO line above, and at Debug persisted observed upstreams with 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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant