Skip to content

fix(controller): bound the gateway stats the Envoy sink exports - #3765

Merged
pilartomas merged 2 commits into
mainfrom
fix/gateway-stats-volume
Sep 17, 2026
Merged

pilartomas merged 2 commits into
mainfrom
fix/gateway-stats-volume

Conversation

@pilartomas

@pilartomas pilartomas commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

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:

  1. Worker count follows the node, not the request. envoyContainer sets 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.
  2. No stats matcher. buildEnvoyBootstrap rendered stats_sinks with grpc_service alone, so the sink admitted everything Envoy holds, including the families Envoy creates per worker thread.
  3. Default flush. Envoy's stats_flush_interval default is 5s — a row per stat, 12 times a minute, per gateway.
  4. No resource on the sink. The sink has no service_name field of its own and was given no resource_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.md claimed. Its Bounded cardinality invariant said gateway telemetry shares one trace/metric service.name with platform.gateway.id riding alongside. That held for access logs (explicit resource_attributes) and traces (the tracer's own service_name plus the environment detector), but not for metrics.

How

envoy.go

  • Pass --concurrency (pinned to envoyWorkerConcurrency), sizing the proxy for a single agent's egress rather than for the node.
  • Add service.name to the gateway's relayed OTEL_RESOURCE_ATTRIBUTES. The stats sink resolves its resource only from the environment, and OTEL_SERVICE_NAME is 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.go

  • stats_config.stats_matcher.inclusion_list admitting 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 named server. gauges, the two listener_manager gauges, and the four aggregate watchdog counters (the main_thread./workers. rollups, which do not scale with worker count — not the per-thread server.worker_N.watchdog_* series). Nothing whose series count scales with worker threads: the whole listener. tree (per-worker stats share that prefix) and server.worker_N.*.
  • stats_flush_interval: 60s.
  • resource_detectors on the sink, the same environment detector the tracer already uses — which is what makes platform.gateway.id reach 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 otelTracing is now a shared otelEnvironmentResourceDetectors() 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:check and check:comment-types all 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.
  • StatsSinkCarriesGatewayIdentity and GatewayStatsFlushInterval.
  • PinsWorkerConcurrency.
  • The telemetry-off and OTLP/HTTP renders now also assert no stats_config/stats_flush_interval leaks 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 with stats_flush_on_admin, which is unset), StatsMatcher.inclusion_list, ListStringMatcher.patterns, and the sink's resource_detectors — which the reference lists …resource_detectors.environment among its known extensions, the same registry the tracer draws from.

Not verified here

envoy --mode validate against 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:

docker run --rm --entrypoint /usr/local/bin/envoy -v <dir>:/cfg:ro \
  mirror.gcr.io/envoyproxy/envoy:distroless-v1.37.2 --mode validate -c /cfg/envoy.yaml

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 the main_thread. and workers. 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 in f3c3393: the four real rollups are admitted by exact name, and the retired server.watchdog_miss is now pinned as rejected so it cannot creep back as dead weight.

Two judgment calls worth a reviewer's eye:

  • Envoy's own docs warn that "excluding stats may affect Envoy's behavior in undocumented ways" (Cluster healthcheck uses wrong interval due to metric filtering envoyproxy/envoy#8771). The admin interface is disabled on these gateways, so the sink is the only stats consumer, which is what makes an inclusion list reasonable here.
  • The list is deliberate, not measured: I could not query the affected store from here to rank the actual top-volume metric names, so it was derived from what this bootstrap renders. If a family outside the list turns out to be load-bearing for someone, adding it back is a one-line change — and the volume reduction does not rest on the list alone, since the concurrency pin and the flush interval each cut it independently.

Assisted-By: Claude (Anthropic AI) [email protected]

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]>
@pilartomas
pilartomas enabled auto-merge (squash) September 17, 2026 14:15
@pilartomas pilartomas added the code-guardian:review Add this label to trigger an automatic review by code-guardian. label Sep 17, 2026

@dam-code-guardian dam-code-guardian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛡️ Code Guardian 🛡️ — ⚠️ Code Review @ 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_detectors field is real at the pinned Envoy v1.37.2 — SinkConfig field 7, whose extension category is the tracer's own detector registry — so the shared otelEnvironmentResourceDetectors() 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, also packages/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

Comment on lines +781 to +782
ev{"exact": "server.watchdog_miss"},
ev{"exact": "server.watchdog_mega_miss"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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).

Suggested change
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"},

Comment on lines +1242 to +1243
"main_thread.watchdog_miss",
"workers.watchdog_miss",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.

@dam-code-guardian dam-code-guardian removed the code-guardian:review Add this label to trigger an automatic review by code-guardian. label Sep 17, 2026
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]>
@pilartomas pilartomas added the code-guardian:review Add this label to trigger an automatic review by code-guardian. label Sep 17, 2026

@dam-code-guardian dam-code-guardian left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛡️ 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's service_name field. documentation-guidelines.md:41 puts 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, so service.name rides 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_interval leak in. The OTLP/HTTP test asserts only stats_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 --concurrency argument as outside it. The sentence sits under the envoy_bootstrap.go heading and covers the three bootstrap keys, which are gated on p.OTel.Metrics at envoy_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

@dam-code-guardian dam-code-guardian removed the code-guardian:review Add this label to trigger an automatic review by code-guardian. label Sep 17, 2026
@pilartomas
pilartomas merged commit a18d52a into main Sep 17, 2026
41 checks passed
@pilartomas
pilartomas deleted the fix/gateway-stats-volume branch September 17, 2026 15:06
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.

2 participants