Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Exclude gRPC health check requests from rate limiting in history & matching service #6036

Merged
merged 13 commits into from
Jun 4, 2024

Conversation

gow
Copy link
Contributor

@gow gow commented May 30, 2024

What changed?

The rate limit interceptor will now ignore gRPC health check requests and doesn't apply any rate limiters.

Why?

Health check requests should never be rate limited.

How did you test it?

Added unit tests to assert interceptor behavior.

Potential risks

N/A

Documentation

N/A

Is hotfix candidate?

no

@gow gow requested a review from a team as a code owner May 30, 2024 22:18
@gow gow requested review from dnr, yycptt and dynajoe May 30, 2024 22:19
Copy link
Member

@dynajoe dynajoe left a comment

Choose a reason for hiding this comment

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

Overall this approach makes sense.

If a method exists in the map with a value of 0 that indicates it would consume 0 tokens from a periodically filled token bucket. So therefore, don't bother trying to consume and return nil to proceed.

If a method does NOT exist in the map, token will be 0 due to go zero value semantics. However, existence check overrides token value with the default of 1. This makes the !ok check extremely critical.

Out of curiosity, I wonder what happens if the value is less than zero? I recognize that any odd handling would not be a new issue introduced by this PR.

common/rpc/interceptor/rate_limit_test.go Outdated Show resolved Hide resolved
Copy link
Member

@dnr dnr left a comment

Choose a reason for hiding this comment

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

I like Tim's suggestion too

common/rpc/interceptor/rate_limit_test.go Outdated Show resolved Hide resolved
common/authorization/default_authorizer_test.go Outdated Show resolved Hide resolved
common/authorization/frontend_api.go Outdated Show resolved Hide resolved
@dnr
Copy link
Member

dnr commented May 31, 2024

Just because there's so many layers of interceptors and behavior, it might be nice to do a manual test also: set the rate limit really low and use evans or some other cli grpc tool to just run a bunch of health checks and non-health-checks and make sure it does what we want.

Co-authored-by: Tim Deeb-Swihart <409226+tdeebswihart@users.noreply.github.com>
@gow
Copy link
Contributor Author

gow commented May 31, 2024

Out of curiosity, I wonder what happens if the value is less than zero? I recognize that any odd handling would not be a new issue introduced by this PR.

The value indicates how many tokens to consume per hit for a given endpoint. So any value <= 0 should be ignored. Tim's suggestion covers that now. Without it would run into some weirdness unless underlying libraries safely handle invalid values.

@gow
Copy link
Contributor Author

gow commented Jun 4, 2024

Manually verified using postman.

@gow gow enabled auto-merge (squash) June 4, 2024 17:16
@gow gow merged commit 77a380c into main Jun 4, 2024
42 checks passed
@gow gow deleted the cg_healthcheck_ratelimit branch June 4, 2024 19:26
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants