-
Notifications
You must be signed in to change notification settings - Fork 5.5k
local_ratelimit: support return x-ratelimit-reset header
#39501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
72331b4
dad3403
57a5bea
75c20a1
871c82e
fc9fe5f
328d697
9c6fb40
7f32917
23ca425
4993162
6b4b3ff
f0156cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| #include <atomic> | ||||||||||||||||||||||||||||||||||||||||||||||||
| #include <chrono> | ||||||||||||||||||||||||||||||||||||||||||||||||
| #include <iostream> | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Envoy { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -103,4 +104,17 @@ double AtomicTokenBucketImpl::timeNowInSeconds() const { | |||||||||||||||||||||||||||||||||||||||||||||||
| return std::chrono::duration<double>(time_source_.monotonicTime().time_since_epoch()).count(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| 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))); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+107
to
+116
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although it's will be a very very very trival case, but it's possible when we check
Comment on lines
+107
to
+116
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace Envoy | ||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.