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

ads: support envoy filter local ratelimit. #859

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yuanqijing
Copy link
Contributor

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?:


@kmesh-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign nlgwcy for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

codecov bot commented Sep 15, 2024

Codecov Report

Attention: Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.

Project coverage is 53.21%. Comparing base (36825ab) to head (33591ee).
Report is 79 commits behind head on main.

Files with missing lines Patch % Lines
pkg/controller/ads/cache.go 0.00% 3 Missing ⚠️
Files with missing lines Coverage Δ
pkg/controller/ads/extensions/local_ratelimit.go 100.00% <100.00%> (ø)
pkg/controller/ads/cache.go 47.01% <0.00%> (-0.54%) ⬇️

... and 24 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 53caaa8...33591ee. Read the comment docs.

@yuanqijing yuanqijing changed the title [WIP] ads: support envoy filter local ratelimit. ads: support envoy filter local ratelimit. Sep 15, 2024
}
*/
message LocalRateLimit {
reserved 1 to 2;
Copy link
Member

Choose a reason for hiding this comment

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

why reserve?

Copy link
Contributor Author

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 ?

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

"enable_x_ratelimit_headers": ...,
"vh_rate_limits": ...,
"always_consume_default_token_bucket": {...},
"rate_limited_as_resource_exhausted": ...
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a 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;
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

@yuanqijing
Copy link
Contributor Author

First we need a proposal to better understand this implement

hi i have created a proposal pr in #873

@yuanqijing yuanqijing force-pushed the ads/ratelimit branch 2 times, most recently from 917ece0 to 007baba Compare September 19, 2024 14:49
@yuanqijing
Copy link
Contributor Author

@hzxuzhonghu hi, ratelimit use the same way to cut tcp connection as circuit breaker, it can be merged after #570.

@yuanqijing yuanqijing force-pushed the ads/ratelimit branch 2 times, most recently from cdf2d67 to 8b988d1 Compare September 19, 2024 15:16
__type(value, struct ratelimit_value);
__uint(max_entries, 1000);
__uint(map_flags, BPF_F_NO_PREALLOC);
} ratelimit_map SEC(".maps");
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated.

@@ -181,6 +182,10 @@ int filter_chain_manager(ctx_buff_t *ctx)
if (filter_chain == NULL) {
return KMESH_TAIL_CALL_RET(-1);
}

/* ratelimit check */
Local_rate_limit__check_and_take(filter_chain, &addr, ctx);
Copy link
Member

Choose a reason for hiding this comment

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

This is ratelimit on filterchain, where did you support rate limit on listener

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, the ratelimit takes on filterchain, maybe i express it incorrect. The EnvoyFilter YAML object applies to the filter chain, and the rate limit configuration is defined inside the filter. A listener includes multiple filter chains. In eBPF, the listener_manager tail calls the filter_chain_manager.

@@ -0,0 +1,56 @@
package extensions
Copy link
Member

Choose a reason for hiding this comment

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

Add copyright

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

const LocalRateLimit = "envoy.filters.tcp.local_ratelimit"

// NewLocalRateLimit constructs a new LocalRateLimit filter wrapper.
func NewLocalRateLimit(filter *listenerv3.Filter) (*listener.Filter_LocalRateLimit, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Any UT or E2E test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hi, i added ut tests.

@tacslon
Copy link
Contributor

tacslon commented Oct 11, 2024

lgtm, and your test report(google doc) can be pasted here to show your test results @yuanqijing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants