-
Notifications
You must be signed in to change notification settings - Fork 69
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
ads: support envoy filter local ratelimit. #859
Conversation
5964c91
to
1c8d1bb
Compare
80747b0
to
17aa8b8
Compare
17aa8b8
to
e064980
Compare
Codecov ReportAttention: Patch coverage is
... and 69 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
b7ffc97
to
d12d047
Compare
api/filter/ratelimit.proto
Outdated
} | ||
*/ | ||
message LocalRateLimit { | ||
reserved 1 to 2; |
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.
why reserve?
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.
reserve for
{
"stat_prefix": ...,
"status": {...},
}
should i start token_bucket with number 1, or keep the number tag ?
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.
You can start from 1
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.
updated.
api/filter/ratelimit.proto
Outdated
"enable_x_ratelimit_headers": ..., | ||
"vh_rate_limits": ..., | ||
"always_consume_default_token_bucket": {...}, | ||
"rate_limited_as_resource_exhausted": ... |
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.
if other fields not supported, please remove them. Add once we support it
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.
just remove the comments? i copy the definition from envoy api.
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.
First we need a proposal to better understand this implement
}; | ||
|
||
struct ratelimit_value { | ||
__u64 last_topup; |
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.
can you add a comment about what is this
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.
updated.
hi i have created a proposal pr in #873 |
917ece0
to
007baba
Compare
@hzxuzhonghu hi, ratelimit use the same way to cut tcp connection as circuit breaker, it can be merged after #570. |
cdf2d67
to
8b988d1
Compare
__type(value, struct ratelimit_value); | ||
__uint(max_entries, 1000); | ||
__uint(map_flags, BPF_F_NO_PREALLOC); | ||
} ratelimit_map SEC(".maps"); |
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.
please keep consistent with other map name.
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.
updated.
8b988d1
to
6d4e280
Compare
In kmesh, we are a little different, we can only ratelimit on the client side now. So take the example here, though it is http. https://istio.io/latest/docs/tasks/policy-enforcement/rate-limit/#local-rate-limit
It should be applied on each client instance, not on all the instances of a node. |
Understood, so the key point here is whether intances in a node share a token bucket. Envoy using option 2, but in kmesh we use option1 ? Is my understanding correct? |
Envoy can use both, kmesh we can only use option 1 |
362207e
to
6876096
Compare
I have added a new field to distinguish different pods:
|
@hzxuzhonghu Hi I think there are 2 pending Issues:
|
Yes, i think its ok
@nlgwcy suggested using atomic update |
suggested atomic updates all addressed. #859 (comment) #859 (comment) |
if (topup > 0) { | ||
value->tokens += topup * settings->tokens_per_fill; | ||
if (value->tokens > settings->max_tokens) { | ||
value->tokens = settings->max_tokens; |
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.
This is not concurrent safe
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.
can this ensue concurent safe ? cause only one progress can add the value.
topup = (now - value->last_topup) / settings->fill_interval;
if (topup > 0) {
topup_time = value->last_topup + topup * settings->fill_interval;
if (__sync_bool_compare_and_swap(&value->last_topup, value->last_topup, topup_time)) {
delta = topup * settings->tokens_per_fill;
if (value->tokens + delta > settings->max_tokens) {
delta = settings->max_tokens - value->tokens;
}
__sync_fetch_and_add(&value->tokens, delta);
}
}
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.
@nlgwcy is an expert on this
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.
@nlgwcy hi, could this approach be used to avoid concurrent issues?
#include "listener/listener.pb-c.h" | ||
|
||
struct ratelimit_key { | ||
union { |
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.
why use union here
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.
Using a union in the ratelimit_key structure improves scalability. If we need to limit HTTP connections in the future, we can reuse the same key structure. For example, we can add a structure for HTTP connections like this:
struct ratelimit_key {
union {
struct {
__u64 netns; /* Network namespace. */
__u32 ipv4; /* Destination IPv4 address. */
__u32 port; /* Destination port. */
__u32 family; /* Address family (e.g., AF_INET) */
} sk_skb;
struct {
__u32 http_method; /* HTTP method (e.g., GET, POST) */
__u32 http_version; /* HTTP version (e.g., 1.1, 2) */
__u32 http_port; /* HTTP port */
} http; // New HTTP connection related fields
} key;
};
/lgtm |
if (rate_limit__check_and_take(&key, &settings)) { | ||
BPF_LOG(INFO, FILTERCHAIN, "rate limit exceeded\n"); | ||
// TODO: remove this after #570 merged. | ||
#ifndef MARK_REJECTED |
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.
It's not needed anymore.
6876096
to
3f0c4e9
Compare
New changes are detected. LGTM label has been removed. |
/retest |
0c4da26
to
6bc5c4e
Compare
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: nlgwcy The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
6bc5c4e
to
102ce34
Compare
Signed-off-by: yuan <[email protected]>
553f30b
to
694e917
Compare
What type of PR is this?
support local rate limit.
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: