-
Notifications
You must be signed in to change notification settings - Fork 458
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
ratelimit: per descriptor hits addend support and prefer uint64 #802
ratelimit: per descriptor hits addend support and prefer uint64 #802
Conversation
Signed-off-by: wangbaiping/wbpcode <wangbaiping@bytedance.com>
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.
high level question: if the number zero is given, it should work like "check the budget is not negative, and if not requests are allowed"? I am asking because if this would obviate the issue we had in #729
Signed-off-by: wangbaiping/wbpcode <wangbaiping@bytedance.com>
The counter in redis is a number that counts all used tokens. So, we only need to check if the counter is larger than the threshold or not. |
cool, so in other words, sending hits_addend=0 can be used to reject requests if the counter in redis is negative or zero ya? |
Signed-off-by: wangbaiping/wbpcode <wangbaiping@bytedance.com>
sorry, I may didn't make it clear. The counter will never be negative in the redis. It is a counter the will increases forever in the time window. But the conclusion is right. hits_addend zero could also could be used to reject a request. |
great, thank you for clarifying! |
Signed-off-by: wangbaiping/wbpcode <wangbaiping@bytedance.com>
cc @psbrar99 |
also @zirain if you have any comments |
src/utils/utilities.go
Outdated
@@ -41,7 +41,7 @@ func CalculateReset(unit *pb.RateLimitResponse_RateLimit_Unit, timeSource TimeSo | |||
return &durationpb.Duration{Seconds: sec - now%sec} | |||
} | |||
|
|||
func Max(a uint32, b uint32) uint32 { | |||
func Max(a uint64, b uint64) uint64 { |
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.
not a must, but is it find to remove this as golang support generic?
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 am not very familiar to go (I use c++ at most times orz), so not sure if a new generic Max is provided by the golang stdlib or not. If it is provided, it would be great to remove this function.
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.
// The max built-in function returns the largest value of a fixed number of
// arguments of [cmp.Ordered] types. There must be at least one argument.
// If T is a floating-point type and any of the arguments are NaNs,
// max will return NaN.
func max[T cmp.Ordered](x T, y ...T) T
looks like there's.
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.
LGTM, only a small nit.
Signed-off-by: wangbaiping/wbpcode <wangbaiping@bytedance.com>
LGTM, thanks @wbpcode . |
fantastic, thank you for your hard work! @wbpcode 👯 |
No description provided.