Repository navigation
feat(backendtrafficpolicy): support targeting Service, ServiceImport, or Backend directly (merged clusters only) - #9816
Conversation
✅ Deploy Preview for cerulean-figolla-1f9435 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 676d0b3446
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Codecov Report❌ Patch coverage is
Additional details and impacted files☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
could we support this without BTP3 could be used across Gateway/GatewayClass, and could be merged/replaced by BTP1 or BTP2 if exists. |
yes, and its also my preference, this feature is independently useful regardless of mergebackends. there was a discussion a few months ago to couple them but i do not remember the details off the top of my head. if the reviewers agree, i can relax this restriction, it would not be a big change on this pull request. |
cc @envoyproxy/gateway-maintainers |
I recall @arkodg had some concerns on this. Users may naturally attach traffic policies to a Backend when they opt to create one cluster per Backend, since that Cluster is shared across multiple route rules. However, if Envoy Gateway creates a separate cluster for each route rule, attaching traffic policies to Routes may feel more intuitive. |
traffic policies attach to Routes take precedence over policies attach to Service. One benififit I could image for this, is we didn't need to expose ClusterSettings to the clusters used by non-Routes(thought we already do these a lot in the past). |
For the following policies at different levels: Note btp-backend says nothing about circuit breakers. The result The result contradicts the intended behavior described in the PR. |
with One more question: What will happen if I have a BTP target to the service used by accesslog(with backendSettings configed), merge or replace? |
|
@zhaohuabing Thanks for flagging this — you found a real bug in how backend-targeted policy interacted with gateway-level policy on the inline (non-merged-cluster) path. It's fixed now, with a golden test ( |
|
@zirain On precedence: the implemented and agreed order, from most specific to least specific, is Backend, then Route, then Gateway — Backend overrides Route, and Route overrides Gateway. This was confirmed with @arkodg, @zhaohuabing, and @guydc in a community meeting on June 25. It also matches Gateway API's own GEP-713 attachment hierarchy, which places Backend as the lowest/most-specific node in the DAG (GatewayClass → Gateway → Route → Backend) — meaning Backend-scoped policy is expected to override Route- and Gateway-scoped policy for whatever fields it sets. Happy to link the exact GEP wording if that's useful for the thread. |
79bacdf to
06eba4b
Compare
this's OK for |
i know we did not support those code paths for MergeBackends feature, i am unsure their status for Backend-BTP, will have to trace the code next week and confirm. but either they are not supported for Backend-BTP or most likely if they are then there is no route there and Backend-BTP just combines with Gateway-BTP for them. but this is just a top off the head response. |
|
/retest |
Signed-off-by: Muhammad Waqar <[email protected]>
…e target backend processBackendTrafficPolicyForBackend iterated every gateway and reported a Disabled ancestor for any of them with mergeBackends off, regardless of whether that gateway's IR referenced the policy's target backend at all. In a cluster with many gateways this could displace real ancestor entries once the 16-ancestor cap kicks in. Add gatewayReferencesBackend and only check it inside the mergeBackends-disabled branch, so the common (enabled) path doesn't pay for a second walk over the same IR the walks below it already traverse. Found by Codex review on envoyproxy#9816. Signed-off-by: Muhammad Waqar <[email protected]>
…rotocol processBackendTrafficPolicyForBackend copied the full ClusterTrafficFeatures onto every matching merged cluster regardless of its protocol, so HTTP-only fields (healthCheck, http2, admissionControl, ...) could leak onto a udp_proxy/tcp_proxy cluster. Reuse applyGatewayPolicyToMergedCluster, which already subsets correctly per protocol for the whole-gateway BTP path (added in envoyproxy#10016 for the same bug class). Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Muhammad Waqar <[email protected]>
…icy's targets A multi-targetRefs backend-targeted BackendTrafficPolicy had each target write Accepted/Conflicted/Disabled status directly and independently to the same policy.Status, with no coordination between targets sharing an ancestor. SetResolveErrorForPolicyAncestors (used for Conflicted/Disabled/ Invalid) has no guard against overwriting an already-set Accepted condition, unlike SetAcceptedForPolicyAncestor - so whichever target was processed last for a shared ancestor won, and in the worst order a genuinely Accepted result could be silently clobbered by an unrelated target's Conflicted/Disabled/error outcome for the same ancestor. Split processBackendTrafficPolicyForBackend into a pure per-target resolver (now returns a backendTargetOutcome instead of writing status) and a new processBackendTargetedPolicies wrapper that owns the per-policy loop over targets, aggregates accepted/merged/failed outcomes across all of a policy's targets, then commits one status entry per ancestor - walking gateways in their given order for a deterministic result, and never regressing an ancestor another target already got accepted for. Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Muhammad Waqar <[email protected]>
…eded Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Muhammad Waqar <[email protected]>
…us message Per envoyproxy#9816 (comment): backend targeting only resolves targetRef/targetRefs (resolvePolicyTargetsFromReferences), so a BackendTrafficPolicy using targetSelectors with kind Service/ServiceImport/Backend was previously accepted by the API and then silently had no effect, with no status feedback. Rejects it in Go instead of CEL, avoiding the CEL cost-budget problem a dedicated rejection rule would hit (api/v1alpha1/backendtrafficpolicy_types.go already has two rules traversing the shared TargetSelectors field, and a third pushes the CRD over budget). Resolves the selector against live Service/ServiceImport/Backend objects purely to find which ancestor Gateways to report a resolve error to - the same resolvePolicyTargetsFromSelectors function already used for Gateway/ListenerSet selector targeting elsewhere, not a new mechanism - the match is never applied. Real selector support is tracked as a follow-up: envoyproxy#10212 Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Muhammad Waqar <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…pattern The multi-targetRefs status aggregation added in 892a4fd was not one of zirain's three blocking comments (protocol subsetting, MergeGateways, targetSelectors) - it was a secondary comment this session chose to fix proactively. On reflection, it introduced bespoke behavior found nowhere else in this file: all six other BackendTrafficPolicy target-kind sections (RouteRule, Route, ListenerSet Listener, ListenerSet, Gateway Listener, Gateway) write status directly per-target with no aggregation across a policy's multiple targets, accepting the same "last processed wins" ordering this aggregation tried to fix only for backend targeting. Reverts processBackendTrafficPolicyForBackend to writing status directly (keeping the unrelated protocol-subsetting fix from 557e4d7), removes processBackendTargetedPolicies/backendTargetOutcome/backendTargetFailure, and restores the plain per-target loop in ProcessBackendTrafficPolicies - matching the other six sections' exact shape. rejectBackendTargetSelectors now writes status directly too, for the same reason. Tracked as a cross-cutting follow-up covering all seven sections, not a backend-targeting-specific fix: envoyproxy#10214 Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Muhammad Waqar <[email protected]>
Fixes a prealloc lint failure in CI. Co-Authored-By: Claude Sonnet 5 <[email protected]> Signed-off-by: Muhammad Waqar <[email protected]>
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
|
Codex Review: Something went wrong. Try again later by commenting “@codex review”. ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@zirain @zhaohuabing This should be ready for re-review now:
Would appreciate a re-review and +1 when you get a chance. Thanks for your patience on this one! |
|
/retest |
guydc
left a comment
There was a problem hiding this comment.
LGTM! Thanks for this fantastic work!
…-scoped field errors A BackendTrafficPolicy's cluster-scoped settings (circuit breaker, load balancer, timeout, etc.) failed to apply to a merged backend cluster whenever any route-scoped field (e.g. a broken rateLimit) failed to translate, even though the cluster-scoped fields themselves were valid. This affected both the whole-Gateway BTP path and the backend-targeted BTP merge path added in envoyproxy#9816. Extract buildClusterTrafficFeatures to build and error on only the cluster-scoped subset, and gate cluster application on that error instead of the combined one. Fixes envoyproxy#10210 Signed-off-by: Muhammad Waqar <[email protected]>
…-scoped field errors (#10234) * fix(backendtrafficpolicy): isolate cluster-scoped settings from route-scoped field errors A BackendTrafficPolicy's cluster-scoped settings (circuit breaker, load balancer, timeout, etc.) failed to apply to a merged backend cluster whenever any route-scoped field (e.g. a broken rateLimit) failed to translate, even though the cluster-scoped fields themselves were valid. This affected both the whole-Gateway BTP path and the backend-targeted BTP merge path added in #9816. Extract buildClusterTrafficFeatures to build and error on only the cluster-scoped subset, and gate cluster application on that error instead of the combined one. Fixes #10210 Signed-off-by: Muhammad Waqar <[email protected]> * gatewayapi: generalize comment to route-scoped field, not just RateLimit Signed-off-by: Muhammad Waqar <[email protected]> --------- Signed-off-by: Muhammad Waqar <[email protected]> Co-authored-by: zirain <[email protected]>
What this PR does / why we need it:
BackendTrafficPolicycan now target aService,ServiceImport, orBackenddirectly, instead of only aGateway,Listener, or route.Today, applying a setting like a circuit breaker or health check to every route that talks to a given backend means attaching (and keeping in sync) the same
BackendTrafficPolicyon every route that references it, or setting it broadly at the Gateway level and accepting that it applies to everything else too. With this change, you attach the policy once, directly to the backend, and it applies wherever that backend resolves to a merged Envoy cluster (via theMergeBackendsfeature) - no matter how many routes or gateways reference it - without touching the routes themselves.What you get:
Service,ServiceImport, orBackendwithspec.targetRefs.ConsistentHashload balancing is rejected for backend-targeted policies: Envoy's hash policy for weighted-cluster selection is route-scoped and singular, so it doesn't make sense for different backends in the same weighted route to each request a different hash input.Scope note: this policy applies only to backends that actually resolve into a shared, merged Envoy cluster. A backend that never merges for any reason (a fallback backend, session persistence, per-listener
ClusterSettingsdivergence, a dynamic resolver, etc.) silently does not get the policy applied - no error, no warning. An earlier iteration of this PR also supported applying the policy to non-merged/inline backends, plus a route-vs-backend precedence resolution for that case; that inline path kept surfacing correctness hazards (most recently, a route-scopedConsistentHashpolicy demerging via a mechanism a same-day guard had already missed once), so it was removed in favor of this smaller, unconditionally-correct surface. See muwaqar#12 for a reference-only copy of the removed inline work.Requires
mergeTypeto be set on the policy, and theMergeBackendsfeature enabled on theEnvoyProxyresource for the Gateway(s) involved.Which issue(s) this PR fixes:
Fixes #8844
PR Checklist
git commit -s)./api(backend-targeting support onBackendTrafficPolicy, plus a CEL rule rejectingConsistentHashfor backend targets). Tracked by Backend-level policy for CDS configuration #8844; not otherwise pre-agreed with maintainers beyond that issue.make generate gen-check,go build ./...,go vet ./...,go test ./..., andmake go.test.celall pass locally.internal/gatewayapiandinternal/xds/translator, plus CEL validation test cases.site/docs update included in this PR yet.release-notes/current/new_features/.make gen-checkclean.