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 current bucket configuration to ConsumptionProbe #117

Merged
merged 1 commit into from
Feb 29, 2020
Merged

Add current bucket configuration to ConsumptionProbe #117

merged 1 commit into from
Feb 29, 2020

Conversation

chipkillmar
Copy link
Contributor

  • Override equals() and hashCode() in BucketConfiguration and Bandwidth
  • Fix warnings in POM
  • Add Maven Wrapper

@vladimir-bukhtoyarov thanks for bucket4j!

I'd like to open a pull request for a minor change to ConsumptionProbe.

My use case is that I'd like to report the current bucket capacity in a custom HTTP header such as X-Rate-Limit-Limit after calling bucket.tryConsumeAndReturnRemaining(numberOfTokens).

I'm using a Hazelcast distributed map whose configuration might be replaced often at runtime, along with a single simple bandwidth bucket configuration. I'd like to be able to report the exact bucket capacity at the time of consumption, without having to track the bucket configuration on each cluster member.

I also overrode equals() and hashCode() on the BucketConfiguration and Bandwidth classes, as I believe this makes it easier to test configurations for equality (I'm using an external utility method for this now).

Other minor changes here include adding explicit versions for Maven plugins to the parent POM, in order to fix some warnings, and adding the Takari Maven Wrapper, which I'm a fan of.

Thanks in advance for your feedback.

* Override equals() and hashCode() in BucketConfiguration and Bandwidth

* Fix warnings in POM

* Add Maven Wrapper
@chipkillmar
Copy link
Contributor Author

@vladimir-bukhtoyarov I'm having a difficult time getting all of the Surefire tests to pass, either locally or in Travis CI.

@vladimir-bukhtoyarov
Copy link
Collaborator

I will look

@chipkillmar
Copy link
Contributor Author

Thanks @vladimir-bukhtoyarov. I'm running Travis CI on the 4.9 branch and it occasionally fails with:

[ERROR] testTryConsume_SynchronizedLimited(io.github.bucket4j.local.LocalTest)  Time elapsed: 15.067 s  <<< FAILURE!
java.lang.AssertionError: Actual rate 16.668 is greater then permitted rate 16.667
	at io.github.bucket4j.local.LocalTest.test15Seconds(LocalTest.java:81)
	at io.github.bucket4j.local.LocalTest.testTryConsume_SynchronizedLimited(LocalTest.java:62)

@vladimir-bukhtoyarov vladimir-bukhtoyarov changed the base branch from master to 4.10 February 29, 2020 19:39
vladimir-bukhtoyarov added a commit that referenced this pull request Feb 29, 2020
@vladimir-bukhtoyarov
Copy link
Collaborator

Hello @chipkillmar

According to failed tests on Travis, I think it failed with little violation because of differences in thread parking on my machine and machine used by Travis, I will rewrite the test to be more stable.

According to Maven Wrapper - it is useful feature, I will merge it.

According to extension of ConsumptionProbe: you provided reasonable arguments that sometimes a client need to know configuration of Bucket which was used during request execution, in general I am agree to provide this kind of functionality. But extension of ConsumptionProbe looks like ad-hoc partial solution which covers only one API method, in same time other users can miss similar functionality for other API methods, so I prefer to solve this problem at more fundamental level by providing verbose versions of interfaces Bucket and AsyncBucket, you can see proposals of Verbose API in this commit. With the new API you will be able to achieve similar in way like this:

VerboseResult<ConsumptionProbe> result =  bucket.asVerbose().tryConsumeAndReturnRemaining(1);
ConsumptionProbe probe = result.getValue();
BucketConfiguration configuration = result.getConfiguration()

And in addition, Verbose Result will provide the time which had been on remote server when it served request and snapshot of bucket state after serving request.

Thanks for your work, I am going to merge your request to the intermediate branch, but I will rollback changes in the ConsumptionProbe because of reason described above. I expect that I will have time to release new version with Verbose API at next weekend.

@vladimir-bukhtoyarov vladimir-bukhtoyarov merged commit 201bf87 into bucket4j:4.10 Feb 29, 2020
vladimir-bukhtoyarov added a commit that referenced this pull request Feb 29, 2020
vladimir-bukhtoyarov added a commit that referenced this pull request Feb 29, 2020
@chipkillmar
Copy link
Contributor Author

chipkillmar commented Feb 29, 2020

Thanks @vladimir-bukhtoyarov! Your VerboseResult<T> API sounds reasonable. If I can help further, please let me know.

@vladimir-bukhtoyarov
Copy link
Collaborator

@chipkillmar

I have released Verbose API under the version 4.10.0. Currently it available only in JCenter repository. I will synchronize with Maven Central a little bit later.

@vladimir-bukhtoyarov
Copy link
Collaborator

Published to Maven Central just now.

Thanks @vladimir-bukhtoyarov! Your VerboseResult<T> API sounds reasonable. If I can help further, please let me know.

@chipkillmar yes your help will be useful, if you have enough time, please add your case to documentation

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.

None yet

2 participants