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

More generic API to work with x/time/rate #582

Merged
merged 2 commits into from
Jul 26, 2017
Merged

More generic API to work with x/time/rate #582

merged 2 commits into from
Jul 26, 2017

Conversation

nelz9999
Copy link
Contributor

As per the discussion in Slack (https://gophers.slack.com/archives/C04S3T99A/p1500582764076547), I added the ability to use the x/time/rate package for the rate limiting implementation, while also keeping backwards-compatible with the juju/ratelimit usage.

I'm pretty pleased with the structure, using subset interfaces off the x/time/rate.Limiter to express most of what we needed.

I was even able to port the older usage of NewTokenBucketLimiter to use the new implementation under the covers, but was unable to do so with NewTokenBucketThrottler (because IMO the API leaked testing configuration).

For any future API-breaking versions, it wouldn't be too hard to make the juju-related adapters a sub-package, but I'm not pushing that in this PR.

Would love to hear solid opinions on improvements I could make to the names.

@thedevelopnik
Copy link

@nelz9999 this looks awesome to me and should fulfill our license limitations while also fulfilling Peter's API request. Thank you!

@blainsmith
Copy link

Very nice man.

Copy link
Member

@peterbourgon peterbourgon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits but once those are done then LGTM!

"testing"
"time"

jujuratelimit "github.com/juju/ratelimit"

"github.com/go-kit/kit/endpoint"
"github.com/go-kit/kit/ratelimit"
"golang.org/x/time/rate"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this import decl up with juju, above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

// exceed the maximum request rate are delayed via the parameterized sleep
// function. By default you may pass time.Sleep.
func NewTokenBucketThrottler(tb *ratelimit.Bucket, sleep func(time.Duration)) endpoint.Middleware {
// return NewDelayingLimiter(NewWaiter(tb))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this didn't work? Would be cool if we could express all the old functions in terms of the new ones!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do it, but then the sleep parameter gets ignored. I'll check in that change, so you can evaluate if you like it.

@nelz9999
Copy link
Contributor Author

@peterbourgon This is ready for you to see if you like what I've done to marry the old functions to the new ones.

@peterbourgon
Copy link
Member

Yep, I'm happy with this for the current point release. For the next one I think we can totally drop Juju. Thanks so much for the work! 👍

@peterbourgon
Copy link
Member

Urgh, build failures are unrelated: see openzipkin-contrib/zipkin-go-opentracing#68

@basvanbeek
Copy link
Member

Build failures due to Thrift have been fixed in zipkin-go-opentracing

Go kit also has issue with thrift update, PR #585 resolves this.

@peterbourgon peterbourgon merged commit 19463ea into go-kit:master Jul 26, 2017
@nelz9999 nelz9999 deleted the ratelimit-x branch July 26, 2017 05:09
@nelz9999
Copy link
Contributor Author

nelz9999 commented Oct 9, 2017

@peterbourgon Now that 0.6.0 has been cut, would you like the follow-on PR to remove juju?

@peterbourgon
Copy link
Member

@nelz9999 Sure.

jamesgist pushed a commit to jamesgist/kit that referenced this pull request Nov 1, 2024
More generic API to work with x/time/rate
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.

5 participants