Skip to content

dynamic_modules: add cluster filter-state read ABI#45040

Merged
agrawroh merged 2 commits into
envoyproxy:mainfrom
basundhara-c:cluster-filter-state-abi
May 15, 2026
Merged

dynamic_modules: add cluster filter-state read ABI#45040
agrawroh merged 2 commits into
envoyproxy:mainfrom
basundhara-c:cluster-filter-state-abi

Conversation

@basundhara-c
Copy link
Copy Markdown
Contributor

@basundhara-c basundhara-c commented May 12, 2026

Commit Message: Adds two ABI callbacks so that a dynamic-module cluster's load balancer can read filter state set by an upstream HTTP filter (or any other producer) when picking a host.

Additional Description:

Dynamic-module clusters get two new ABI callbacks (get_filter_state_bytes and get_filter_state_typed) so a custom load balancer can read filter state during host selection. Today the cluster LB side can only see things like SNI and route metadata — it can't reach into filter state that an upstream HTTP filter (or any other producer) attached to the request. With these callbacks, an HTTP filter can compute or look up a value, stash it on filter state, and a downstream dynamic-module cluster can use that value to pick a host.

API shape

Both callbacks mirror the existing HTTP-filter equivalents so module authors see a familiar surface:

  • envoy_dynamic_module_callback_cluster_lb_context_get_filter_state_bytes — reads a Router::StringAccessor-typed value. Returns a view that borrows directly from the request's filter state.
  • envoy_dynamic_module_callback_cluster_lb_context_get_filter_state_typed — reads any registered filter-state object and returns its serializeAsString() bytes.

Risk Level: Low
Testing: Integration test added
Docs Changes: N.A
Release Notes: N.A
Platform Specific Features: N.A

@repokitteh-read-only
Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #45040 was opened by basundhara-c.

see: more, trace.

@basundhara-c
Copy link
Copy Markdown
Contributor Author

/coverage

@repokitteh-read-only
Copy link
Copy Markdown

Coverage for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-cncf-pr/45040/coverage/index.html

For comparison, current coverage on main branch is here:

https://storage.googleapis.com/envoy-cncf-postsubmit/main/coverage/index.html

The coverage results are (re-)rendered each time the CI Envoy/Checks (coverage) job completes.

🐱

Caused by: a #45040 (comment) was created by @basundhara-c.

see: more, trace.

@basundhara-c basundhara-c force-pushed the cluster-filter-state-abi branch 2 times, most recently from b3db1af to 25d45da Compare May 12, 2026 23:44
Adds two ABI callbacks so that a dynamic-module cluster's load balancer
can read filter state set by an upstream HTTP filter (or any other
producer) when picking a host. Today the cluster context only exposes
downstream headers, hash key, override-host, and SNI — filter state was
reachable from the C++ side via ``LoadBalancerContext::requestStreamInfo()
->filterState()`` but not surfaced through the ABI, forcing modules to
fall back to header round-tripping.

ABI additions:

  * envoy_dynamic_module_callback_cluster_lb_context_get_filter_state_bytes
    — reads a ``Router::StringAccessor``-typed filter state value. Mirrors
    the existing HTTP-filter ``get_filter_state_bytes``.
  * envoy_dynamic_module_callback_cluster_lb_context_get_filter_state_typed
    — returns the serialized bytes of a typed filter state object via
    ``serializeAsString``. Mirrors the existing HTTP-filter
    ``get_filter_state_typed``. The serialized buffer is stashed in a
    thread-local string so the returned pointer survives the current
    host-selection callback.

Weak fallback definitions are added alongside the existing cluster-LB
weak stubs in ``source/extensions/dynamic_modules/abi_impl.cc`` so that
binaries that link the Rust SDK without the cluster_lib (e.g. the HTTP
filter integration test) still resolve cleanly.

The Rust SDK gains matching ``ClusterLbContext::get_filter_state_bytes``
and ``ClusterLbContext::get_filter_state_typed`` methods.

Tests:

  * test_data/rust/cluster_filter_state_test.rs — single shared library
    exporting an HTTP filter (``filter_state_producer``) that writes both
    a bytes value and a typed value during ``on_request_headers``, plus a
    cluster (``filter_state_reader``) whose load balancer reads both
    values in ``choose_host`` and only returns its host when both
    round-trip correctly.
  * integration_test.cc registers an ``ObjectFactory`` for the typed key
    and adds ``ReadsFilterStateProducedByHttpFilter``: prepends the
    producer HTTP filter via ``prependFilter``, swaps cluster_0 for the
    reader cluster, and asserts a 200 response — proving the
    filter-state round trip from HTTP filter to cluster host selection.

Signed-off-by: Basundhara Chakrabarty <basundhara17061996@gmail.com>
@basundhara-c basundhara-c force-pushed the cluster-filter-state-abi branch from 25d45da to 4061539 Compare May 13, 2026 00:17
@basundhara-c basundhara-c marked this pull request as ready for review May 13, 2026 07:10
@agrawroh agrawroh assigned agrawroh and wbpcode and unassigned agrawroh May 14, 2026
@kyessenov
Copy link
Copy Markdown
Contributor

Needs main merge.
/wait

…e-abi

# Conflicts:
#	test/extensions/clusters/dynamic_modules/BUILD
#	test/extensions/clusters/dynamic_modules/cluster_test.cc
Copy link
Copy Markdown
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the contribution.

@agrawroh
Copy link
Copy Markdown
Member

/retest

@agrawroh agrawroh enabled auto-merge (squash) May 15, 2026 06:39
@agrawroh agrawroh merged commit 5032a1d into envoyproxy:main May 15, 2026
29 checks passed
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.

4 participants