-
Notifications
You must be signed in to change notification settings - Fork 93
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
Add incrementer #18
base: master
Are you sure you want to change the base?
Add incrementer #18
Conversation
…Client that cannot be throttled but still counts towards some limits, contractual, performance, etc. Two paths two different applications, especially on shared keys.
|
||
/** | ||
* Regardless of being over limit, we still want to track the count, this is for a client that is going to act | ||
* regardless of a limit, but, still needs to be counted towareds said limit. |
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.
towareds -> towards
@@ -92,7 +91,7 @@ public boolean resetLimit(String key) { | |||
return hz.getMap(key); | |||
} | |||
|
|||
private boolean eqOrGeLimit(String key, int weight, boolean strictlyGreater) { | |||
private boolean eqOrGeLimit(String key, int weight, boolean strictlyGreater, boolean increment_anyway) { |
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.
increment_anyway
-> incrementAnyway
For me alwaysIncrement
sounds better.
|
||
|
||
|
||
|
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.
Way too many new lines :)
@@ -100,7 +106,9 @@ public boolean resetLimit(String key) { | |||
}); | |||
} | |||
|
|||
private boolean eqOrGeLimit(String key, int weight, boolean strictlyGreater) { | |||
// Chris Fauerbach, adding a way to override the increment even if over limit | |||
// @chrisfauerbach , https://fauie.com , github.com/chrisfauerbach |
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.
Why are these comments present?
return true; // over limit, don't record request | ||
if (increment_regardless) { | ||
geLimit = true; | ||
}else { |
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.
}else {
-> } else {
// Counter should be 0 now | ||
assertThat(requestRateLimiter.overLimitWhenIncremented(key, 1)).isFalse(); | ||
// Counter should be 1 now and 'false', meaning not over limit | ||
LOG.debug("About to print add 10 to go over."); |
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.
IMHO the log debug messages are not needed, and they could be Java comments if they bring any value
I have the use case need to increment my counter, even if I'm over limit. I added another parameter to 'increment anyway', and also added convenience methods.
Tests written and verified in: hazelcast, memory, redis.
Please let me know if there are any questions!