Skip to content

Fix weighted cluster generation in RouteAction when URLRewrite filter is applied#7027

Merged
arkodg merged 3 commits intoenvoyproxy:mainfrom
sekar-saravanan:fix-incorrect-cluster-mapping
Sep 23, 2025
Merged

Fix weighted cluster generation in RouteAction when URLRewrite filter is applied#7027
arkodg merged 3 commits intoenvoyproxy:mainfrom
sekar-saravanan:fix-incorrect-cluster-mapping

Conversation

@sekar-saravanan
Copy link
Copy Markdown
Contributor

What type of PR is this?
Bug Fix

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #7019

Release Notes: No

@sekar-saravanan sekar-saravanan requested a review from a team as a code owner September 22, 2025 09:54
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.01%. Comparing base (2b1f351) to head (082bf42).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7027   +/-   ##
=======================================
  Coverage   71.00%   71.01%           
=======================================
  Files         226      226           
  Lines       40302    40308    +6     
=======================================
+ Hits        28617    28625    +8     
+ Misses       9991     9989    -2     
  Partials     1694     1694           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@rudrakhp rudrakhp left a comment

Choose a reason for hiding this comment

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

Can we add a XDS translator test for this usecase? Ensure to run make -k gen-check after adding an input test.

…ction when URLRewrite filter is applied

Signed-off-by: Sekar Saravanan <[email protected]>
Copy link
Copy Markdown
Member

@rudrakhp rudrakhp left a comment

Choose a reason for hiding this comment

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

LGTM, will be good to add an E2E as well. Eg here. We can take it up in a separate PR as well.

router.Action = &routev3.Route_Redirect{Redirect: buildXdsRedirectAction(httpRoute)}
case httpRoute.URLRewrite != nil:
routeAction := buildXdsURLRewriteAction(httpRoute.Destination.Name, httpRoute.URLRewrite, httpRoute.PathMatch)
routeAction := buildXdsURLRewriteAction(httpRoute, httpRoute.URLRewrite, httpRoute.PathMatch)
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 code looks identical to default now, can we instead fallthrough with a comment says logic is same

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.

I think it would be better to use a separate method to configure the additional attributes for routeAction.

