-
Notifications
You must be signed in to change notification settings - Fork 818
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
Expose the current Limit() on existing ratelimiters #6235
Changes from all commits
7eb716d
971b0e6
7e9e5b8
46854d3
4e268ed
6323f62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,9 +22,9 @@ | |
|
||
import ( | ||
"context" | ||
"math" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
"golang.org/x/time/rate" | ||
|
@@ -58,8 +58,9 @@ | |
} | ||
|
||
// NewSimpleRateLimiter returns a new rate limiter backed by the golang rate | ||
// limiter | ||
func NewSimpleRateLimiter(rps int) *RateLimiter { | ||
// limiter. This is currently only used in tests. | ||
func NewSimpleRateLimiter(t *testing.T, rps int) *RateLimiter { | ||
t.Helper() // ensure a T has been passed | ||
initialRps := float64(rps) | ||
return NewRateLimiter(&initialRps, _defaultRPSTTL, _burstSize) | ||
} | ||
|
@@ -107,13 +108,13 @@ | |
} | ||
|
||
// Limit returns the current rate per second limit for this ratelimiter | ||
func (rl *RateLimiter) Limit() float64 { | ||
func (rl *RateLimiter) Limit() rate.Limit { | ||
Comment on lines
-110
to
+111
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. Had to change because this is also a |
||
rl.RLock() | ||
defer rl.RUnlock() | ||
if rl.maxDispatchPerSecond != nil { | ||
return *rl.maxDispatchPerSecond | ||
return rate.Limit(*rl.maxDispatchPerSecond) | ||
} | ||
return math.MaxFloat64 | ||
return rate.Inf | ||
} | ||
|
||
func (rl *RateLimiter) storeLimiter(maxDispatchPerSecond *float64) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -436,7 +436,7 @@ func (tm *TaskMatcher) UpdateRatelimit(rps *float64) { | |
|
||
// Rate returns the current rate at which tasks are dispatched | ||
func (tm *TaskMatcher) Rate() float64 { | ||
return tm.limiter.Limit() | ||
return float64(tm.limiter.Limit()) | ||
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. though I'd like to add this....... it leads to a massive explosion in "well this is also the same value, so change that too..." chain of changes, with no good place to cut things off. I think changing all these is very much worth it, |
||
} | ||
|
||
func (tm *TaskMatcher) pollOrForward( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems very likely that this will only ever be used in tests. almost all of our real limiters are dynamically configurable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd consider s/Simple/Test/ because it presumably means this has testing functionality and that makes it considerably easier to find when casting about for functions to use in tests