-
Notifications
You must be signed in to change notification settings - Fork 63
Add RateLimit middleware using TokenBucket algorithm #557
base: master
Are you sure you want to change the base?
Conversation
Thank you for opening this pull request! 🙌 These tips will help get your PR across the finish line:
|
b4f04b6
to
064a129
Compare
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.
Thank you for your contribution!
Codecov Report
@@ Coverage Diff @@
## master #557 +/- ##
==========================================
+ Coverage 58.42% 60.03% +1.60%
==========================================
Files 168 169 +1
Lines 16153 13265 -2888
==========================================
- Hits 9438 7964 -1474
+ Misses 5875 4461 -1414
Partials 840 840
Flags with carried forward coverage won't be shown. Click here to find out more.
|
064a129
to
8cbb5c0
Compare
Would anyone be available to re-review my PR or may be at least approve the workflows so that I have visibility on what are the remaining to fix/improve ? Thanks a lot. |
Thanks for launching the CI/CD for me. The |
Correct. Fixing the flaky test in #563. |
Thanks. I synced the PR with |
@LaPetiteSouris , can you merge master instead? This last update brought commits that don't have to do with your changes. |
5bd1cf3
to
b2383af
Compare
Signed-off-by: TungHoang <[email protected]>
Signed-off-by: TungHoang <[email protected]>
Signed-off-by: TungHoang <[email protected]>
Signed-off-by: TungHoang <[email protected]>
Signed-off-by: TungHoang <[email protected]>
Signed-off-by: TungHoang <[email protected]>
Signed-off-by: TungHoang <[email protected]>
Signed-off-by: TungHoang <[email protected]>
b2383af
to
dfaf183
Compare
@eapolinario Sorry for that. I did not pay attention. I rebase to |
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.
If I understand correctly, we're essentially having a version of sync.Map with TTL. So just to make the code more readable, how about we move that logic behind a new type that does only that?
if !accessRecord.(*accessRecords).limiter.Allow() { | ||
return RateLimitExceeded(fmt.Errorf("rate limit exceeded")) | ||
} |
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.
shouldn't this happen before we modify the map?
TL;DR
Solve flyteorg/flyte#327
Type
Are all requirements met?
Complete description
Main changes
userID
andrate
per user ID.rate
is a native Golang package to track total count of requests.auth
package. In fact, the best way to uniquely identify requests to rate limit is to track usage per authenticated user.Tradeoff
flyteadmin
is deployed. If this is the case and we are serious about rate limit, another improvement is needed, like introduction of Redis for example, which is out of scopes for this PR.Tracking Issue
Remove the 'fixes' keyword if there will be multiple PRs to fix the linked issue
fixes flyteorg/flyte#327
Follow-up issue
NA