Skip to content

feat: support is_negative_hits in rate limit actions#44059

Merged
wbpcode merged 5 commits intoenvoyproxy:mainfrom
rudrakhp:rl_action_subtrahend
Apr 9, 2026
Merged

feat: support is_negative_hits in rate limit actions#44059
wbpcode merged 5 commits intoenvoyproxy:mainfrom
rudrakhp:rl_action_subtrahend

Conversation

@rudrakhp
Copy link
Copy Markdown
Member

@rudrakhp rudrakhp commented Mar 21, 2026

Commit Message: feat: support is_negative_hits in rate limit actions
Additional Description: Support is_negative_hits for hits_addend in rate limit actions that can be used to have an opposite effect. Can be used to refill previously consumed tokens. See issue for usecase.
Risk Level: Low (new api)
Testing: unit testing
Docs Changes: N/A
Release Notes: Yes
Platform Specific Features: N/A
Fixes: #41219

@repokitteh-read-only
Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #44059 was opened by rudrakhp.

see: more, trace.

Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
@rudrakhp rudrakhp force-pushed the rl_action_subtrahend branch from 755dce1 to c7f6a1a Compare March 23, 2026 13:18
@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Mar 26, 2026

I check the previous issue and also the API. It's weird for me to do it with rate limit filter because the rate limit works with a time window rather than a single concurrency gauge.

I guess, in the design, a very large limit refresh time window will be configured to make the rate limit works like a concurrency gauge.

But it still weird. Could use use the concurrency filter to do this?

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.

Then, let's continue. Some comments are added to the API. Thanks for the contribution.

Comment on lines +2719 to +2727
// An optional hits subtrahend to be appended to the descriptor produced by this rate limit
// configuration. This is the inverse of ``hits_addend`` and can be used to refill previously
// consumed rate limit tokens. Only one of ``hits_addend`` or ``hits_subtrahend`` may be specified.
//
// .. note::
// This is only supported if the rate limit action is configured in the ``typed_per_filter_config`` like
// :ref:`VirtualHost.typed_per_filter_config<envoy_v3_api_field_config.route.v3.VirtualHost.typed_per_filter_config>` or
// :ref:`Route.typed_per_filter_config<envoy_v3_api_field_config.route.v3.Route.typed_per_filter_config>`, etc.
HitsSubtrahend hits_subtrahend = 8;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess rather then to add a new message for subtrahend, we can add a bool field like negative_hits_addend to indicate it's subtrahend.

Then at least we needn't to handle the one of validation and so on

Copy link
Copy Markdown
Member Author

@rudrakhp rudrakhp Mar 30, 2026

Choose a reason for hiding this comment

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

Going with is_negative_hits alongside value under existing hits_addend API.

Comment thread api/envoy/extensions/common/ratelimit/v3/ratelimit.proto Outdated
Comment thread api/envoy/service/ratelimit/v3/rls.proto Outdated
@rudrakhp rudrakhp force-pushed the rl_action_subtrahend branch 4 times, most recently from f4b3031 to a183428 Compare March 30, 2026 20:04
@rudrakhp rudrakhp requested a review from wbpcode March 30, 2026 20:05
@rudrakhp rudrakhp changed the title feat: support hits_subtrahend in rate limit actions feat: support is_negative_hits in rate limit actions Mar 30, 2026
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
@rudrakhp rudrakhp force-pushed the rl_action_subtrahend branch from a183428 to 485b270 Compare March 31, 2026 09:39
@rudrakhp
Copy link
Copy Markdown
Member Author

/retest

Signed-off-by: code <wbphub@gmail.com>
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.

@repokitteh-read-only repokitteh-read-only Bot removed the api label Apr 8, 2026
@rudrakhp
Copy link
Copy Markdown
Member Author

rudrakhp commented Apr 9, 2026

/retest

@wbpcode wbpcode merged commit 72fe53c into envoyproxy:main Apr 9, 2026
30 checks passed
nshipilov pushed a commit to nshipilov/envoy that referenced this pull request Apr 13, 2026
<!--
!!!ATTENTION!!!

If you are fixing *any* crash or *any* potential security issue, *do
not*
open a pull request in this repo. Please report the issue via emailing
envoy-security@googlegroups.com where the issue will be triaged
appropriately.
Thank you in advance for helping to keep Envoy secure.

!!!ATTENTION!!!

For an explanation of how to fill out the fields, please see the
relevant section
in
[PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md)

!!!ATTENTION!!!

Please check the [use of generative AI
policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41).

You may use generative AI only if you fully understand the code. You
need to disclose
this usage in the PR description to ensure transparency.
-->

Commit Message: feat: support is_negative_hits in rate limit actions
Additional Description: Support `is_negative_hits` for `hits_addend` in
rate limit actions that can be used to have an opposite effect. Can be
used to refill previously consumed tokens. See issue for usecase.
Risk Level: Low (new api)
Testing: unit testing
Docs Changes: N/A
Release Notes: Yes
Platform Specific Features: N/A
Fixes: envoyproxy#41219

---------

Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Signed-off-by: code <wbphub@gmail.com>
Co-authored-by: code <wbphub@gmail.com>
Signed-off-by: Nick Shipilov <nick.shipilov.n@gmail.com>
krinkinmu pushed a commit to grnmeira/envoy that referenced this pull request Apr 20, 2026
<!--
!!!ATTENTION!!!

If you are fixing *any* crash or *any* potential security issue, *do
not*
open a pull request in this repo. Please report the issue via emailing
envoy-security@googlegroups.com where the issue will be triaged
appropriately.
Thank you in advance for helping to keep Envoy secure.

!!!ATTENTION!!!

For an explanation of how to fill out the fields, please see the
relevant section
in
[PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md)

!!!ATTENTION!!!

Please check the [use of generative AI
policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41).

You may use generative AI only if you fully understand the code. You
need to disclose
this usage in the PR description to ensure transparency.
-->

Commit Message: feat: support is_negative_hits in rate limit actions
Additional Description: Support `is_negative_hits` for `hits_addend` in
rate limit actions that can be used to have an opposite effect. Can be
used to refill previously consumed tokens. See issue for usecase.
Risk Level: Low (new api)
Testing: unit testing
Docs Changes: N/A
Release Notes: Yes
Platform Specific Features: N/A
Fixes: envoyproxy#41219

---------

Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
Signed-off-by: code <wbphub@gmail.com>
Co-authored-by: code <wbphub@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.

Enable per-user concurrency limits by supporting negative cost in the rate limiting protocol

2 participants