Skip to content

wasm: use root stats scope for upstream filter stats#45242

Merged
kyessenov merged 1 commit into
envoyproxy:mainfrom
yueshangzuo:fix/upstream-wasm-root-scope
Jun 15, 2026
Merged

wasm: use root stats scope for upstream filter stats#45242
kyessenov merged 1 commit into
envoyproxy:mainfrom
yueshangzuo:fix/upstream-wasm-root-scope

Conversation

@yueshangzuo

@yueshangzuo yueshangzuo commented May 25, 2026

Copy link
Copy Markdown
Contributor

Supersedes #45065. Implements the root-scope approach surfaced in that review discussion.

Commit Message:
wasm: use root stats scope for upstream filter stats

Additional Description:
Upstream HTTP Wasm filter stats currently use the cluster stats scope, while downstream HTTP Wasm filter stats use the root scope. This makes the same Wasm metric name produce different stat names depending on whether the plugin is loaded as a downstream or upstream filter.

This changes upstream HTTP Wasm filter stats to use the server-wide root stats scope by default, matching the downstream filter. In Prometheus, a counter previously exposed as envoy_cluster_wasmcustom_foo{envoy_cluster_name="X"} is now exposed as foo. The previous cluster-scope behavior can be temporarily restored with the envoy.reloadable_features.upstream_wasm_filter_uses_root_scope runtime guard set to false.

Risk Level: Medium

Testing:

  • git diff --check
  • bazel test -c dbg //test/extensions/filters/http/wasm:config_test
  • bazel build -c dbg envoy
  • Manual Envoy smoke test with upstream Wasm stats and runtime-guard rollback.

Docs Changes: N/A

Release Notes: Added in changelogs/current/minor_behavior_changes/wasm__upstream-http-wasm-stats-use-root-scope.rst.

Platform Specific Features: N/A

[Optional Runtime guard:]
envoy.reloadable_features.upstream_wasm_filter_uses_root_scope, defaults to true. Set to false to restore the previous upstream Wasm cluster-scope stats behavior.

[Optional Fixes #Issue:] N/A

[Optional Deprecated:] N/A

[Optional API Considerations:] N/A

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

@yueshangzuo yueshangzuo requested a review from kyessenov as a code owner May 25, 2026 11:18
@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: #45242 was opened by yueshangzuo.

see: more, trace.

@yueshangzuo

Copy link
Copy Markdown
Contributor Author

@kyessenov Gentle ping when you get a chance. This PR implements the root-scope approach discussed in #45065.

@kyessenov kyessenov 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.

Looks close, but I think test could be better.

Upstream HTTP Wasm filter stats now use the server-wide root stats scope instead of the
cluster stats scope, matching downstream HTTP Wasm filter scoping. Upstream Wasm custom metrics
no longer carry a ``cluster.<cluster_name>.`` prefix; for example a counter previously exposed as
``envoy_cluster_wasmcustom_foo{envoy_cluster_name="X"}`` is now ``foo``. Plugins that need

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.

Is it wasmcustom_foo or just foo? I think the prefix still applies?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done — split admin /stats vs Prometheus output to clarify the prefix behavior.

EXPECT_NE(nullptr,
TestUtility::findCounter(upstream_factory_context_.server_factory_context_.store_,
lifecycle_counter));
EXPECT_EQ(nullptr,

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.

This should be a positive test, e.g. please spell out the full path for the stat.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@kyessenov kyessenov self-assigned this May 27, 2026
@yueshangzuo yueshangzuo force-pushed the fix/upstream-wasm-root-scope branch from 7b6f121 to fd15232 Compare May 28, 2026 02:49
@yueshangzuo

Copy link
Copy Markdown
Contributor Author

/retest

@yueshangzuo yueshangzuo force-pushed the fix/upstream-wasm-root-scope branch from fd15232 to aa2f87d Compare May 28, 2026 05:40
@yueshangzuo

Copy link
Copy Markdown
Contributor Author

/retest

@yueshangzuo

Copy link
Copy Markdown
Contributor Author

@kyessenov Friendly ping — addressed both review comments in the latest push.

@KBaichoo

Copy link
Copy Markdown
Contributor

PTAL @kyessenov

@kyessenov kyessenov 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.

Minor comment to improve test. LMK.
/wait

const auto counter = TestUtility::findCounter(
upstream_factory_context_.server_factory_context_.store_, full_stat_name);
ASSERT_NE(nullptr, counter);
}

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.

This should be a positive test, e.g. please spell out the full path for the stat.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated with a positive check using the full literal stat path.

Upstream HTTP Wasm filter stats currently use the cluster stats scope,
while downstream HTTP Wasm filter stats use the server-wide root scope. This
causes upstream custom metrics to inherit the cluster prefix and Prometheus
cluster label, even though Wasm extension stats should be scoped consistently
across downstream and upstream filters.

Use the server-wide root stats scope for upstream HTTP Wasm filter stats and
keep the old cluster-scope behavior behind the
envoy.reloadable_features.upstream_wasm_filter_uses_root_scope runtime guard.
Setting the guard to false temporarily reverts to the previous behavior.

Signed-off-by: Yueshang zuo <zuoyueshang.zys@alibaba-inc.com>
@yueshangzuo yueshangzuo force-pushed the fix/upstream-wasm-root-scope branch from aa2f87d to 17f851f Compare June 15, 2026 04:02
@yueshangzuo

Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@yueshangzuo

Copy link
Copy Markdown
Contributor Author

/retest

@kyessenov kyessenov merged commit ed71488 into envoyproxy:main Jun 15, 2026
27 of 28 checks passed
nezdolik pushed a commit to nezdolik/envoy that referenced this pull request Jun 16, 2026
Supersedes envoyproxy#45065. Implements the root-scope approach surfaced in that
review discussion.

Commit Message:
wasm: use root stats scope for upstream filter stats

Additional Description:
Upstream HTTP Wasm filter stats currently use the cluster stats scope,
while downstream HTTP Wasm filter stats use the root scope. This makes
the same Wasm metric name produce different stat names depending on
whether the plugin is loaded as a downstream or upstream filter.

This changes upstream HTTP Wasm filter stats to use the server-wide root
stats scope by default, matching the downstream filter. In Prometheus, a
counter previously exposed as
`envoy_cluster_wasmcustom_foo{envoy_cluster_name="X"}` is now exposed as
`foo`. The previous cluster-scope behavior can be temporarily restored
with the
`envoy.reloadable_features.upstream_wasm_filter_uses_root_scope` runtime
guard set to `false`.

Risk Level: Medium

Testing:
- `git diff --check`
- `bazel test -c dbg //test/extensions/filters/http/wasm:config_test`
- `bazel build -c dbg envoy`
- Manual Envoy smoke test with upstream Wasm stats and runtime-guard
rollback.

Docs Changes: N/A

Release Notes: Added in
`changelogs/current/minor_behavior_changes/wasm__upstream-http-wasm-stats-use-root-scope.rst`.

Platform Specific Features: N/A

[Optional Runtime guard:]
`envoy.reloadable_features.upstream_wasm_filter_uses_root_scope`,
defaults to true. Set to false to restore the previous upstream Wasm
cluster-scope stats behavior.

[Optional Fixes #Issue:] N/A

[Optional Deprecated:] N/A

[Optional API Considerations:] N/A

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

Signed-off-by: Yueshang zuo <zuoyueshang.zys@alibaba-inc.com>
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.

3 participants