Skip to content
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

Method for checking if over limit w/o updating #1

Closed
ctoomey opened this issue Jun 14, 2017 · 7 comments
Closed

Method for checking if over limit w/o updating #1

ctoomey opened this issue Jun 14, 2017 · 7 comments

Comments

@ctoomey
Copy link
Contributor

ctoomey commented Jun 14, 2017

Hi, your library looks great, with the best-of-breed sliding window algorithm and the pluggable backends!

I've got a use case that it doesn't support very well though, where I need to check if the limit has been reached without incrementing it if not. We're going to track login failures, and once we've reached the limit, disallow further login attempts. So we first need to check if the failure rate has reached limit, and only then allow the request and increment the count if it fails.

So I'm thinking of adding another method to RequestRateLimiter to enable this, say

    /**
     * Determine if the given key, after incrementing by the given weight, is >= the configured rate limit.
     * @param key key.
     * @param weight A variable weight.
     * @return {@code true} if the key is >== the limit, otherwise {@code false} .
     */
    boolean geLimit(String key, int weight);

Looking at the implementation code, this would be easily implemented since it's a slight variant of the existing code for overlimit().

Would you be open to a pull request if I add this?

thx,
Chris

ctoomey added a commit to ctoomey/ratelimitj that referenced this issue Jun 15, 2017
ctoomey added a commit to ctoomey/ratelimitj that referenced this issue Jun 15, 2017
ctoomey added a commit to ctoomey/ratelimitj that referenced this issue Jun 15, 2017
ctoomey added a commit to ctoomey/ratelimitj that referenced this issue Jun 15, 2017
@mokies
Copy link
Owner

mokies commented Jun 15, 2017

HI Chris,

Thanks for taking the time to write up your suggestion for a pull request.

I would most definitely be happy to accept this pull request. An incorrect password attempt count seems to be a common scenario that people are looking for the library to support.

Cheers,
Craig

@mokies
Copy link
Owner

mokies commented Jun 15, 2017

Thanks Chris - I've taken a look at your changes and they look good, appreciate the effort. I should get some time this weekend to add a few more tests and merge in your branch.

Cheers,
Craig

@ctoomey
Copy link
Contributor Author

ctoomey commented Jun 15, 2017

Great, thanks Craig. I'd originally thought to add an atLimit(key) function which would only check the limit, but realized that I also needed a function that would take a key and a weight, store the hit if the limit wasn't exceeded, and return whether the limit was met or exceeded. I realized I that a single function that did the latter would suffice since it could be passed 0 as weight to achieve the former. Hence geLimit(key, weight).

mokies pushed a commit that referenced this issue Jun 17, 2017
* Method for checking if over limit w/o updating

Implemented for InMemory  and Hazelcast

* #1: Method for checking if over limit w/o updating

Implemented atLimit() for reds

* #1: Method for checking if over limit w/o updating

Replaced atLimit() with geLimit()

* #1: Method for checking if over limit w/o updating

* #1: Method for checking if over limit w/o updating
@ctoomey
Copy link
Contributor Author

ctoomey commented Jun 20, 2017

Craig, thanks for merging my pull request. Will you publish version 0.3.4 with the changes to maven soon so I can use that instead of my local build? Thanks

@mokies
Copy link
Owner

mokies commented Jun 22, 2017

I will push out a 4.0-RC over the weekend as I'm going to change some of the method names to better communicate the action.

@mokies
Copy link
Owner

mokies commented Jun 24, 2017

0.4.0.M1 released to maven central and should be available in a few hours.

@ctoomey
Copy link
Contributor Author

ctoomey commented Jun 28, 2017

Thanks, I've updated to use that and all is well. Much appreciated!

@ctoomey ctoomey closed this as completed Jun 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants