Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[RateLimiter] Add limit object on RateLimiter consume method#38257
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
vasilvestre commentedSep 24, 2020
@wouterj how should I handle the Redirect login fail attempts ? |
wouterj left a comment
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@vasilvestre! And I'm sorry for not being available at second half of the week..
This PR looks good to me - all pending comments are minor ones no big design changes. The only thing I'm wondering about is whether to use FQCN in the configuration - that might not be very easy to use for Yaml and XML users. Would love feedback from the core team about this.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
vasilvestre commentedSep 26, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I just finish the PR on a live coding session, it was a nice moment so no problem! Yeah FQCN isn't fine for YAML and XML, how is the core team dealing with it recently? |
fabpot commentedSep 27, 2020
I'm not comfortable using a FQCN in configuration, I would prefer to keep using strings instead. |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
vasilvestre commentedSep 27, 2020
Strings are back. |
kbond commentedSep 27, 2020
It was my understanding the FQCN was only being dropped in config, not |
vasilvestre commentedSep 27, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Well I do not really understand what you mean actually, where should we use it? |
kbond commentedSep 27, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This should still be an option, no? I thought Fabien's comment was about removing FQCN from the configuration. |
vasilvestre commentedSep 27, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Limiter isn't set at this moment, we set it in limiter itself in create() publicfunctioncreate(?string$key =null):LimiterInterface{$id =$this->config['id'].$key;$lock =$this->lockFactory ?$this->lockFactory->createLock($id) :newNoLock();switch ($this->config['strategy']) {case'token_bucket':returnnewTokenBucketLimiter($id,$this->config['limit'],$this->config['rate'],$this->storage,$lock);case'fixed_window':returnnewFixedWindowLimiter($id,$this->config['limit'],$this->config['interval'],$this->storage,$lock);default:thrownew \LogicException(sprintf('Limiter strategy "%s" does not exists, it must be either "token_bucket" or "fixed_window".',$this->config['strategy'])); }} Edit : OK I got it mate sorry ! I haven't worked yet on headers and this isn't the goal here so I didn't think about it. This will be useful in future, when we will be able to attach a response or whatever and set headers, that's it ? |
vasilvestre commentedSep 27, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Flaky test here but fixable through#38320 Edit : It's already merged so I rebased and test should all pass :) |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
fabpot left a comment
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.
minor comments
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
nicolas-grekas commentedSep 29, 2020
So, now, I'm wondering about the design: Why didn't we add |
vasilvestre commentedSep 29, 2020
See#38257 (comment) for history details, it's not needed right now but it will be useful for test, as shown there :#38257 (comment) |
nicolas-grekas commentedSep 29, 2020
I'm not convinced at all that the abstraction needs to provide reflective information. Wiring should be tested by another mean IMHO.
We should also resolve this question :) |
vasilvestre commentedSep 29, 2020
@wouterj I think Nicolas is right here, the Limit object isn't that useful. WDYT? |
wouterj commentedSep 29, 2020
Please note that I'm far from experienced with rate limiting (I just wanted login throttling), but my ideas on this:
|
nicolas-grekas commentedSep 29, 2020
Thanks@wouterj, that makes sense! |
wouterj commentedSep 29, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I don't have a strong opinion on this one (and not a real use-case). If you think it's better to remove it, let's do that. It's easier to add it if we find good use-cases than to remove it in the future :) |
vasilvestre commentedSep 29, 2020
The ci check fail happens on a code part I haven't modified, what to do ? |
fabpot commentedSep 30, 2020
Thank you@vasilvestre. |
…ded IO blocking (wouterj)This PR was merged into the 5.2-dev branch.Discussion----------[RateLimiter] Call all compound limiters on failure and added IO blocking| Q | A| ------------- | ---| Branch? | master| Bug fix? | yes| New feature? | no| Deprecations? | no| Tickets | -| License | MIT| Doc PR | -Two small improvements that I missed in#38257:* Added `wait()` method, to be able to do logic like this: ```php while (!($limit = $limiter->consume())->isAccepted()) { $limit->wait(); } ```* Fixed the `CompoundLimiter` to always call all limiters (even when one already blocks). This was the original behavior of the compound limiter and imho the best behavior (at least, it's always consistent and doesn't rely on the order of limiters - which is unsorted).Commits-------0279f88 Call all compound limiters on failure and added IO blocking
NikosDevPhp commentedJul 22, 2023
@wouterj We have a rate limiting for failed attempts let's say 3 for a sliding window of 1 hour. Then if the attempt is failed I would consume(1). Is this how it is supposed to work? |
NikosDevPhp commentedNov 3, 2023
Anyone able to respond to this one? I think it's a pretty valid case to get the current state |
vasilvestre commentedNov 7, 2023
The RateLimiter evolved a LOT since this PR. AFAIK the documentation says to consume 1 and if an exception is thrown then you don't have load on your server. Pseudo code fromdocumentation:
Maybe you could make a new issue or find wouterj on a social network. |
Uh oh!
There was an error while loading.Please reload this page.