Skip to content

perf(supervisor): probe /ready in the verified steady state, /server_info only for epoch identity - #647

Merged
bpalermo merged 2 commits into
mainfrom
perf/646-supervisor-ready-probe
Aug 30, 2026
Merged

bpalermo merged 2 commits into
mainfrom
perf/646-supervisor-ready-probe

Conversation

@bpalermo

Copy link
Copy Markdown
Owner

Closes #646.

Mechanism

The proxy-supervisor's liveness watchdog needs one boolean pair per tick — live at our epoch and reachable — and was buying it with a full JSON parse of an unbounded /server_info document once a second on every node, forever.

Epoch identity is only load-bearing while an epoch is unverified. adminProber (new, agent/internal/proxy/hotrestart/adminprobe.go) makes that explicit:

  • UNVERIFIED — every 1s tick goes to /server_info on the authoritative client. A LIVE answer at our epoch records (verifiedEpoch, verifiedAt).
  • VERIFIED — while epoch == verifiedEpoch && childTracked(epoch) && age < adminReverifyInterval (15s), the tick goes to /ready on the fast (pooled) client: plain text LIVE\n, HTTP 200 iff LIVE, computed from the same main-thread Utility::serverState(...) call as /server_info's state — so equally sensitive to the wedged-main-thread mode the watchdog exists to detect. Anything but a plain LIVE (or any transport error) invalidates and the next tick re-verifies authoritatively.

readyPollInterval stays 1s, so detection latency is unchanged. adminLiveAtEpoch (initStartEpoch / handleDebounce / handleShutdown) is untouched in behavior — it always takes the authoritative, unpooled path.

15s for adminReverifyInterval sits below both ParentShutdownTime (60s — a cross-pod takeover is still diagnosed while our parent lives) and defaultAdminUnresponsiveDeadline (30s).

The two-client correctness invariant (lesson 3 / errno-111)

The epoch-identity probe must always run on a FRESH TCP connection. A draining hot-restart parent keeps answering LIVE at its OLD epoch over already-accepted connections for the whole --parent-shutdown-time-s window — Envoy flips live_ in InstanceImpl::shutdown(), not in drainListeners().

Proposal 001 lesson 3 is that the old pod detects a mid-handoff takeover via its own admin no longer answering at its epoch (handleShutdown). A pooled /server_info would invert that: the old pod would believe it is still the serving Envoy, take the plain shutdown path, and SIGTERM the successor's hot-restart parent — the errno-111 node data-plane gap of 2026-06-11.

Hence two clients, and the difference between them is a correctness invariant rather than tuning:

  • adminAuthoritative: DisableKeepAlives: true. Byte-for-byte today's semantics.
  • adminFast: one idle conn, 30s idle timeout, used only by /ready in the verified state.

invalidate() clears verifiedEpoch and calls CloseIdleConnections(), so the pinned connection never survives a re-verification boundary or an ambiguous tick.