@arkodg arkodg merged commit b97f1a1 into envoyproxy:main Sep 23, 2025
32 checks passed
zirain pushed a commit to zirain/gateway that referenced this pull request Oct 1, 2025
… is applied (envoyproxy#7027)

* Fix weighted cluster generation in RouteAction when URLRewrite filter is applied

Signed-off-by: Sekar Saravanan <[email protected]>

* XDS translator test added - Fix weighted cluster generation in RouteAction when URLRewrite filter is applied

Signed-off-by: Sekar Saravanan <[email protected]>

---------

Signed-off-by: Sekar Saravanan <[email protected]>
Signed-off-by: zirain <[email protected]>
@zirain zirain mentioned this pull request Oct 2, 2025
33 tasks
zirain added a commit that referenced this pull request Oct 3, 2025
* rm DeepCopy from Status Updator (#6986)

* Use Shallow Copy for TypedMeta, ObjectMeta and Spec
which are read only fields during the status update

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: avoid string concatenation overhead of fmt.Sprintf in Sort (#6987)

~14% improvement in CPU

```
 benchstat old.txt new.txt
goos: darwin
goarch: amd64
pkg: github.com/envoyproxy/gateway/test/gobench
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
                          │   old.txt    │                new.txt                │
                          │    sec/op    │    sec/op     vs base                 │
GatewayAPItoXDS/small-12    4.257m ± ∞ ¹   2.707m ± ∞ ¹        ~ (p=0.700 n=3) ²
GatewayAPItoXDS/medium-12   37.32m ± ∞ ¹   34.76m ± ∞ ¹        ~ (p=1.000 n=3) ²
GatewayAPItoXDS/large-12    409.5m ± ∞ ¹   437.1m ± ∞ ¹        ~ (p=1.000 n=3) ²
geomean                     40.22m         34.52m        -14.17%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

                          │    old.txt    │                new.txt                │
                          │     B/op      │     B/op       vs base                │
GatewayAPItoXDS/small-12    721.7Ki ± ∞ ¹   722.4Ki ± ∞ ¹       ~ (p=0.700 n=3) ²
GatewayAPItoXDS/medium-12   15.63Mi ± ∞ ¹   15.63Mi ± ∞ ¹       ~ (p=0.100 n=3) ²
GatewayAPItoXDS/large-12    151.3Mi ± ∞ ¹   151.3Mi ± ∞ ¹       ~ (p=1.000 n=3) ²
geomean                     11.86Mi         11.86Mi        +0.04%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

                          │   old.txt    │               new.txt                │
                          │  allocs/op   │  allocs/op    vs base                │
GatewayAPItoXDS/small-12    11.70k ± ∞ ¹   11.71k ± ∞ ¹       ~ (p=0.700 n=3) ²
GatewayAPItoXDS/medium-12   257.3k ± ∞ ¹   257.3k ± ∞ ¹       ~ (p=0.700 n=3) ²
GatewayAPItoXDS/large-12    2.467M ± ∞ ¹   2.467M ± ∞ ¹       ~ (p=0.200 n=3) ²
geomean                     195.1k         195.2k        +0.03%
```

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: improve mem allocation in TruncatePolicyAncestors (#6998)

* perf: improve mem allocation in TruncatePolicyAncestors

Relates to #6919

Signed-off-by: Arko Dasgupta <[email protected]>

* lint

Signed-off-by: Arko Dasgupta <[email protected]>

* also sort on ns before name

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: reuse route rule metadata (#7001)

* perf: reuse route rule metadata

* build it once and pass it in the caller
* also since EG annotations are rare, make
sure to return early and reduce allocations

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: reduce mem allocs in internal/metrics (#7004)

```
                         │   old.txt    │       new.txt       │
                         │    sec/op    │    sec/op     vs base   │
  MergeLabelValuesOld-12   354.6n ± 42%
  MergeLabelValuesNew-12                  131.6n ± 18%

                         │  old.txt   │      new.txt      │
                         │    B/op    │    B/op     vs base   │
  MergeLabelValuesOld-12   640.0 ± 0%
  MergeLabelValuesNew-12                320.0 ± 0%

                         │  old.txt   │      new.txt      │
                         │ allocs/op  │ allocs/op   vs base   │
  MergeLabelValuesOld-12   2.000 ± 0%
  MergeLabelValuesNew-12                1.000 ± 0%
```

Signed-off-by: Arko Dasgupta <[email protected]>
Co-authored-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: aggregate publish metric counts and call once (#7005)

* Reduces calls from O(N) where N is the total number of resources to O(1)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: avoid loop variable in k8s provider (#7010)

* reduces heap allocs
* also removes the copyloopvar lint error

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: remove reflect from BackendRefContext (#7015)

* similar to #6820

```
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5002508	       239.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4764154	       264.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4866708	       238.6 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 5032014	       243.8 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_HTTPBackendRef-12             	 4935594	       259.5 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4833061	       245.3 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4970496	       252.1 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4517140	       253.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 4556660	       273.4 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_Old_GRPCBackendRef-12             	 5003169	       244.2 ns/op	     152 B/op	       3 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2495 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2499 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2576 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_HTTPBackendRef-12             	1000000000	         0.2556 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2505 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2504 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2591 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2502 ns/op	       0 B/op	       0 allocs/op
  BenchmarkBackendRefContext_New_GRPCBackendRef-12             	1000000000	         0.2483 ns/op	       0 B/op	       0 allocs/op
  ```

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* rm reflect from gateway api runner (#7012)

* use length check instead of a relfect
  `ValueOf(backend.Status).IsZero()` check

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: lazy allocation for new condition in SetConditionForPolicyAncestor (#6999)

* only create a new condition when we need to i.e. when it doesnt
  already exist

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* Fix weighted cluster generation in RouteAction when URLRewrite filter is applied (#7027)

* Fix weighted cluster generation in RouteAction when URLRewrite filter is applied

Signed-off-by: Sekar Saravanan <[email protected]>

* XDS translator test added - Fix weighted cluster generation in RouteAction when URLRewrite filter is applied

Signed-off-by: Sekar Saravanan <[email protected]>

---------

Signed-off-by: Sekar Saravanan <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: use SDS for service account token in Gateway Namespace Mode (#7002)

* use sds config for credential injector

Signed-off-by: Karol Szwaj <[email protected]>

* check for token review status error

Signed-off-by: Karol Szwaj <[email protected]>

* use sds config for credential injector

Signed-off-by: Karol Szwaj <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: reduce ancestorRef copies in policy status (#7032)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: preallocate structs in securitypolicy processing (#7039)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: remove reflect.DeepCopy in parentRef comparison (#7040)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: escape regex metacharacters from path prefix string (#7024)

Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: convert mockData into string and reuse in lua (#7078)

Signed-off-by: Arko Dasgupta <[email protected]>
Co-authored-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: make sets when needed in policy processing (#7076)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: preallocate slices in route processing (#7041)

* perf: preallocate slices in route processing

Signed-off-by: Arko Dasgupta <[email protected]>

* use index

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: enable gocritic perfomance linter setting (#7056)

https://go-critic.com/overview#checkers-from-the-performance-group

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: avoid JSON Marshal when debug logger is disabled (#7066)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: avoid YAML to JSON conversion in JSONPatch (#7069)

* Use value.Raw directly

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* Fix: Preserve route parent status for multi-parent routes (#7068)

* fix: preserve route parent statuses during merge

Routes with multiple parent references should maintain status for all
parents, not just the one being currently updated. The mergeRouteParentStatus
function was incorrectly removing parent statuses when they weren't in the
current update batch.

This change preserves all existing parent statuses during the merge operation,
ensuring routes with multiple parents maintain status for all parent refs.

Fixes #7067

Signed-off-by: rajsinghtech <[email protected]>
Signed-off-by: Raj Singh <[email protected]>

* fix: remove unused controllerName parameter and update tests

- Remove unused controllerName parameter from mergeRouteParentStatus function
- Update test expectations to match the new behavior where all parent
  statuses are preserved during merge operations
- This ensures routes with multiple parent references maintain status
  for all parents, not just the ones being currently updated

Signed-off-by: rajsinghtech <[email protected]>
Signed-off-by: Raj Singh <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: remove watchable LoadAll() from gateway api runner (#7081)

* perf: remove watchable LoadAll() from gateway api runner

* use a keyCache in the gateway-api runner instead of
making an expensive LoadAll() call thats copies all the statuses and IRs
on every subscribe adding a ton of pressure for GC

* use the same mark and sweep operation to clean up the key cache and
  watchable store

* make a one time LoadAll() call in runner Start() to populate the cache
  for the restart runner case (when EnvoyGateway config is updated)

Signed-off-by: Arko Dasgupta <[email protected]>

* fix tests

Signed-off-by: Arko Dasgupta <[email protected]>

* fix test

Signed-off-by: Arko Dasgupta <[email protected]>

* rm populateCache, not needed

since we restart runners and reset watchable messages
https://github.com/envoyproxy/gateway/blob/d973842ea2f948a7d6eb2163e8ecc6950b49ae3d/internal/cmd/server.go#L65

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: enable prealloc linter (#7055)

* perf: enable prealloc linter

* and fix all the warnings

Fixes: #7053

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: pre allocate maps in btp processing (#7050)

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: fix possible memory leak in XDS snapshot (#7101)

perf: fix possible mem leak in XDS snapshot

Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: zirain <[email protected]>

* perf: direct assign policies in translate result instead of append (#7077)

* perf: direct assign policies in translate result instead of append

Signed-off-by: Arko Dasgupta <[email protected]>

* fix test

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* remove redundant file

Signed-off-by: zirain <[email protected]>

* fix: do not add same service multiple times (#7119)

Signed-off-by: zirain <[email protected]>

* fix: use maps for backendRefMappings instead of Sets (#7120)

* fix: use maps for backendRefMappings instead of Sets

* Sets compare by value and BackendRef contain multiple ptrs to Kind,
  Group and Namespace, so this Set didnt really serve us any good
  purpose of deduping same backendRefs
* Instead use maps keyed by a util string - NamespaceNameWithGroupKind
similar to what we use for ExtentionRefFilters

Signed-off-by: Arko Dasgupta <[email protected]>

* make key a ptr

Signed-off-by: Arko Dasgupta <[email protected]>

* fix test

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* bug: disable x-envoy-ratelimited by default (#7110)

* bug: disable x-envoy-ratelimited by default

* can be enabled with `enableEnvoyHeaders` in CTP

Relates to #7034

Signed-off-by: Arko Dasgupta <[email protected]>

* fix tests and release note

Signed-off-by: Arko Dasgupta <[email protected]>

* fix testdata

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

* fix: use lock when accessing mergeGateways Set (#7124)

* fix: use lock when accessing mergeGateways Set

* accessed in multiple goroutines to map proxy fleet to resource via
  labels

Fixes this panic

```
fatal error: concurrent map read and map write

   4 internal/runtime/maps.fatal({0x3b83570?, 0x8b3de58?})
   5     /opt/hostedtoolcache/go/1.24.7/x64/src/runtime/panic.go:1058 +0x18
   6 k8s.io/apimachinery/pkg/util/sets.Set[...[].Has(...)
   7     /home/runner/go/pkg/mod/k8s.io/[email protected]/pkg/util/sets/set.go:78
   8 github.com/envoyproxy/gateway/internal/provider/kubernetes.(*gatewayAPIReconciler).envoyObjectForGateway.func1({0x8bc2dc8, 0xc0054163f0})
   9     /home/runner/work/gateway/gateway/internal/provider/kubernetes/predicates.go:666 +0x7b
  10 github.com/envoyproxy/gateway/internal/provider/kubernetes.(*gatewayAPIReconciler).envoyObjectForGateway(0xc0018858e8?, {0x8ba6648?, 0xc0009c8b90?}, 0x11?)
  11     /home/runner/work/gateway/gateway/internal/provider/kubernetes/predicates.go:682 +0x5e
  12 github.com/envoyproxy/gateway/internal/provider/kubernetes.(*gatewayAPIReconciler).updateStatusForGateway(0xc000516600, {0x8ba6648, 0xc0009c8b90}, 0xc00541a380)
  13     /home/runner/work/gateway/gateway/internal/provider/kubernetes/status.go:579 +0x5a
  14 github.com/envoyproxy/gateway/internal/provider/kubernetes.(*gatewayAPIReconciler).subscribeAndUpdateStatus.func2.1({{{0xc0096a7e46, 0x7}, {0xc001944cc0, 0x11}}, 0x0, 0xc0052fa690}, 0xc00a582a1     0)
```

Relates to #7115 (comment)

Signed-off-by: Arko Dasgupta <[email protected]>

* lint

Signed-off-by: Arko Dasgupta <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>

---------

Signed-off-by: Arko Dasgupta <[email protected]>
Signed-off-by: zirain <[email protected]>
Signed-off-by: Sekar Saravanan <[email protected]>
Signed-off-by: Karol Szwaj <[email protected]>
Signed-off-by: Rudrakh Panigrahi <[email protected]>
Signed-off-by: rajsinghtech <[email protected]>
Signed-off-by: Raj Singh <[email protected]>
Co-authored-by: Arko Dasgupta <[email protected]>
Co-authored-by: Rudrakh Panigrahi <[email protected]>
Co-authored-by: sekar-saravanan <[email protected]>
Co-authored-by: Karol Szwaj <[email protected]>
Co-authored-by: Raj Singh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Cluster Mapping in Route Config When adding URLRewrite Filter

4 participants