-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 3 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
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", | ||
| ], | ||
| ) |
31 changes: 31 additions & 0 deletions
31
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,31 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.config.filter.network.local_rate_limit.v2alpha; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.config.filter.network.local_rate_limit.v2alpha"; | ||
| option java_outer_classname = "LocalRateLimitProto"; | ||
| option java_multiple_files = true; | ||
|
|
||
| import "envoy/api/v2/core/base.proto"; | ||
| import "envoy/type/token_bucket.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| // [#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. Each incoming connection | ||
| // 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. | ||
| 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 enabled = 3; | ||
|
mattklein123 marked this conversation as resolved.
Outdated
|
||
| } | ||
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", | ||
| ], | ||
| ) |
36 changes: 36 additions & 0 deletions
36
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,36 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.config.filter.network.local_rate_limit.v3alpha; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.config.filter.network.local_rate_limit.v3alpha"; | ||
| option java_outer_classname = "LocalRateLimitProto"; | ||
| option java_multiple_files = true; | ||
|
|
||
| import "envoy/api/v3alpha/core/base.proto"; | ||
| import "envoy/type/v3alpha/token_bucket.proto"; | ||
|
|
||
| import "udpa/annotations/versioning.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| // [#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. Each incoming connection | ||
| // 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. | ||
| 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 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; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.type"; | ||
| option java_outer_classname = "TokenBucketProto"; | ||
| option java_multiple_files = true; | ||
|
|
||
| import "google/protobuf/duration.proto"; | ||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| // [#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. Must be greater than 50ms. During | ||
|
mattklein123 marked this conversation as resolved.
Outdated
|
||
| // 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 {nanos: 50000000} | ||
| }]; | ||
| } | ||
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; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.type.v3alpha"; | ||
| option java_outer_classname = "TokenBucketProto"; | ||
| option java_multiple_files = true; | ||
|
|
||
| import "google/protobuf/duration.proto"; | ||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "udpa/annotations/versioning.proto"; | ||
|
|
||
| import "validate/validate.proto"; | ||
|
|
||
| // [#protodoc-title: Token bucket] | ||
|
|
||
| // Configures a token bucket, typically used for rate limiting. | ||
| message TokenBucket { | ||
|
mattklein123 marked this conversation as resolved.
|
||
| 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. Must be greater than 50ms. 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 {nanos: 50000000} | ||
| }]; | ||
| } | ||
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
38 changes: 38 additions & 0 deletions
38
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,38 @@ | ||
| .. _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.
|
||
| 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. Each connection utilizes a single token, and if no tokens are | ||
|
mattklein123 marked this conversation as resolved.
Outdated
|
||
| available, the connection will be immediately closed without further filter iteration. | ||
|
|
||
| .. _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_limit, Counter, Total connections that have been closed due to rate limit exceeded | ||
|
mattklein123 marked this conversation as resolved.
Outdated
mattklein123 marked this conversation as resolved.
Outdated
|
||
|
|
||
| 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.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
11 changes: 11 additions & 0 deletions
11
docs/root/intro/arch_overview/other_features/local_rate_limiting.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,11 @@ | ||
| .. _arch_overview_local_rate_limit: | ||
|
|
||
| Local rate limiting | ||
| =================== | ||
|
|
||
| Envoy supports local (non-distributed) rate limiting of L4 connections via the | ||
| :ref:`local rate limit filter <config_network_filters_local_rate_limit>`. | ||
|
|
||
| Note that Envoy also supports :ref:`global rate limiting <arch_overview_global_rate_limit>`. Local | ||
| rate limiting can be used in conjunction with global rate limiting to reduce load on the global | ||
| rate limit service. |
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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ Other features | |
| .. toctree:: | ||
| :maxdepth: 2 | ||
|
|
||
| local_rate_limiting | ||
| global_rate_limiting | ||
| scripting | ||
| ip_transparency | ||
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.