-
Notifications
You must be signed in to change notification settings - Fork 5.5k
extensions: add http bandwidth limit filter #16358
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 40 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
4f21be4
add bandwidth limit filter core functionality and UTs
nitgoy e2e9ff3
docs and format fix
nitgoy 42ad169
try fix docs precheck error
nitgoy bcb06b3
fix format
nitgoy efc4d21
fix spelling
nitgoy 0e3ae50
use duration type for fill_interval proto field
nitgoy cab2a33
revert token bucket changes
nitgoy 5059bc2
format fix
nitgoy f4cb248
try format fix again
nitgoy e038f7d
fix format pre
nitgoy 7052748
try fix clang tidy
nitgoy d128ac8
fix build errors
nitgoy e6d805b
Merge from upstream
nitgoy eb74ffc
add more test assertions
nitgoy 7cf3f4f
fix docs
nitgoy ea77fde
test coverage fixes
nitgoy fafa873
format fix
nitgoy d92b8d4
merge from upstream
nitgoy 7d21500
minor: version history
nitgoy 573f2da
readd deleted method
nitgoy 75e8874
format fix
nitgoy 530c569
update owners
nitgoy 68c5c24
minor: comment
nitgoy 85642de
Merge branch 'main' of https://github.com/envoyproxy/envoy into bwlfi…
nitgoy 2dae1e8
Merge branch 'main' into bwlfilter
nitgoy 6371854
Merge branch 'bwlfilter' of github.com:nitgoy/envoy into bwlfilter
nitgoy c3b8ef0
Merge branch 'main' into bwlfilter
nitgoy f942789
fix format
nitgoy e999e75
fix typo
nitgoy 40af12a
Merge branch 'main' into bwlfilter
nitgoy ecc7dec
move example config to separate yaml
nitgoy 99458ed
Merge branch 'bwlfilter' of github.com:nitgoy/envoy into bwlfilter
nitgoy d6c7d41
revert merge typo
nitgoy 9356621
fix
nitgoy 62ca7fe
try fix build
nitgoy 9c08bf5
more doc improvements
nitgoy cdb60a0
fix format
nitgoy ce53ad6
address comment
nitgoy f7e39d9
address doc comments
nitgoy 4fc4837
rename proto enum values
nitgoy 54302e9
make getConfig return ref
nitgoy 2a70c24
rename enum and stats values
nitgoy 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
12 changes: 12 additions & 0 deletions
12
api/envoy/extensions/filters/http/bandwidth_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,12 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = [ | ||
| "//envoy/config/core/v3:pkg", | ||
| "@com_github_cncf_udpa//udpa/annotations:pkg", | ||
| ], | ||
| ) |
70 changes: 70 additions & 0 deletions
70
api/envoy/extensions/filters/http/bandwidth_limit/v3alpha/bandwidth_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,70 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.filters.http.bandwidth_limit.v3alpha; | ||
|
|
||
| import "envoy/config/core/v3/base.proto"; | ||
|
|
||
| import "google/protobuf/duration.proto"; | ||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.filters.http.bandwidth_limit.v3alpha"; | ||
| option java_outer_classname = "BandwidthLimitProto"; | ||
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).work_in_progress = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Bandwidth limit] | ||
| // Bandwidth limit :ref:`configuration overview <config_http_filters_bandwidth_limit>`. | ||
| // [#extension: envoy.filters.http.bandwidth_limit] | ||
|
|
||
| // [#next-free-field: 6] | ||
| message BandwidthLimit { | ||
| // Defines the mode for the bandwidth limit filter. | ||
| // Values represent bitmask. | ||
| enum EnableMode { | ||
| // Filter is disabled. | ||
| DISABLED = 0; | ||
|
|
||
| // Filter enabled only for incoming traffic. | ||
| DECODE = 1; | ||
|
|
||
| // Filter enabled only for outgoing traffic. | ||
| ENCODE = 2; | ||
|
|
||
| // Filter enabled for both incoming and outgoing traffic. | ||
| DECODE_AND_ENCODE = 3; | ||
| } | ||
|
nitgoy marked this conversation as resolved.
|
||
|
|
||
| // The human readable prefix to use when emitting stats. | ||
| string stat_prefix = 1 [(validate.rules).string = {min_len: 1}]; | ||
|
|
||
| // The enable mode for the bandwidth limit filter. | ||
| // Default is Disabled. | ||
| EnableMode enable_mode = 2 [(validate.rules).enum = {defined_only: true}]; | ||
|
|
||
| // The limit supplied in KiB/s. | ||
| // | ||
| // .. note:: | ||
| // It's fine for the limit to be unset for the global configuration since the bandwidth limit | ||
| // can be applied at a the virtual host or route level. Thus, the limit must be set for the | ||
| // per route configuration otherwise the config will be rejected. | ||
| // | ||
| // .. note:: | ||
| // When using per route configuration, the limit becomes unique to that route. | ||
| // | ||
| google.protobuf.UInt64Value limit_kbps = 3 [(validate.rules).uint64 = {gte: 1}]; | ||
|
|
||
| // Optional Fill interval in milliseconds for the token refills. Defaults to 50ms. | ||
| // It must be at least 20ms to avoid too aggressive refills. | ||
| google.protobuf.Duration fill_interval = 4 [(validate.rules).duration = { | ||
| lte {seconds: 1} | ||
| gte {nanos: 20000000} | ||
| }]; | ||
|
|
||
| // Runtime flag that controls whether the filter is enabled or not. If not specified, defaults | ||
| // to enabled. | ||
| config.core.v3.RuntimeFeatureFlag runtime_enabled = 5; | ||
| } | ||
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
65 changes: 65 additions & 0 deletions
65
docs/root/configuration/http/http_filters/_include/bandwidth-limit-filter.yaml
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,65 @@ | ||
| static_resources: | ||
| listeners: | ||
| - address: | ||
| socket_address: | ||
| address: 0.0.0.0 | ||
| port_value: 8000 | ||
| filter_chains: | ||
| - filters: | ||
| - name: envoy.filters.network.http_connection_manager | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager | ||
| codec_type: AUTO | ||
| stat_prefix: ingress_http | ||
| route_config: | ||
| name: local_route | ||
| virtual_hosts: | ||
| - name: local_service | ||
| domains: ["*"] | ||
| routes: | ||
| - match: { prefix: "/path/with/bandwidth/limit" } | ||
| route: { cluster: service_protected_by_bandwidth_limit } | ||
| typed_per_filter_config: | ||
| envoy.filters.http.bandwidth_limit: | ||
| "@type": type.googleapis.com/envoy.extensions.filters.http.bandwidth_limit.v3alpha.BandwidthLimit | ||
| stat_prefix: bandwidth_limiter_custom_route | ||
| enable_mode: DECODE_AND_ENCODE | ||
| limit_kbps: 500 | ||
| fill_interval: 0.1s | ||
| - match: { prefix: "/" } | ||
| route: { cluster: web_service } | ||
| http_filters: | ||
| - name: envoy.filters.http.bandwidth_limit | ||
| typed_config: | ||
| "@type": type.googleapis.com/envoy.extensions.filters.http.bandwidth_limit.v3alpha.BandwidthLimit | ||
| stat_prefix: bandwidth_limiter_default | ||
| - name: envoy.filters.http.router | ||
| typed_config: {} | ||
|
|
||
| clusters: | ||
| - name: service_protected_by_bandwidth_limit | ||
| connect_timeout: 0.25s | ||
| type: STRICT_DNS | ||
| lb_policy: ROUND_ROBIN | ||
| load_assignment: | ||
| cluster_name: service1 | ||
| endpoints: | ||
| - lb_endpoints: | ||
| - endpoint: | ||
| address: | ||
| socket_address: | ||
| address: web_service | ||
| port_value: 9000 | ||
| - name: web_service | ||
| connect_timeout: 0.25s | ||
| type: STRICT_DNS | ||
| lb_policy: ROUND_ROBIN | ||
| load_assignment: | ||
| cluster_name: service1 | ||
| endpoints: | ||
| - lb_endpoints: | ||
| - endpoint: | ||
| address: | ||
| socket_address: | ||
| address: web_service | ||
| port_value: 9000 |
64 changes: 64 additions & 0 deletions
64
docs/root/configuration/http/http_filters/bandwidth_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,64 @@ | ||
| .. _config_http_filters_bandwidth_limit: | ||
|
|
||
| Bandwidth limit | ||
| ==================== | ||
|
|
||
| * Bandwidth limiting :ref:`architecture overview <arch_overview_bandwidth_limit>` | ||
| * :ref:`v3 API reference <envoy_v3_api_msg_extensions.filters.http.bandwidth_limit.v3alpha.BandwidthLimit>` | ||
| * This filter should be configured with the name ``envoy.filters.http.bandwidth_limit``. | ||
|
|
||
| The HTTP Bandwidth limit filter limits the size of data flow to the max bandwidth set in the ``limit_kbps`` | ||
| when the request's route or virtual host has a per filter | ||
| :ref:`bandwidth limit configuration <envoy_v3_api_msg_extensions.filters.http.bandwidth_limit.v3alpha.BandwidthLimit>`. | ||
|
|
||
| If the bandwidth limit has been exhausted the filter stops further transfer until more bandwidth gets allocated | ||
| according to the ``fill_interval`` (default is 50 milliseconds). If the connection buffer fills up with accumulated | ||
| data then the source of data will have ``readDisable(true)`` set as described in the :repo:`flow control doc<source/docs/flow_control.md>`. | ||
|
|
||
| .. note:: | ||
| The token bucket is shared across all workers, thus the limits are applied per Envoy process. | ||
|
|
||
| Example configuration | ||
| --------------------- | ||
|
|
||
| Example filter configuration for a globally disabled bandwidth limiter but enabled for a specific route: | ||
|
|
||
| .. literalinclude:: _include/bandwidth-limit-filter.yaml | ||
| :language: yaml | ||
| :lines: 11-53 | ||
| :emphasize-lines: 9-25 | ||
| :caption: :download:`bandwidth-limit-filter.yaml <_include/bandwidth-limit-filter.yaml>` | ||
|
|
||
| Note that if this filter is configured as globally disabled and there are no virtual host or route level | ||
| token buckets, no bandwidth limiting will be applied. | ||
|
|
||
| Statistics | ||
| ---------- | ||
|
|
||
| The HTTP bandwidth limit filter outputs statistics in the ``<stat_prefix>.http_bandwidth_limit.`` namespace. | ||
|
|
||
| .. csv-table:: | ||
| :header: Name, Type, Description | ||
| :widths: 1, 1, 2 | ||
|
|
||
| decode_enabled, Counter, Total number of request streams for which the bandwidth limiter was consulted | ||
| decode_pending, GAUGE, Number of request streams which the currently pending transfer in bandwidth limiter | ||
| decode_incoming_size, GAUGE, Size in bytes of incoming request data to bandwidth limiter | ||
| decode_allowed_size, GAUGE, Size in bytes of outgoing request data from bandwidth limiter | ||
| decode_transfer_duration, HISTOGRAM, Total time (including added delay) it took for the request stream transfer | ||
| encode_enabled, Counter, Total number of response streams for which the bandwidth limiter was consulted | ||
| encode_pending, GAUGE, Number of response streams which the currently pending transfer in bandwidth limiter | ||
| encode_incoming_size, GAUGE, Size in bytes of incoming response data to bandwidth limiter | ||
| encode_allowed_size, GAUGE, Size in bytes of outgoing response data from bandwidth limiter | ||
| encode_transfer_duration, HISTOGRAM, Total time (including added delay) it took for the response stream transfer | ||
|
|
||
| .. _config_http_filters_bandwidth_limit_runtime: | ||
|
|
||
| Runtime | ||
| ------- | ||
|
|
||
| The HTTP bandwidth limit filter supports the following runtime settings: | ||
|
|
||
| The bandwidth limit filter can be runtime feature flagged via the :ref:`enabled | ||
| <envoy_v3_api_field_extensions.filters.http.bandwidth_limit.v3alpha.BandwidthLimit.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
9 changes: 9 additions & 0 deletions
9
docs/root/intro/arch_overview/other_features/bandwidth_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,9 @@ | ||
| .. _arch_overview_bandwidth_limit: | ||
|
|
||
| Bandwidth limiting | ||
| =================== | ||
|
|
||
| Envoy supports local (non-distributed) bandwidth limiting of HTTP requests and response via the | ||
| :ref:`HTTP bandwidth limit filter <config_http_filters_bandwidth_limit>`. This can be activated | ||
| globally at the listener level or at a more specific level (e.g.: the virtual host or route level). | ||
|
|
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
generated_api_shadow/envoy/extensions/filters/http/bandwidth_limit/v3alpha/BUILD
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...ed_api_shadow/envoy/extensions/filters/http/bandwidth_limit/v3alpha/bandwidth_limit.proto
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.