local_ratelimit: support return x-ratelimit-reset header#39501
local_ratelimit: support return x-ratelimit-reset header#39501wbpcode merged 13 commits intoenvoyproxy:mainfrom
x-ratelimit-reset header#39501Conversation
Signed-off-by: zirain <zirain2009@gmail.com>
Signed-off-by: zirain <zirain2009@gmail.com>
|
flaky: |
|
/retest |
agrawroh
left a comment
There was a problem hiding this comment.
Left some comments, looks good otherwise.
source/extensions/filters/http/local_ratelimit/local_ratelimit.cc
Outdated
Show resolved
Hide resolved
test/extensions/filters/http/local_ratelimit/local_ratelimit_integration_test.cc
Outdated
Show resolved
Hide resolved
Signed-off-by: zirain <zirain2009@gmail.com>
Signed-off-by: zirain <zirain2009@gmail.com>
|
/retest |
1 similar comment
|
/retest |
agrawroh
left a comment
There was a problem hiding this comment.
Looks good! Should we also add a blurb on the Local RateLimit Docs to capture this?
test/extensions/filters/http/local_ratelimit/local_ratelimit_integration_test.cc
Outdated
Show resolved
Hide resolved
|
/assign @wbpcode |
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: zirain <zirain2009@gmail.com>
|
/wait |
|
/retest |
1 similar comment
|
/retest |
| std::chrono::milliseconds AtomicTokenBucketImpl::nextTokenAvailable() const { | ||
| // If there are tokens available, return immediately. | ||
| if (remainingTokens() >= 1) { | ||
| return std::chrono::milliseconds(0); | ||
| } | ||
|
|
||
| // Calculate time since the last fill. | ||
| double current_time = timeNowInSeconds(); | ||
| double last_time = time_in_seconds_.load(); | ||
| return std::chrono::milliseconds( | ||
| static_cast<uint64_t>(((1 / fill_rate_ - (current_time - last_time)) * 1000))); | ||
| } |
There was a problem hiding this comment.
Although it's will be a very very very trival case, but it's possible when we check remainingTokens(), the remaining tokens are less then 1. Then, when we calculate the next available token, time passes, the 1 / fill_rate_ - (current_time - last_time) may return a minus value.
| std::chrono::milliseconds AtomicTokenBucketImpl::nextTokenAvailable() const { | ||
| // If there are tokens available, return immediately. | ||
| if (remainingTokens() >= 1) { | ||
| return std::chrono::milliseconds(0); | ||
| } | ||
|
|
||
| // Calculate time since the last fill. | ||
| double current_time = timeNowInSeconds(); | ||
| double last_time = time_in_seconds_.load(); | ||
| return std::chrono::milliseconds( | ||
| static_cast<uint64_t>(((1 / fill_rate_ - (current_time - last_time)) * 1000))); | ||
| } |
There was a problem hiding this comment.
| std::chrono::milliseconds AtomicTokenBucketImpl::nextTokenAvailable() const { | |
| // If there are tokens available, return immediately. | |
| if (remainingTokens() >= 1) { | |
| return std::chrono::milliseconds(0); | |
| } | |
| // Calculate time since the last fill. | |
| double current_time = timeNowInSeconds(); | |
| double last_time = time_in_seconds_.load(); | |
| return std::chrono::milliseconds( | |
| static_cast<uint64_t>(((1 / fill_rate_ - (current_time - last_time)) * 1000))); | |
| } | |
| std::chrono::milliseconds AtomicTokenBucketImpl::nextTokenAvailable() const { | |
| // If there are tokens available, return immediately. | |
| const double remaining_tokens = remainingTokens(); | |
| if (remaining_tokens >= 1) { | |
| return std::chrono::milliseconds(0); | |
| } | |
| // Calculate time since the last fill. | |
| return std::chrono::milliseconds( | |
| static_cast<uint64_t>(((1 - remaining_tokens) / fill_rate_) * 1000)); | |
| } |
Signed-off-by: zirain <zirain2009@gmail.com>
Commit Message: local_ratelimit: support return
x-ratelimit-resetheaderAdditional 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:]