-
Notifications
You must be signed in to change notification settings - Fork 5.3k
rate limit: add local rate limit network filter #9354
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
29164d9
rate limit: add local rate limit network filter
mattklein123 2e12407
Merge remote-tracking branch 'origin/master' into local_rate_limit
mattklein123 db8024c
update to use CAS loop
mattklein123 b012e3a
Merge remote-tracking branch 'origin/master' into local_rate_limit
mattklein123 cfd54c1
comments
mattklein123 443a30f
Merge branch 'master' into local_rate_limit
mattklein123 b4aec8b
remove file
mattklein123 568ac1b
fix
mattklein123 1f76a21
Merge remote-tracking branch 'origin/master' into local_rate_limit
mattklein123 e4bfd50
add thread synchronizer
mattklein123 7bdb15b
comments
mattklein123 962f5c9
Merge remote-tracking branch 'origin/master' into local_rate_limit
mattklein123 564bee9
Merge remote-tracking branch 'origin/master' into local_rate_limit
mattklein123 d1f51d3
comments
mattklein123 8ff63ed
fix docs
mattklein123 f26e679
Merge remote-tracking branch 'origin/master' into local_rate_limit
mattklein123 fdfd2dc
Merge branch 'master' into local_rate_limit
mattklein123 5e1fd44
fixes
mattklein123 a8d2f8f
Merge remote-tracking branch 'origin/master' into local_rate_limit
mattklein123 c3a7da6
merge master, fix format, comments
mattklein123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
api/envoy/config/filter/network/local_rate_limit/v2alpha/BUILD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = [ | ||
| "//envoy/api/v2/core:pkg", | ||
| "//envoy/type:pkg", | ||
| ], | ||
| ) |
40 changes: 40 additions & 0 deletions
40
api/envoy/config/filter/network/local_rate_limit/v2alpha/local_rate_limit.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.config.filter.network.local_rate_limit.v2alpha; | ||
|
|
||
| import "envoy/api/v2/core/base.proto"; | ||
| import "envoy/type/token_bucket.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.config.filter.network.local_rate_limit.v2alpha"; | ||
| option java_outer_classname = "LocalRateLimitProto"; | ||
| option java_multiple_files = true; | ||
|
|
||
| // [#protodoc-title: Local rate limit] | ||
| // Local rate limit :ref:`configuration overview <config_network_filters_local_rate_limit>`. | ||
| // [#extension: envoy.filters.network.local_ratelimit] | ||
|
|
||
| message LocalRateLimit { | ||
| // The prefix to use when emitting :ref:`statistics | ||
| // <config_network_filters_local_rate_limit_stats>`. | ||
| string stat_prefix = 1 [(validate.rules).string = {min_bytes: 1}]; | ||
|
|
||
| // The token bucket configuration to use for rate limiting connections that are processed by the | ||
| // filter's filter chain. Each incoming connection processed by the filter consumes a single | ||
| // token. If the token is available, the connection will be allowed. If no tokens are available, | ||
| // the connection will be immediately closed. | ||
| // | ||
| // .. note:: | ||
| // In the current implementation each filter and filter chain has an independent rate limit. | ||
| // | ||
| // .. note:: | ||
| // In the current implementation the token bucket's :ref:`fill_interval | ||
| // <envoy_api_field_type.TokenBucket.fill_interval>` must be >= 50ms to avoid too aggressive | ||
| // refills. | ||
| type.TokenBucket token_bucket = 2 [(validate.rules).message = {required: true}]; | ||
|
|
||
| // Runtime flag that controls whether the filter is enabled or not. If not specified, defaults | ||
| // to enabled. | ||
| api.v2.core.RuntimeFeatureFlag runtime_enabled = 3; | ||
| } |
14 changes: 14 additions & 0 deletions
14
api/envoy/config/filter/network/local_rate_limit/v3alpha/BUILD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = [ | ||
| "//envoy/api/v3alpha/core:pkg", | ||
| "//envoy/config/filter/network/local_rate_limit/v2alpha:pkg", | ||
| "//envoy/type/v3alpha:pkg", | ||
| "@com_github_cncf_udpa//udpa/annotations:pkg", | ||
| ], | ||
| ) |
45 changes: 45 additions & 0 deletions
45
api/envoy/config/filter/network/local_rate_limit/v3alpha/local_rate_limit.proto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.config.filter.network.local_rate_limit.v3alpha; | ||
|
|
||
| import "envoy/api/v3alpha/core/base.proto"; | ||
| import "envoy/type/v3alpha/token_bucket.proto"; | ||
|
|
||
| import "udpa/annotations/versioning.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.config.filter.network.local_rate_limit.v3alpha"; | ||
| option java_outer_classname = "LocalRateLimitProto"; | ||
| option java_multiple_files = true; | ||
|
|
||
| // [#protodoc-title: Local rate limit] | ||
| // Local rate limit :ref:`configuration overview <config_network_filters_local_rate_limit>`. | ||
| // [#extension: envoy.filters.network.local_ratelimit] | ||
|
|
||
| message LocalRateLimit { | ||
| option (udpa.annotations.versioning).previous_message_type = | ||
| "envoy.config.filter.network.local_rate_limit.v2alpha.LocalRateLimit"; | ||
|
|
||
| // The prefix to use when emitting :ref:`statistics | ||
| // <config_network_filters_local_rate_limit_stats>`. | ||
| string stat_prefix = 1 [(validate.rules).string = {min_bytes: 1}]; | ||
|
|
||
| // The token bucket configuration to use for rate limiting connections that are processed by the | ||
| // filter's filter chain. Each incoming connection processed by the filter consumes a single | ||
| // token. If the token is available, the connection will be allowed. If no tokens are available, | ||
| // the connection will be immediately closed. | ||
| // | ||
| // .. note:: | ||
| // In the current implementation each filter and filter chain has an independent rate limit. | ||
| // | ||
| // .. note:: | ||
| // In the current implementation the token bucket's :ref:`fill_interval | ||
| // <envoy_api_field_type.v3alpha.TokenBucket.fill_interval>` must be >= 50ms to avoid too | ||
| // aggressive refills. | ||
| type.v3alpha.TokenBucket token_bucket = 2 [(validate.rules).message = {required: true}]; | ||
|
|
||
| // Runtime flag that controls whether the filter is enabled or not. If not specified, defaults | ||
| // to enabled. | ||
| api.v3alpha.core.RuntimeFeatureFlag runtime_enabled = 3; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.type; | ||
|
|
||
| import "google/protobuf/duration.proto"; | ||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.type"; | ||
| option java_outer_classname = "TokenBucketProto"; | ||
| option java_multiple_files = true; | ||
|
|
||
| // [#protodoc-title: Token bucket] | ||
|
|
||
| // Configures a token bucket, typically used for rate limiting. | ||
| message TokenBucket { | ||
| // The maximum tokens that the bucket can hold. This is also the number of tokens that the bucket | ||
| // initially contains. | ||
| uint32 max_tokens = 1 [(validate.rules).uint32 = {gt: 0}]; | ||
|
|
||
| // The number of tokens added to the bucket during each fill interval. If not specified, defaults | ||
| // to a single token. | ||
| google.protobuf.UInt32Value tokens_per_fill = 2 [(validate.rules).uint32 = {gt: 0}]; | ||
|
|
||
| // The fill interval that tokens are added to the bucket. During each fill interval | ||
| // `tokens_per_fill` are added to the bucket. The bucket will never contain more than | ||
| // `max_tokens` tokens. | ||
| google.protobuf.Duration fill_interval = 3 [(validate.rules).duration = { | ||
| required: true | ||
| gt {} | ||
| }]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.type.v3alpha; | ||
|
|
||
| import "google/protobuf/duration.proto"; | ||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "udpa/annotations/versioning.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.type.v3alpha"; | ||
| option java_outer_classname = "TokenBucketProto"; | ||
| option java_multiple_files = true; | ||
|
|
||
| // [#protodoc-title: Token bucket] | ||
|
|
||
| // Configures a token bucket, typically used for rate limiting. | ||
| message TokenBucket { | ||
| option (udpa.annotations.versioning).previous_message_type = "envoy.type.TokenBucket"; | ||
|
|
||
| // The maximum tokens that the bucket can hold. This is also the number of tokens that the bucket | ||
| // initially contains. | ||
| uint32 max_tokens = 1 [(validate.rules).uint32 = {gt: 0}]; | ||
|
|
||
| // The number of tokens added to the bucket during each fill interval. If not specified, defaults | ||
| // to a single token. | ||
| google.protobuf.UInt32Value tokens_per_fill = 2 [(validate.rules).uint32 = {gt: 0}]; | ||
|
|
||
| // The fill interval that tokens are added to the bucket. During each fill interval | ||
| // `tokens_per_fill` are added to the bucket. The bucket will never contain more than | ||
| // `max_tokens` tokens. | ||
| google.protobuf.Duration fill_interval = 3 [(validate.rules).duration = { | ||
| required: true | ||
| gt {} | ||
| }]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,5 @@ Network filters | |
| */empty/* | ||
| */v1alpha1/* | ||
| */v2/* | ||
| */v2alpha/* | ||
| */v2alpha1/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
docs/root/configuration/listeners/network_filters/local_rate_limit_filter.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| .. _config_network_filters_local_rate_limit: | ||
|
|
||
| Local rate limit | ||
| ================ | ||
|
|
||
| * Local rate limiting :ref:`architecture overview <arch_overview_local_rate_limit>` | ||
| * :ref:`v2 API reference | ||
| <envoy_api_msg_config.filter.network.local_rate_limit.v2alpha.LocalRateLimit>` | ||
| * This filter should be configured with the name *envoy.filters.network.local_ratelimit*. | ||
|
|
||
mattklein123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .. note:: | ||
| Global rate limiting is also supported via the :ref:`global rate limit filter | ||
| <config_network_filters_rate_limit>`. | ||
|
|
||
| Overview | ||
| -------- | ||
|
|
||
| The local rate limit filter applies a :ref:`token bucket | ||
| <envoy_api_field_config.filter.network.local_rate_limit.v2alpha.LocalRateLimit.token_bucket>` rate | ||
| limit to incoming connections that are processed by the filter's filter chain. Each connection | ||
| processed by the filter utilizes a single token, and if no tokens are available, the connection will | ||
| be immediately closed without further filter iteration. | ||
|
|
||
| .. note:: | ||
| In the current implementation each filter and filter chain has an independent rate limit. | ||
|
|
||
| .. _config_network_filters_local_rate_limit_stats: | ||
|
|
||
| Statistics | ||
| ---------- | ||
|
|
||
| Every configured local rate limit filter has statistics rooted at *local_ratelimit.<stat_prefix>.* | ||
| with the following statistics: | ||
|
|
||
| .. csv-table:: | ||
| :header: Name, Type, Description | ||
| :widths: 1, 1, 2 | ||
|
|
||
| rate_limited, Counter, Total connections that have been closed due to rate limit exceeded | ||
|
|
||
| Runtime | ||
| ------- | ||
|
|
||
| The local rate limit filter can be runtime feature flagged via the :ref:`enabled | ||
| <envoy_api_field_config.filter.network.local_rate_limit.v2alpha.LocalRateLimit.runtime_enabled>` | ||
| configuration field. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.