Two structural consequences worth stating:

  • The fast path is unreachable while the handoff watchdog is armed — only a /server_info confirmation sets verifiedEpoch, and that same tick calls markEpochLive, while the watchdog requires !wasLive. The handoff.duration histogram is untouched.
  • Known benign divergence: a cross-pod successor taking over while our child is still alive is invisible to /ready for ≤15s. The readiness outcome is identical on both paths (hold while ready && reachable && childTracked, per fix(supervisor): hold readiness while serving as hot-restart parent #132), and writeState is a no-op under the downgrade guard. Only a diagnostic log is delayed.

Before-numbers (talos-main, measured 2026-08-30 — do not re-measure)

  • Pyroscope process_cpu, service_name="unknown_service:supervisor", 3h window: adminProbe ≈ 29% of supervisor CPU, of which json decode ≈21%; dialConn 2.6%; gcBgMarkWorker 10.9%. (onLiveEpoch/writeState 5.1% — pre-existing, see below.)
  • Envoy admin stats: rq_total 5.00/s, cx_total 5.00/s, cx_active 0, destroy_remote 100% → one TCP connection per request. The json.Decoder left the body short of EOF, so Go never pooled the connection. No Envoy-side change is needed.
  • Envoy 1.39 /ready: plain text <STATE>\n, HTTP 200 iff LIVE.

Acceptance / rollout on talos-main (recorded here for the deploy — NOT done in this PR)

Baseline (before-picture): rq_total 5.00/s, cx_total 5.00/s, cx_active 0, destroy_remote 100%; profile shares as above.

Staged: OnDelete strategy, one canary pod, 30 min, then roll the rest. Never --reuse-values.

Acceptance A — cost dropped

  • rq_total ≈ 5.00/s (cadence unchanged), cx_total ≈ 0.33/s, cx_active ≈ 5.
  • aether_supervisor_admin_probes: ready ≈ 4.67/s vs server_info ≈ 0.33/s (the ~14:1 ratio the metric description calls out).
  • Profile: adminProbe < 5%, json frames absent, dialConn ≲ 0.3%, gc lower.
  • One-time /ready contract check via kubectl debug node: curl 127.0.0.1:9901/ready → 200, body LIVE\n; note the absence of Connection: close.

Acceptance B — watchdog unchanged

  • wedges_total still absent/0; ready_transitions 0; epoch flat; no unexpected child_exits; zero restarts.

Acceptance C — hitless roll harness (e2e/soak, grade on the external prober only)

  • 3× rollout restart ds/aether-proxy at 15-min spacing under k6 load (+ optional TRIPLE).
  • liveness failures 0, dns_* 0.
  • handoff_duration p95 must not regress — this is the sentinel for the pinned-connection hazard. Stretch toward the 30/60s buckets ⇒ revert commit B (it is an independent rollback lever).
  • child_exits{successor_terminated} = 1/node/roll, {unexpected} = 0; predecessor_detected = 1/node; hot_restart_epoch +1/node/roll; zero restarts.

Risks

Risk Mitigation
R1 A pooled connection answering for a superseded process Structural: DisableKeepAlives on the authoritative client, invalidate() (incl. CloseIdleConnections) on every transition. Sentinel = handoff_duration p95.
R2 Cross-pod takeover invisible ≤15s Readiness outcome identical; log-only delay; interval is tunable.
R3 /ready semantics diverging in a future Envoy TestAdminReadyMatchesServerInfoState + the debug-pod contract check; add to the Envoy-bump checklist.
R4 httptest Close racing a live keep-alive Probes idle at 1s spacing; t.Cleanup(s.adminFast.CloseIdleConnections) in the test helper.
R5 Transparent GET retry on a stale pooled conn Safe direction (re-dials, never reuses a dead one).
R6 json.Unmarshal stricter than Decoder.Decode re trailing content Envoy emits exactly one protojson object; documented, bytes.NewReader+Decode is a zero-delta fallback.
R7 +6 metric series/node Negligible.
R8 Post-change, onLiveEpoch → writeState (mkdir+flock+read+write+rename every second, 5.1%) becomes the top Go frame PRE-EXISTING, out of scope. Do not read the new profile as a regression. Follow-up (heartbeat every N ticks / only on epoch change or near-stale) to be filed separately.

Rejected alternatives

  • /stats?filter=… — the admin /stats endpoint renders on Envoy's main thread and must never be scraped (already documented in agent-proxy-configmap.yaml).
  • json.Decoder token walk over /server_info — still lexes the whole document; kept only as a fallback if /ready ever had to be abandoned.
  • Relaxing readyPollInterval to 2–5s — detection latency is the value the watchdog provides; the cost was the parse, not the cadence.

Commits

  1. refactor(supervisor) — dedicated unpooled client for the authoritative probe, adminServerInfo, the admin_probes metric, the per-endpoint fake admin, proposal-001 lesson 6. Behavior-identical; the full pre-existing suite passes untouched.
  2. perf(supervisor) — adminReady + adminProber + the watchLiveness wiring. Independent rollback lever.

Tests

//agent/internal/proxy/hotrestart/... — 13 new tests (fast-path engagement, interval re-verification, successor takeover, child gone, new epoch, not-live invalidation, unreachable invalidation, /ready↔/server_info state equivalence table, connection reuse vs. never-pool, pinned-connection drop, admin-hangs-after-LIVE through the real Run, plus the metric attributes). bazel test //agent/... --test_output=errors green; --config=ci lint clean; make format clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr

bpalermo and others added 2 commits August 30, 2026 16:23
… admin probe

The Envoy-admin watchdog probed /server_info with http.DefaultClient and a
streaming JSON decoder that left the response body short of EOF, so Go never
pooled the connection: measured on talos-main, cx_total == rq_total == 1/s/node
with destroy_remote at 100%. Give the supervisor its own clients instead, and
make the probe read its (bounded) body whole.

The two clients are a correctness invariant, not tuning. A draining hot-restart
parent keeps answering LIVE at its OLD epoch over already-accepted connections
for the whole --parent-shutdown-time-s window, so every epoch-identity decision
(proposal 001 lessons 2 and 3: initStartEpoch, handleDebounce, handleShutdown)
must dial fresh — a pooled answer there would make the old pod SIGTERM the
successor's hot-restart parent, the errno-111 node data-plane gap of
2026-06-11. The authoritative client therefore disables keep-alives outright;
the pooled fast client is added here but not yet used by any probe.

Behavior is identical: adminProbe becomes adminServerInfo on the authoritative
client, with the same reachable-vs-live contract, called from the same two
places. json.Unmarshal replaces Decoder.Decode now that the body is read whole
(Envoy emits exactly one protojson object; a truncated transient response is
still a decode failure, i.e. reachable-but-not-live).

Also adds the aether.supervisor.admin_probes counter (endpoint × outcome), the
per-endpoint fake Envoy admin the tests need (real /ready contract plus
connection counting), and records lesson 6 in proposal 001.

Refs #646

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01NArCRTfMPZkw4Y97U9Gdsr
The liveness watchdog needs a boolean pair — live-at-epoch, reachable — and was
paying for a full JSON parse of an unbounded /server_info document every second
on every node, plus one Envoy admin request per second forever. Continuous
profiling on talos-main put adminProbe at ~29% of the supervisor's CPU, most of
it encoding/json.

Epoch identity is only needed while an epoch is unverified. Once /server_info
has confirmed that the Envoy on this node's admin is ours at our epoch,
adminProber rides /ready — plain text, HTTP 200 iff LIVE, computed from the
same main-thread Utility::serverState(...) call, so equally sensitive to the
wedged-main-thread mode the watchdog exists to detect — on one pinned
connection. The identity claim is re-confirmed on a fresh connection at least
every adminReverifyInterval (15s, under both ParentShutdownTime and the
admin-unresponsive deadline), and immediately whenever the epoch changes, our
child stops being tracked, or /ready answers anything but a plain LIVE. Every
invalidation drops the pinned connection with it, so no epoch-identity answer
can ever come off a connection accepted by a since-superseded process.

The 1s cadence is unchanged, so detection latency is unchanged. The fast path
is structurally unreachable while the handoff watchdog is armed (only a
/server_info confirmation can set it, and that same tick marks the epoch live).
A cross-pod takeover while our child is still alive stays invisible to /ready
for up to 15s; the readiness outcome is identical on both paths (hold while
reachable and our child is tracked) and the heartbeat write is a no-op under
the downgrade guard, so only a diagnostic log is delayed.

Closes #646

Co-Authored-By: Claude Fable 5 <[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

Development

Successfully merging this pull request may close these issues.

proxy-supervisor: steady-state admin watchdog burns ~40% of its CPU JSON-decoding /server_info once per second

1 participant