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 support for General RateLimit Policy #5363

Merged

Conversation

shadialtarsha
Copy link
Contributor

@shadialtarsha shadialtarsha commented May 15, 2023

PR adds support for a global rate limit policy that can be defined in the RateLimit service configuration.

Proposal: #5359
Fixes: #5357

Signed-off-by: Shadi Altarsha shadi.altarsha.94@gmail.com

@shadialtarsha shadialtarsha requested a review from a team as a code owner May 15, 2023 12:20
@shadialtarsha shadialtarsha requested review from stevesloka and sunjayBhatia and removed request for a team May 15, 2023 12:20
@codecov
Copy link

codecov bot commented May 16, 2023

Codecov Report

Merging #5363 (43c1205) into main (b5acf7f) will increase coverage by 0.07%.
The diff coverage is 97.43%.

❗ Current head 43c1205 differs from pull request most recent head 6f22159. Consider uploading reports for the commit 6f22159 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5363      +/-   ##
==========================================
+ Coverage   78.46%   78.53%   +0.07%     
==========================================
  Files         138      138              
  Lines       18896    18925      +29     
==========================================
+ Hits        14826    14863      +37     
+ Misses       3789     3783       -6     
+ Partials      281      279       -2     
Impacted Files Coverage Δ
pkg/config/parameters.go 86.26% <ø> (+0.13%) ⬆️
cmd/contour/serve.go 20.15% <50.00%> (+0.04%) ⬆️
cmd/contour/servecontext.go 83.37% <100.00%> (+0.07%) ⬆️
internal/dag/httpproxy_processor.go 92.89% <100.00%> (+0.78%) ⬆️
internal/dag/policy.go 95.91% <100.00%> (ø)

... and 2 files with indirect coverage changes

@shadialtarsha
Copy link
Contributor Author

Hey @sunjayBhatia @skriss and @tsaarni
I would appreciate a round of review on this PR
Thank you!

@shadialtarsha shadialtarsha force-pushed the general-rate-limit-policy branch 5 times, most recently from 6a8e2e6 to 5a199a5 Compare June 6, 2023 11:51
Copy link
Contributor

@davinci26 davinci26 left a comment

Choose a reason for hiding this comment

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

some comments around config generation

internal/dag/httpproxy_processor.go Outdated Show resolved Hide resolved
internal/dag/httpproxy_processor.go Outdated Show resolved Hide resolved
internal/dag/httpproxy_processor.go Outdated Show resolved Hide resolved
shadi-altarsha added 9 commits June 9, 2023 13:41
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
shadi-altarsha added 3 commits June 10, 2023 15:52
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
@shadialtarsha
Copy link
Contributor Author

@skriss and @sunjayBhatia
I would appreciate your review of this PR when you have time.
Thank you

Copy link
Contributor

@clayton-gonsalves clayton-gonsalves left a comment

Choose a reason for hiding this comment

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

we should also add a test to contour/internal/featuretests/v3/globalratelimit_test.go

internal/dag/httpproxy_processor.go Outdated Show resolved Hide resolved
internal/dag/httpproxy_processor.go Outdated Show resolved Hide resolved
internal/dag/httpproxy_processor.go Show resolved Hide resolved
site/content/docs/main/guides/global-rate-limiting.md Outdated Show resolved Hide resolved
shadi-altarsha added 3 commits June 26, 2023 12:23
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
@shadialtarsha
Copy link
Contributor Author

Hey @sunjayBhatia
I would appreciate another round!

…policy

Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Copy link
Member

@skriss skriss 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 the PR @shadialtarsha, still making my way through it but a couple small comments so far.

apis/projectcontour/v1/httpproxy.go Outdated Show resolved Hide resolved
apis/projectcontour/v1/httpproxy.go Show resolved Hide resolved
shadi-altarsha added 2 commits July 11, 2023 11:39
…policy

Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
},
Domain: "contour",
DefaultGlobalRateLimitPolicy: &contour_api_v1.GlobalRateLimitPolicy{
Descriptors: []contour_api_v1.RateLimitDescriptor{
Copy link
Member

Choose a reason for hiding this comment

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

a drawback of adding to this test this way is we have to set "Disabled" on the HTTPProxies in all the cases where we don't expect a rate limit to be set, not a huge thing but makes the test coverage a little different

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, unfortunately, the way these tests are written doesn't allow multiple global rate limit services to be configured easily. All HTTPProxy uses the same RLS and that is why the opted-in by default.

Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
internal/dag/httpproxy_processor.go Outdated Show resolved Hide resolved
@@ -1138,6 +1140,7 @@ func (s *Server) getDAGBuilder(dbc dagBuilderConfig) *dag.Builder {
ConnectTimeout: dbc.connectTimeout,
GlobalExternalAuthorization: dbc.globalExternalAuthorizationService,
MaxRequestsPerConnection: dbc.maxRequestsPerConnection,
GlobalRateLimitService: dbc.globalRateLimitService,
Copy link
Member

Choose a reason for hiding this comment

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

xref #5458 this is another instance where we should probably apply this to at least the Ingress processor as well. I'm OK logging a follow-up issue since we don't currently support rate limiting in any way on Ingress.

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 that, thanks for pointing this out!

internal/dag/policy.go Show resolved Hide resolved
Signed-off-by: shadi-altarsha <shadi.altarsha@reddit.com>
Copy link
Member

@skriss skriss left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @shadialtarsha!

Comment on lines +177 to +184
// Make requests against the proxy, confirm a 429 response
// is now gotten since we've exceeded the rate limit.
res, ok := f.HTTP.RequestUntil(&e2e.HTTPRequestOpts{
Host: p.Spec.VirtualHost.Fqdn,
Condition: e2e.HasStatusCode(429),
})
require.NotNil(t, res, "request never succeeded")
require.Truef(t, ok, "expected 429 response code, got %d", res.StatusCode)
Copy link
Member

Choose a reason for hiding this comment

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

It's tough to get perfect validation for these tests, but I think in combo with reviewing the code + the unit test coverage, this is sufficient for an E2E.

@sunjayBhatia sunjayBhatia merged commit 95f3eab into projectcontour:main Jul 14, 2023
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note/minor A minor change that needs about a paragraph of explanation in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set Global RateLimit Policy inside Contour's Config
5 participants