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 rate-limiters to ServerPolicy #3305

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

alpeb
Copy link
Member

@alpeb alpeb commented Oct 29, 2024

This adds the local_rate_limit module to the server-policy crate, that
ServerPolicy uses for its new local_rate_limit field, containing
three optional rate-limiters: total, identity, overrides (this one is
really a vector of limiters, one per configured override).

I tried putting that under Protocol instead, but the PartialEq
requirement made it very hard to follow. Server OTOH doesn't really
require that trait, so I was able to remove it and accommodate the
limiters.

I made sure to avoid pulling the dashmap dependency in governor; I
haven't checked yet the necessity of the "jitter" and "quanta" features.

This temporarily overrides linkerd2-proxy-api dependency to pick changes
from linkerd/linkerd2-proxy-api#388

Update

The HttpPolicyService middleware has been expanded to call the local_rate_limit module above to perform the rate-limit check.

@alpeb alpeb requested a review from a team as a code owner October 29, 2024 17:40
@alpeb alpeb marked this pull request as draft October 29, 2024 17:59
@alpeb alpeb force-pushed the alpeb/server-policy-rate-limiter branch 5 times, most recently from 0536b1f to 8636f8e Compare October 29, 2024 22:19
This adds the local_rate_limit module to the server-policy crate, that
`ServerPolicy` uses for its new `local_rate_limit` field, containing
three optional rate-limiters: total, identity, overrides (this one is
really a vector of limiters, one per configured override).

I tried putting that under `Protocol` instead, but the `PartialEq`
requirement made it very hard to follow. `Server` OTOH doesn't really
require that trait, so I was able to remove it and accommodate the
limiters.

I made sure to avoid pulling the dashmap dependency in `governor`; I
haven't checked yet the necessity of the "jitter" and "quanta" features.

This temporarily overrides linkerd2-proxy-api dependency to pick changes
from linkerd/linkerd2-proxy-api#388
@alpeb alpeb force-pushed the alpeb/server-policy-rate-limiter branch from 8636f8e to b580e65 Compare October 29, 2024 22:19
linkerd/proxy/server-policy/Cargo.toml Outdated Show resolved Hide resolved
linkerd/proxy/server-policy/src/local_rate_limit.rs Outdated Show resolved Hide resolved
linkerd/proxy/server-policy/src/local_rate_limit.rs Outdated Show resolved Hide resolved
linkerd/proxy/server-policy/src/lib.rs Outdated Show resolved Hide resolved
@alpeb alpeb mentioned this pull request Oct 30, 2024
@alpeb alpeb force-pushed the alpeb/server-policy-rate-limiter branch from af63198 to 6d9a4a7 Compare October 30, 2024 20:15
@alpeb alpeb marked this pull request as ready for review October 31, 2024 00:40
linkerd/proxy/server-policy/src/lib.rs Outdated Show resolved Hide resolved
linkerd/proxy/server-policy/src/local_rate_limit.rs Outdated Show resolved Hide resolved
linkerd/proxy/server-policy/src/local_rate_limit.rs Outdated Show resolved Hide resolved
linkerd/proxy/server-policy/src/lib.rs Outdated Show resolved Hide resolved
linkerd/app/inbound/src/policy/http.rs Show resolved Hide resolved
@olix0r olix0r self-assigned this Nov 1, 2024
@alpeb alpeb force-pushed the alpeb/server-policy-rate-limiter branch from adb0cc9 to 15ec396 Compare November 5, 2024 13:23
@alpeb alpeb force-pushed the alpeb/server-policy-rate-limiter branch from 15ec396 to 3af685b Compare November 5, 2024 16:44
linkerd/app/inbound/src/policy/http.rs Show resolved Hide resolved
linkerd/app/inbound/src/policy/http.rs Show resolved Hide resolved
linkerd/proxy/server-policy/src/lib.rs Show resolved Hide resolved
Comment on lines +47 to +48
impl LocalRateLimit {
pub fn new_no_overrides(
Copy link
Member

Choose a reason for hiding this comment

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

We would typically feature-gate this to assert that it's only used for tests.

Comment on lines +395 to +407
let rsp = svc
.call(
::http::Request::builder()
.body(hyper::Body::default())
.unwrap(),
)
.await
.expect("serves");
let permit = rsp
.extensions()
.get::<HttpRoutePermit>()
.expect("permitted");
assert_eq!(permit.labels.route.route, rmeta);
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 some way that we could actually test actually fails when a rate limit is exceeded? E.g. Set of rate limit of 1 and send 2 requests.

linkerd/app/inbound/src/policy/http/tests.rs Show resolved Hide resolved
linkerd/app/inbound/src/http/server.rs Show resolved Hide resolved
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