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

RateLimiter: change CanAccept() to TryAccept() #17694

Merged
merged 1 commit into from
Nov 26, 2015

Conversation

hongchaodeng
Copy link
Contributor

The CanAccept interface description is not accurate. The actual behavior is taking a token instead of just testing without side-effect. And all the users of the interface relies on the taking behavior, not testing.

This commit gives it a better name and also a more accurate description.

/cc @brendandburns @liggitt

@k8s-bot
Copy link

k8s-bot commented Nov 24, 2015

Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist")

If this message is too spammy, please complain to ixdy.

1 similar comment
@k8s-bot
Copy link

k8s-bot commented Nov 24, 2015

Can one of the admins verify that this patch is reasonable to test? (reply "ok to test", or if you trust the user, reply "add to whitelist")

If this message is too spammy, please complain to ixdy.

@k8s-github-robot
Copy link

Labelling this PR as size/S

@k8s-github-robot k8s-github-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Nov 24, 2015
@liggitt
Copy link
Member

liggitt commented Nov 24, 2015

don't feel super strongly, but I think I'd prefer just updating the documentation on the CanAccept function

@xiang90
Copy link
Contributor

xiang90 commented Nov 24, 2015

@liggitt I feel CanAccept and TryAccept are conceptually different. I would prefer naming this one TryAccept. We will need to add CanAccept that test the rate limiter status soon enough.

@derekwaynecarr
Copy link
Member

If the plan is to add a function that checks with no side-effect, then I agree that function should be called CanAccept(), and the function that actually mutates would then be called TryAccept in the same vein of peek/pop on stacks.

@@ -47,7 +48,7 @@ func NewFakeRateLimiter() RateLimiter {
return &fakeRateLimiter{}
}

func (t *tickRateLimiter) CanAccept() bool {
func (t *tickRateLimiter) TryAccept() bool {
Copy link
Member

Choose a reason for hiding this comment

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

Godoc please while you are here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is private implementation.
The docs should be covered in public interface (i.e. RateLimiter), right?

Copy link
Member

Choose a reason for hiding this comment

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

ah, sorry, I agree. thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great. Thanks!

@derekwaynecarr
Copy link
Member

nit on godoc for public functions. otherwise lgtm.

@derekwaynecarr
Copy link
Member

my mistake on the godoc comment. lgtm.

@derekwaynecarr derekwaynecarr added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 25, 2015
@k8s-github-robot
Copy link

@k8s-bot ok to test

pr builder appears to be missing, activating due to 'lgtm' label.

@k8s-github-robot
Copy link

Continuous integration appears to have missed, closing and re-opening to trigger it

@k8s-bot
Copy link

k8s-bot commented Nov 25, 2015

GCE e2e test build/test passed for commit 13d152a.

@k8s-github-robot
Copy link

The author of this PR is not in the whitelist for merge, can one of the admins add the 'ok-to-merge' label?

@xiang90
Copy link
Contributor

xiang90 commented Nov 25, 2015

@derekwaynecarr We are working on the CanAccept one. It blocks on juju/ratelimit#10.

@liggitt
Copy link
Member

liggitt commented Nov 25, 2015

I'm curious how you anticipate a non-token-acquiring CanAccept function being used... if it returns true, don't you immediately have to call TryAccept to know for sure that another goroutine didn't just use up the available token?

@xiang90
Copy link
Contributor

xiang90 commented Nov 25, 2015

@liggitt Oh. We want to expose the metrics. Like is this ratelimiter limiting the rate, what is the current filling rate, etc..

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Nov 26, 2015

GCE e2e test build/test passed for commit 13d152a.

@k8s-github-robot
Copy link

@k8s-bot test this [submit-queue is verifying that this PR is safe to merge]

@k8s-bot
Copy link

k8s-bot commented Nov 26, 2015

GCE e2e test build/test passed for commit 13d152a.

@k8s-github-robot
Copy link

Automatic merge from submit-queue

k8s-github-robot pushed a commit that referenced this pull request Nov 26, 2015
@k8s-github-robot k8s-github-robot merged commit 4eb010b into kubernetes:master Nov 26, 2015
@hongchaodeng hongchaodeng deleted the ratelimit branch January 11, 2016 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants