Skip to content

stats: strip inner custom namespaces in prometheus names#45065

Open
yueshangzuo wants to merge 1 commit into
envoyproxy:mainfrom
yueshangzuo:fix/scoped-custom-namespace-prometheus
Open

stats: strip inner custom namespaces in prometheus names#45065
yueshangzuo wants to merge 1 commit into
envoyproxy:mainfrom
yueshangzuo:fix/scoped-custom-namespace-prometheus

Conversation

@yueshangzuo
Copy link
Copy Markdown
Contributor

Commit Message:
stats: strip inner custom namespaces in prometheus names

The Prometheus formatter only stripped a registered custom stat namespace when it was the leading segment of the tag-extracted name. This worked for listener/root-scoped Wasm custom stats but not for upstream Wasm stats scoped under a cluster, where after tag extraction the namespace ends up in the middle (e.g. cluster.wasmcustom.foo), producing names like envoy_cluster_wasmcustom_foo.

Add CustomStatNamespaces::stripRegisteredInnerNamespace() and call it from the Prometheus formatter to strip a registered namespace appearing as a non-leading, non-trailing segment, without hard-coding wasmcustom or a specific scope depth. Gated by envoy.reloadable_features.strip_scoped_custom_stat_namespace (default true).

Additional Description:
The existing leading-prefix custom namespace behavior is unchanged. This aligns upstream Wasm custom stats with listener/root-scoped Wasm custom stats and native cluster metrics without hard-coding wasmcustom or a specific scope depth in the Prometheus formatter.

This PR was prepared with assistance from generative AI; the code and behavior were reviewed and tested by the author.

Risk Level:
Medium

Testing:
Added unit coverage for custom namespace inner-segment stripping and Prometheus formatting, including nested scope names, runtime guard disabled behavior, leading-prefix behavior, unregistered namespaces, and full Prometheus text output.

Docs Changes:
N/A

Release Notes:
See changelogs/current.yaml.

Platform Specific Features:
N/A

[Optional Runtime guard:]
envoy.reloadable_features.strip_scoped_custom_stat_namespace

[Optional API Considerations:]
Adds a new pure virtual method stripRegisteredInnerNamespace() to Stats::CustomStatNamespaces. The interface is internal to the stats subsystem and only one production implementation exists (CustomStatNamespacesImpl); no mocks override it, so impact is contained to this PR.

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #45065 was opened by yueshangzuo.

see: more, trace.

@yueshangzuo yueshangzuo force-pushed the fix/scoped-custom-namespace-prometheus branch from 6d90b33 to 8c3fbaf Compare May 15, 2026 02:41
The Prometheus formatter only stripped a registered custom stat
namespace when it was the leading segment of the tag-extracted name.
This worked for listener/root-scoped Wasm custom stats but not for
upstream Wasm stats scoped under a cluster, where after tag extraction
the namespace ends up in the middle (e.g. `cluster.wasmcustom.foo`),
producing names like `envoy_cluster_wasmcustom_foo`.

Add `CustomStatNamespaces::stripRegisteredInnerNamespace()` and call it
from the Prometheus formatter to strip a registered namespace appearing
as a non-leading, non-trailing segment, without hard-coding `wasmcustom`
or a specific scope depth. Gated by
`envoy.reloadable_features.strip_scoped_custom_stat_namespace`
(default true).

Signed-off-by: Yueshang zuo <zuoyueshang.zys@alibaba-inc.com>
@yueshangzuo yueshangzuo force-pushed the fix/scoped-custom-namespace-prometheus branch from 8c3fbaf to e2cb747 Compare May 15, 2026 03:42
@yueshangzuo
Copy link
Copy Markdown
Contributor Author

/retest

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.

1 participant