Skip to content

Conversation

@kkk777-7
Copy link
Member

What this PR does / why we need it:
Support both local and global ratelimit in BackendTrafficPolicy simultaneously.
Requests are evaluated first by the local limit, then by the global limit.

Which issue(s) this PR fixes:

Fixes #7271

Release Notes: Yes

@kkk777-7 kkk777-7 requested a review from a team as a code owner October 26, 2025 05:29
@codecov
Copy link

codecov bot commented Oct 26, 2025

Codecov Report

❌ Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.38%. Comparing base (d4e44fd) to head (3ed043e).

Files with missing lines Patch % Lines
internal/gatewayapi/backendtrafficpolicy.go 82.14% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7334      +/-   ##
==========================================
+ Coverage   72.34%   72.38%   +0.03%     
==========================================
  Files         231      231              
  Lines       33896    33918      +22     
==========================================
+ Hits        24521    24550      +29     
+ Misses       7614     7607       -7     
  Partials     1761     1761              

☔ 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.

@kkk777-7 kkk777-7 marked this pull request as draft October 26, 2025 05:54
@kkk777-7 kkk777-7 marked this pull request as ready for review October 26, 2025 15:09
if match.Distinct {
// For distinct matches, we only check if the header exists using the RequestHeaders action.
descriptorKey := getRouteRuleDescriptor(rIdx, mIdx)
descriptorKey := fmt.Sprintf("local_%s", getRouteRuleDescriptor(rIdx, mIdx))
Copy link
Contributor

Choose a reason for hiding this comment

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

imo not needed, since these are applied to different filters, prefer minimal changes to enable this

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, I misunderstood 🙏 I’ve reverted it.

return patchRouteWithRateLimitOnTypedFilterConfig(route, rateLimits, irRoute)
}
xdsRouteAction.RateLimits = rateLimits
xdsRouteAction.RateLimits = append(xdsRouteAction.RateLimits, rateLimits...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this needed

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe, append operation is necessary to avoid overwriting the local rate limit config.
https://github.com/envoyproxy/gateway/blob/main/internal/xds/translator/local_ratelimit.go#L139

Copy link
Contributor

Choose a reason for hiding this comment

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

is this an existing bug or related to this PR ?
cc @zhaohuabing

Copy link
Member Author

Choose a reason for hiding this comment

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

this is related to this PR.
I believe there was no issue before because we had only used either local or global, not both.

Copy link
Contributor

Choose a reason for hiding this comment

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

the code flow for local looks like its different

rateLimits, descriptors := buildRouteLocalRateLimits(local)

vs global
global := route.Traffic.RateLimit.Global

Copy link
Member Author

Choose a reason for hiding this comment

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

avoid overwriting the local rate limit config.

sorry, my word make mislead.

There’s no issue converting both the local and global configurations from irRoute to routev3.RateLimit.
However, since both converted routev3.RateLimit are set on the same xdsRouteAction, if we don’t append them, only the later processed (global) routev3.RateLimit will take effect.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah in that case, we need to bring back the local_ prefix to ensure uniqueness in descriptors, my bad

Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
@zirain zirain force-pushed the feat-both-type-rl branch from 9e40480 to 402db53 Compare October 27, 2025 02:52
@arkodg arkodg added this to the v1.6.0 Milestone milestone Oct 30, 2025
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.com>
Signed-off-by: kkk777-7 <kota.kimura0725@gmail.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.

Add support for using local and global ratelimit simultaneously

2 participants