-
Notifications
You must be signed in to change notification settings - Fork 270
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
base: main
Are you sure you want to change the base?
Conversation
0536b1f
to
8636f8e
Compare
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
8636f8e
to
b580e65
Compare
af63198
to
6d9a4a7
Compare
adb0cc9
to
15ec396
Compare
15ec396
to
3af685b
Compare
impl LocalRateLimit { | ||
pub fn new_no_overrides( |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
This adds the local_rate_limit module to the server-policy crate, that
ServerPolicy
uses for its newlocal_rate_limit
field, containingthree 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 thePartialEq
requirement made it very hard to follow.
Server
OTOH doesn't reallyrequire that trait, so I was able to remove it and accommodate the
limiters.
I made sure to avoid pulling the dashmap dependency in
governor
;Ihaven'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 thelocal_rate_limit
module above to perform the rate-limit check.