cluster specifier: support new attempt aware cluster specifier - #46640
cluster specifier: support new attempt aware cluster specifier#46640wbpcode wants to merge 4 commits into
Conversation
Signed-off-by: wbpcode <wbphub@gmail.com>
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
| // envoy.my_filter: | ||
| // priority_groups: | ||
| // - name: remote | ||
| // - name: local |
There was a problem hiding this comment.
The metadata self is extendable and it should be easy to support clusters there if we want per-request level fallback order and traffic distribution.
There was a problem hiding this comment.
For example, the default order and configuration:
priority_groups:
- name: local
- name: a
weight: 20
- name: b
weight: 80
- name: remote
clusters:
- name: c
weight: 20
- name: d
weight: 80
the metadata could be:
envoy.my_filter:
priority_groups:
- name: remote
clusters:
- name: c
weight: 80
- name: d
weight: 20
- name: local
Then, the order will be overridden. And for the specific request, the group remote's clusters traffic distribution also will be overridden, but the group local, it's will use the default distribution.
Signed-off-by: wbpcode <wbphub@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR introduces a new router cluster specifier plugin, envoy.router.cluster_specifier_plugin.priority_group, which selects a priority group based on the request attempt count and then selects a cluster within the group via weighted selection. It integrates the extension into Envoy’s build/metadata systems, adds the v3 API proto, and provides docs + tests.
Changes:
- Added the priority-group cluster specifier plugin implementation with optional per-request overrides via dynamic metadata and optional stable random selection via header or route hash policy.
- Added the v3 API proto and wired it into API build targets and router retry documentation.
- Added extension registration/build integration, user docs, changelog entry, and a comprehensive unit test suite.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
source/extensions/router/cluster_specifiers/priority_group/priority_group_cluster_specifier.h |
Declares the priority-group cluster specifier plugin and metadata parsing entry type. |
source/extensions/router/cluster_specifiers/priority_group/priority_group_cluster_specifier.cc |
Implements attempt-aware group selection, weighted cluster selection, metadata overrides, and refresh-on-retry behavior. |
source/extensions/router/cluster_specifiers/priority_group/config.h |
Declares the factory config for the new extension. |
source/extensions/router/cluster_specifiers/priority_group/config.cc |
Implements factory creation/validation and registers the extension. |
source/extensions/router/cluster_specifiers/priority_group/BUILD |
Adds Bazel targets for the new extension library and config. |
source/extensions/extensions_build_config.bzl |
Registers the extension in the build configuration map. |
source/extensions/extensions_metadata.yaml |
Adds extension metadata (category/status/type URL). |
api/envoy/extensions/router/cluster_specifiers/priority_group/v3/priority_group.proto |
Adds the public v3 API for the new cluster specifier. |
api/envoy/extensions/router/cluster_specifiers/priority_group/v3/BUILD |
Adds the API proto Bazel package definition. |
api/BUILD |
Wires the new API package into the main API proto library deps. |
api/versioning/BUILD |
Wires the new API package into versioning proto deps. |
api/envoy/config/route/v3/route_components.proto |
Updates retry policy docs to include priority-group cluster specifier support for refresh-on-retry. |
docs/root/configuration/http/cluster_specifier/priority_group.rst |
Adds user-facing documentation and an example configuration. |
docs/root/configuration/http/cluster_specifier/cluster_specifier.rst |
Adds the new page to the cluster specifier docs index. |
test/extensions/router/cluster_specifiers/priority_group/priority_group_cluster_specifier_test.cc |
Adds unit tests covering attempt selection, metadata overrides, random-value specifiers, and validation. |
test/extensions/router/cluster_specifiers/priority_group/BUILD |
Adds Bazel test target for the new unit test. |
CODEOWNERS |
Adds owners for the new extension directory. |
changelogs/current/new_features/router__priority-group-cluster-specifier.rst |
Adds a release note for the new feature. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: code <wbphub@gmail.com>
adisuissa
left a comment
There was a problem hiding this comment.
Thanks!
Here's a first-pass on the API
| // <envoy_v3_api_msg_extensions.router.cluster_specifiers.priority_group.v3.PriorityGroup>`. | ||
| message ClusterWeight { | ||
| // Name of the upstream cluster. | ||
| string name = 1 [(validate.rules).string = {min_len: 1}]; |
| // exceeds the number of the available groups, the selection wraps around to the beginning of the | ||
| // list. | ||
| // | ||
| // This plugin supports refreshing the target cluster of the returned route entry, so it could be |
There was a problem hiding this comment.
The description says 'could be used', but I wonder if it should be 'must be used'. What are the cases where 'refresh_cluster_on_retry' should not be set? (consider clarifying this either here or in a the doc)
There was a problem hiding this comment.
When only single priority group is there, then refresh_cluster_on_retry could be unset. Let's me make clarify it clearly.
| // - name: remote_primary | ||
| // weight: 100 | ||
| // | ||
| // With the configuration above, the initial attempt will be routed to ``local_primary`` or |
There was a problem hiding this comment.
From a design point-of-view, wouldn't it be better to use WeightedCluster?
This way even the first attempt request will be routed using the already provided WeightedCluster mechanism. This should avoid adding features in both the original WeightedCluster and this one.
There was a problem hiding this comment.
I guess you means should we reuse the WeightedCluster API as a group? The reason is the WeightedCluster is over complex for our requirements and lots of unnecessary features (like typed_per_filter_configs, request headers to add and so on, these features now should be covered by our upstream HTTP filter rather than be put in the cluster specifier).
| repeated PriorityGroup priority_groups = 1 [(validate.rules).repeated = {min_items: 1}]; | ||
|
|
||
| // Optional dynamic metadata key that is used to override the priority groups on a per-request | ||
| // basis. If this is configured and the referenced dynamic metadata value is a non-empty list, |
There was a problem hiding this comment.
Could the matched list change between retries? For example on the first attempt the metadata selector returns a list containing 3 elements, but on the first retry the matched metadata has only 1 element?
There was a problem hiding this comment.
Yeah. Although not suggested, but yeah. we allow that be updated after every retry so we could use dynamic metadata to customize every attempt
| // is used instead. | ||
| type.metadata.v3.MetadataKey group_override_metadata = 2; | ||
|
|
||
| // The source of the random value that is used to select the target cluster of the selected |
There was a problem hiding this comment.
Isn't selecting the cluster in a weighted-cluster related to a specific group (and not to all the groups)? If so, why isn't this part of PriorityGroup?
There was a problem hiding this comment.
We didn't expect different random value at different retries. A single random value is evaluated once but be used for every attempt (at every PriorityGroup).
So, we put it out of PriorityGroup as shared configuration. If we put it to the PriorityGroup, we need to repeat the same configuration at multiple groups.
Commit Message: cluster specifier: support new attempt aware cluster specifier
Additional Description:
Risk Level:
Testing:
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]