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

Add incrementer #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

chrisfauerbach
Copy link

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!

…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.

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) {

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.

Comment on lines +92 to +95




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

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 {

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.");

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

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

Successfully merging this pull request may close these issues.

3 participants