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

Explicit unlimited ratelimits #261

Merged

Conversation

lmajercak-wish
Copy link
Contributor

@lmajercak-wish lmajercak-wish commented Jun 9, 2021

Provide the ability to explicitly set a rate limit descriptor to be unlimited to avoid calls to redis/memcached.

#241

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks for adding this. Can you add some documentation and then we can go from there? Thank you.

/wait

examples/ratelimit/config/example.yaml Outdated Show resolved Hide resolved
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

/wait

README.md Outdated Show resolved Hide resolved
@mattklein123
Copy link
Member

Sorry can you fix DCO? Feel free to force push in this case and then we can continue the review from there.

/wait

@lmajercak-wish lmajercak-wish force-pushed the lmajercak_unlimited_ratelimits branch from d59efa8 to 6a81d9b Compare June 17, 2021 16:28
@lmajercak-wish
Copy link
Contributor Author

Sorry can you fix DCO? Feel free to force push in this case and then we can continue the review from there.

/wait

done

@lmajercak-wish
Copy link
Contributor Author

Hi @mattklein123, would you be able to take a look again? Thanks! :)

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks LGTM with small comments.

/wait

value, present :=
pb.RateLimitResponse_RateLimit_Unit_value[strings.ToUpper(descriptorConfig.RateLimit.Unit)]
if !present || value == int32(pb.RateLimitResponse_RateLimit_UNKNOWN) {
if (!present || value == int32(pb.RateLimitResponse_RateLimit_UNKNOWN)) && !unlimited {
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 split this logic out so that we actually check if unlimited is set with a unit at all and have an error message (and test) for that? I think that would be more clear to the user.

Copy link
Member

Choose a reason for hiding this comment

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

(Ping on this)

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 wasn't too sure what exactly you meant, so please review this again :)

src/memcached/cache_impl.go Outdated Show resolved Hide resolved
@lmajercak-wish lmajercak-wish force-pushed the lmajercak_unlimited_ratelimits branch from c854586 to 01de07f Compare June 30, 2021 15:54
Signed-off-by: lmajercak-wish <[email protected]>
@lmajercak-wish lmajercak-wish force-pushed the lmajercak_unlimited_ratelimits branch from 2290800 to 2d18c1c Compare June 30, 2021 15:55
Signed-off-by: lmajercak-wish <[email protected]>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

/wait

README.md Outdated
requests_per_unit: 100
```

For an unlimited descriptor, the request will not be sent to the underlying cache (Redis/Memcached), but will be quickly returned locally by the ratelimit instance.
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 mention why someone would want to do this? I assume for stats, etc.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, stats yes. But also, in our case, our client will not allow a request to go through if a descriptor is not found, so we do have to have it defined.

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'll add something to the readme

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

value, present :=
pb.RateLimitResponse_RateLimit_Unit_value[strings.ToUpper(descriptorConfig.RateLimit.Unit)]
if !present || value == int32(pb.RateLimitResponse_RateLimit_UNKNOWN) {
if (!present || value == int32(pb.RateLimitResponse_RateLimit_UNKNOWN)) && !unlimited {
Copy link
Member

Choose a reason for hiding this comment

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

(Ping on this)

src/memcached/cache_impl.go Outdated Show resolved Hide resolved
test/service/ratelimit_test.go Outdated Show resolved Hide resolved
@lmajercak-wish lmajercak-wish force-pushed the lmajercak_unlimited_ratelimits branch from 283c882 to 7adeec5 Compare July 2, 2021 22:45
@mattklein123
Copy link
Member

Please do not force push after the PR is started. It breaks the review process. Just merge main and add commits. Thank you!

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks LGTM with a small doc comment.

/wait

if isUnlimited[i] {
response.Statuses[i] = &pb.RateLimitResponse_DescriptorStatus{
Code: pb.RateLimitResponse_OK,
LimitRemaining: math.MaxUint32,
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 document this somewhere? It should probably go directly in the proto docs as a comment? Or potentially also somewhere in the README?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean by the proto docs, I added a comment to the README

Copy link
Member

Choose a reason for hiding this comment

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

I mean doing a PR here also: https://github.com/envoyproxy/envoy/blob/7c1991ffe382bacf2bf415a643c5ea7428d0880e/api/envoy/service/ratelimit/v3/rls.proto#L130-L131

This is the canonical service definition for the ratelimit service.

@lmajercak-wish
Copy link
Contributor Author

Please do not force push after the PR is started. It breaks the review process. Just merge main and add commits. Thank you!

I just followed the DCO steps

@lmajercak-wish lmajercak-wish force-pushed the lmajercak_unlimited_ratelimits branch from 35e338b to 5b69edf Compare July 7, 2021 15:35
@mattklein123
Copy link
Member

@lmajercak-wish now that DCO is broken you will need to squash and force push, so please do that. In the future please make sure to only add commits and sign off each commit. Thank you!

/wait

@lmajercak-wish lmajercak-wish force-pushed the lmajercak_unlimited_ratelimits branch from 5b69edf to 629323a Compare July 7, 2021 15:52
@lmajercak-wish lmajercak-wish force-pushed the lmajercak_unlimited_ratelimits branch from 629323a to 2d561da Compare July 7, 2021 16:00
Signed-off-by: lmajercak-wish <[email protected]>
@lmajercak-wish lmajercak-wish force-pushed the lmajercak_unlimited_ratelimits branch from 2d561da to 0862dd8 Compare July 7, 2021 16:10
mattklein123
mattklein123 previously approved these changes Jul 7, 2021
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123
Copy link
Member

Oops looks like CI issue.

/wait

Signed-off-by: lmajercak-wish <[email protected]>
Signed-off-by: lmajercak-wish <[email protected]>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thank you!

@mattklein123 mattklein123 merged commit edab0ec into envoyproxy:main Jul 7, 2021
@lmajercak-wish
Copy link
Contributor Author

Thank you!

Thank you @mattklein123 !

zdmytriv pushed a commit to verygoodsecurity/ratelimit that referenced this pull request Aug 2, 2021
timcovar pushed a commit to goatapp/ratelimit that referenced this pull request Jan 16, 2024
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.

2 participants