-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RateLimiter] Add limit object on RateLimiter consume method #38257
Conversation
vasilvestre
commented
Sep 21, 2020
•
edited
Loading
edited
Q | A |
---|---|
Branch? | master (should be merged in 5.2 before 31 September if possible) |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Tickets | Fix #38241 |
License | MIT |
Doc PR | Not yet :/ |
@wouterj how should I handle the Redirect login fail attempts ? |
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.
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? |
I'm not comfortable using a FQCN in configuration, I would prefer to keep using strings instead. |
Strings are back. |
It was my understanding the FQCN was only being dropped in config, not |
Well I do not really understand what you mean actually, where should we use it? |
This should still be an option, no? I thought Fabien's comment was about removing FQCN from the configuration. |
Limiter isn't set at this moment, we set it in limiter itself in create() public function create(?string $key = null): LimiterInterface
{
$id = $this->config['id'].$key;
$lock = $this->lockFactory ? $this->lockFactory->createLock($id) : new NoLock();
switch ($this->config['strategy']) {
case 'token_bucket':
return new TokenBucketLimiter($id, $this->config['limit'], $this->config['rate'], $this->storage, $lock);
case 'fixed_window':
return new FixedWindowLimiter($id, $this->config['limit'], $this->config['interval'], $this->storage, $lock);
default:
throw new \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 ? |
Flaky test here but fixable through #38320 Edit : It's already merged so I rebased and test should all pass :) |
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
So, now, I'm wondering about the design: Why didn't we add |
See #38257 (comment) for history details, it's not needed right now but it will be useful for test, as shown there : #38257 (comment) |
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 :) |
@wouterj I think Nicolas is right here, the Limit object isn't that useful. WDYT? |
Please note that I'm far from experienced with rate limiting (I just wanted login throttling), but my ideas on this:
|
Thanks @wouterj, that makes sense! |
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 :) |
The ci check fail happens on a code part I haven't modified, what to do ? |
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
@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? |
Anyone able to respond to this one? I think it's a pretty valid case to get the current state |
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 from documentation:
Maybe you could make a new issue or find wouterj on a social network. |