Repository navigation
fix(controller): bound the gateway stats the Envoy sink exports - #3765
Conversation
The gateway's OTLP stats sink exported every stat Envoy holds, every five seconds, from a proxy whose worker count defaults to the host's core count. One agent's gateway on a large node therefore held a stat per core for several families and pushed all of them 12 times a minute, which made gateway stats the bulk of the telemetry store and crowded out the logs and traces the store exists to hold. - Pin `--concurrency`: the container sets no CPU limit, so Envoy sized its workers for the whole node against a 50m CPU request. - Export an inclusion list rather than every stat, admitting the families that answer operational questions about an egress proxy and nothing whose series count scales with worker threads. - Flush once a minute instead of Envoy's five-second default. - Resolve the sink's resource through the environment detector, and carry `service.name` in the gateway's relayed `OTEL_RESOURCE_ATTRIBUTES`. The sink has no `service_name` field of its own and was configured with no resource at all, so rows from every gateway arrived indistinguishable and attributable to none. Field names verified against the Envoy v1.37.2 protos; `--mode validate` against the pinned image is still worth running before rollout. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Tomas Pilar <[email protected]>
dam-code-guardian
left a comment
There was a problem hiding this comment.
🛡️ Code Guardian 🛡️ — d56edee
PR #3765: fix(controller): bound the gateway stats the Envoy sink exports
Author: pilartomas | Branch: fix/gateway-stats-volume → main | Changes: +172 −15 (4 files)
Summary
The PR bounds what the gateway's Envoy stats sink exports: it pins Envoy's worker concurrency, adds an inclusion list, sets a 60-second flush interval, and gives the sink a resource detector so each row names its gateway. One inclusion-list entry names a stat that Envoy does not emit. 2 suggestion(s) dropped under the 🟢 budget.
Findings
- 🟡 Warning: the inclusion list names two watchdog counters Envoy never emits, so the gateway exports none (
packages/controller/pkg/reconciler/envoy_bootstrap.go:781) - ✅ Looks good: the sink's
resource_detectorsfield is real at the pinned Envoy v1.37.2 —SinkConfigfield 7, whose extension category is the tracer's own detector registry — so the sharedotelEnvironmentResourceDetectors()helper renders a valid sink and the detector name is correct for both consumers. No other reader of gateway stats exists in the repository, so the inclusion list breaks no dashboard, alert or probe.
Documentation Check (doc-drift)
- 🟢 Suggestion: the page enumerates what the inclusion list admits and reads as complete, but it omits the two listener-manager gauges the code admits (
listener_manager.total_listeners_active,listener_manager.listener_create_failure), so a reader concludes that no listener-scoped series reaches the store (docs/architecture/logging.md:71, alsopackages/controller/pkg/reconciler/envoy_bootstrap.go:784). Reported by doc-drift and issue-fit; the PR body carries the same gap.
Issue Fit
Both findings are folded in: the enumeration gap is reported under Documentation Check, and one suggestion was dropped under the 🟢 budget.
Verdict
COMMENT — the design is sound and the field names check out, but two of the inclusion list's stat names do not exist in the pinned Envoy build, so a signal the PR promises is silently absent.
Review by Code Guardian 🛡️ · automated code guardian
| ev{"exact": "server.watchdog_miss"}, | ||
| ev{"exact": "server.watchdog_mega_miss"}, |
There was a problem hiding this comment.
🟡 Warning: Envoy v1.37.2 emits no server.watchdog_miss and no server.watchdog_mega_miss, so these two patterns match nothing. The guard dog creates its counters on the root scope under the thread-group name — source/server/instance_impl.cc:26 passes *stats().rootScope(), and source/server/guarddog_impl.cc:50 builds <name>.watchdog_miss from the group name main_thread or workers — so the real names are main_thread.watchdog_miss, main_thread.watchdog_mega_miss, workers.watchdog_miss and workers.watchdog_mega_miss. ALL_SERVER_STATS (source/server/server.h:72) holds no watchdog entry at all. The list excludes the main_thread. and workers. prefixes, so the gateway exports no watchdog counter, while the page and the PR body both state that it exports the aggregate watchdog counters. A stalled event loop on a proxy pinned to two workers is then invisible. Those four series are two per counter type and do not grow with the worker count, so admitting them keeps the bound this PR sets.
Fix: Every pattern in the inclusion list must name a stat the pinned Envoy build emits. Replace the two server.watchdog_* exact patterns with the four real names, and move main_thread.watchdog_miss and workers.watchdog_miss out of the test's dropped list (envoy_test.go:1242).
| ev{"exact": "server.watchdog_miss"}, | |
| ev{"exact": "server.watchdog_mega_miss"}, | |
| ev{"exact": "main_thread.watchdog_miss"}, | |
| ev{"exact": "main_thread.watchdog_mega_miss"}, | |
| ev{"exact": "workers.watchdog_miss"}, | |
| ev{"exact": "workers.watchdog_mega_miss"}, |
| "main_thread.watchdog_miss", | ||
| "workers.watchdog_miss", |
There was a problem hiding this comment.
🟡 Warning: These two lines assert that Envoy's real aggregate watchdog counters are dropped, and line 1231 asserts that server.watchdog_miss — a name Envoy never emits — is admitted. The test therefore passes while no watchdog counter reaches the sink. server.worker_0.watchdog_mega_miss and server.worker_95.watchdog_miss on lines 1240–1241 are not Envoy stat names either: the guard dog aggregates per thread group, never per worker.
Fix: Every name in either list must be one the pinned Envoy build can emit. Move main_thread.watchdog_miss and workers.watchdog_miss to the admitted list, replace server.watchdog_miss on line 1231 with one of them, and remove the two server.worker_N.watchdog_* names.
The inclusion list named `server.watchdog_miss` and `server.watchdog_mega_miss`, which Envoy stopped emitting in 1.16.0 — the aggregate counters moved to the `main_thread.` and `workers.` prefixes, leaving the two `server.` names dead and the watchdog signal absent from the pinned v1.37.2 build. The test compounded it by asserting the real names were dropped. Admit the four aggregate rollups by exact name. They do not scale with worker count; the per-thread `server.worker_N.watchdog_*` series still stay out, and the retired `server.watchdog_miss` name is now pinned as rejected so it cannot return as dead weight. Also enumerate the `listener_manager` gauges and the watchdog rollups in logging.md, which read as a complete list of what the sink admits but named neither. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Tomas Pilar <[email protected]>
dam-code-guardian
left a comment
There was a problem hiding this comment.
🛡️ Code Guardian 🛡️ — ✅ Code Review @ f3c3393
PR #3765: fix(controller): bound the gateway stats the Envoy sink exports
Author: pilartomas | Branch: fix/gateway-stats-volume → main | Changes: +176 −15 (4 files)
Summary
The PR bounds the gateway's stats egress: it pins Envoy's worker concurrency, adds a stats inclusion list, sets a 60s flush interval, and gives the OTLP stats sink a resource detector plus service.name in the relayed environment. The fix commit f3c3393 replaces the two dead server.watchdog_* patterns with the four counters Envoy emits.
Changes since last review
Previous HEAD: d56edee (2026-09-17T14:43:23Z) — verdict COMMENT
- ✅ Fixed: inclusion list names watchdog stats Envoy never emits (
packages/controller/pkg/reconciler/envoy_bootstrap.go:781) - ✅ Fixed: page enumeration omits the listener_manager gauges (
docs/architecture/logging.md:71) - 🆕 New: page transcribes the code's stat list and field names (
docs/architecture/logging.md:71) - 🆕 New: body's gating sentence covers the bootstrap render only (
packages/controller/pkg/reconciler/envoy.go:655) - 🆕 New: HTTP render asserts stats_config only, not the flush interval (
packages/controller/pkg/reconciler/envoy_test.go:1299)
The fix is complete at each location the warning named. The list now admits main_thread.watchdog_miss, main_thread.watchdog_mega_miss, workers.watchdog_miss and workers.watchdog_mega_miss — the names the guard dog builds from its two thread-group names. The four series are two per counter type, so they do not scale with the worker count and the bound the PR sets still holds. The test now asserts those four are admitted and pins the retired server.watchdog_miss as rejected. The page states the same four rollups.
Findings
No findings from the diff review at this HEAD; the three current suggestions are in the skill sections below.
Documentation Check (doc-drift)
- 🟢 Suggestion: The bounded-stat-set bullet transcribes the controller's inclusion list into prose — the admitted families, their literal Envoy scope names (
server.,listener_manager.,main_thread./workers.) and their counts — and it names the tracer's and the sink'sservice_namefield.documentation-guidelines.md:41puts field names and code-level shape on the omit list and asks for a link out instead, so each future pattern added to or removed from the matcher drifts this page. The coupling itself (the sink cannot name itself, soservice.namerides in the relayed environment) is durable and belongs on the page (docs/architecture/logging.md:71).
Issue Fit
- 🟢 Suggestion: The body states that the telemetry-off and the OTLP/HTTP renders both assert no
stats_config/stats_flush_intervalleak in. The OTLP/HTTP test asserts onlystats_config; a later leak of the flush interval into that render fails no test (packages/controller/pkg/reconciler/envoy_test.go:1299). - 🟢 Suggestion: The skill read the body's gating sentence as a claim about the whole change and reported the unconditional
--concurrencyargument as outside it. The sentence sits under theenvoy_bootstrap.goheading and covers the three bootstrap keys, which are gated onp.OTel.Metricsatenvoy_bootstrap.go:137; the concurrency pin is a pod-spec change that the body describes in its own section and in reason 1. The claim holds as written, so this is not a defect. Stating the blast radius per surface — bootstrap render, pod spec, relayed environment — would still remove the ambiguity (packages/controller/pkg/reconciler/envoy.go:655).
Verdict
APPROVE — the warning from the previous round is fixed at every location it named, and only suggestions remain.
Review by Code Guardian 🛡️ · automated code guardian
What
The agent gateway's Envoy stats sink exported every stat Envoy holds, every five seconds, from a proxy whose worker count defaults to the host's core count. This bounds it: pinned worker concurrency, an inclusion list, a one-minute flush, and a resource on the sink so the rows can be told apart.
Why
Four things compound in the current render:
envoyContainersets a 50m CPU request and no CPU limit, and passes no--concurrency. Envoy defaults to hardware concurrency, so one gateway serving one agent spawns a worker per core — dozens on a large node — each with its own buffers, connection pools and stat series.buildEnvoyBootstraprenderedstats_sinkswithgrpc_servicealone, so the sink admitted everything Envoy holds, including the families Envoy creates per worker thread.stats_flush_intervaldefault is 5s — a row per stat, 12 times a minute, per gateway.service_namefield of its own and was given noresource_detectors, so gateway metrics arrived with an empty resource. Every gateway pushed identical stat names with nothing to distinguish them, making the rows unattributable to any gateway — so the volume bought nothing.Point 4 also contradicted what
logging.mdclaimed. Its Bounded cardinality invariant said gateway telemetry shares one trace/metricservice.namewithplatform.gateway.idriding alongside. That held for access logs (explicitresource_attributes) and traces (the tracer's ownservice_nameplus the environment detector), but not for metrics.How
envoy.go--concurrency(pinned toenvoyWorkerConcurrency), sizing the proxy for a single agent's egress rather than for the node.service.nameto the gateway's relayedOTEL_RESOURCE_ATTRIBUTES. The stats sink resolves its resource only from the environment, andOTEL_SERVICE_NAMEis deliberately not relayed (it would carry the controller's identity), so the shared gateway service name has to ride here. The tracer already sets the same value through its own field, so this changes no trace.envoy_bootstrap.gostats_config.stats_matcher.inclusion_listadmitting the families that answer operational questions about a credential-injecting egress proxy —http.(connection manager, including the ext_authz filter stats),tcp.(L4 passthrough tunnels),cluster.(upstream egress),ext_authz.(the network filter),dns_cache.,access_logs.(OTLP log delivery failures), plus a few namedserver.gauges, the twolistener_managergauges, and the four aggregate watchdog counters (themain_thread./workers.rollups, which do not scale with worker count — not the per-threadserver.worker_N.watchdog_*series). Nothing whose series count scales with worker threads: the wholelistener.tree (per-worker stats share that prefix) andserver.worker_N.*.stats_flush_interval: 60s.resource_detectorson the sink, the same environment detector the tracer already uses — which is what makesplatform.gateway.idreach a metric row.All three are gated on
p.OTel.Metrics, so a deployment without gateway metrics renders byte-identical to before.The inline resource-detector literal in
otelTracingis now a sharedotelEnvironmentResourceDetectors()helper, so the tracer and the sink cannot drift apart on the detector they use.logging.md— the Bounded cardinality invariant becomes Bounded cardinality, and a bounded stat set: it now says how each of the three signals resolves its identity (they take three different routes, which is the non-obvious part), what the inclusion list admits, and why concurrency is pinned.Testing
//packages/controller:test,//packages/controller:check,//docs:checkandcheck:comment-typesall pass.New tests in
envoy_test.go:GatewayStatsExcludePerWorkerSeries— evaluates the rendered inclusion list's own matcher semantics against representative stat names, asserting the operational families are admitted and that per-worker/per-thread names (listener.…worker_63.downstream_cx_total,server.worker_95.watchdog_miss,filesystem.*,runtime.*) are not. This tests the matcher's effect rather than pinning a literal, so broadening the list back to a worker-scaled family fails.StatsSinkCarriesGatewayIdentityandGatewayStatsFlushInterval.PinsWorkerConcurrency.stats_config/stats_flush_intervalleaks in.Every field name was verified against the Envoy v1.37.2 proto reference (the pinned image):
Bootstrap.stats_config/stats_flush_interval(default 5000ms; mutually exclusive withstats_flush_on_admin, which is unset),StatsMatcher.inclusion_list,ListStringMatcher.patterns, and the sink'sresource_detectors— which the reference lists…resource_detectors.environmentamong its known extensions, the same registry the tracer draws from.Not verified here
envoy --mode validateagainst the pinned image could not be run — this environment has no registry access and the image isn't cached locally. The render is pinned by the existing YAML-parse test and the field names are checked against the v1.37.2 reference above, but a bad bootstrap field is a fatal Envoy startup error, so it is worth one validate run against the in-cluster binary before rollout:Review round 2
The guardian correctly caught that the list named
server.watchdog_miss/server.watchdog_mega_miss, which Envoy retired in 1.16.0 when the aggregate counters moved to themain_thread.andworkers.prefixes. Both names were dead in the pinned v1.37.2 build, so the watchdog signal this PR claimed was silently absent, and the test compounded it by asserting the real names were dropped. Fixed inf3c3393: the four real rollups are admitted by exact name, and the retiredserver.watchdog_missis now pinned as rejected so it cannot creep back as dead weight.Two judgment calls worth a reviewer's eye:
Assisted-By: Claude (Anthropic AI) [email protected]