From c8c64e59fa1122ca78cd829a0eabe51783a5ccf4 Mon Sep 17 00:00:00 2001 From: "data-plane-api(Azure Pipelines)" Date: Tue, 25 May 2021 17:55:36 +0000 Subject: [PATCH] extensions: add http bandwidth limit filter (#16358) the filter smoothens the flow of data in both direction up to the specified bandwidth limit. Risk Level: Low, new filter Testing: UTs added. Adding more UTs and integration tests. Docs Changes: Added Release Notes: Added Fixes #13604 Signed-off-by: Nitin Goyal Mirrored from https://github.com/envoyproxy/envoy @ a467b0ef41864459f4b4ad76fad7e1efb06b0bf8 --- BUILD | 1 + STYLE.md | 6 +- .../http/bandwidth_limit/v3alpha/BUILD | 12 ++++ .../v3alpha/bandwidth_limit.proto | 70 +++++++++++++++++++ versioning/BUILD | 1 + 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 envoy/extensions/filters/http/bandwidth_limit/v3alpha/BUILD create mode 100644 envoy/extensions/filters/http/bandwidth_limit/v3alpha/bandwidth_limit.proto diff --git a/BUILD b/BUILD index 136e248f..e051250b 100644 --- a/BUILD +++ b/BUILD @@ -177,6 +177,7 @@ proto_library( "//envoy/extensions/filters/http/admission_control/v3alpha:pkg", "//envoy/extensions/filters/http/aws_lambda/v3:pkg", "//envoy/extensions/filters/http/aws_request_signing/v3:pkg", + "//envoy/extensions/filters/http/bandwidth_limit/v3alpha:pkg", "//envoy/extensions/filters/http/buffer/v3:pkg", "//envoy/extensions/filters/http/cache/v3alpha:pkg", "//envoy/extensions/filters/http/cdn_loop/v3alpha:pkg", diff --git a/STYLE.md b/STYLE.md index 18d96fd4..d73e17b7 100644 --- a/STYLE.md +++ b/STYLE.md @@ -113,11 +113,11 @@ organization](#package-organization) above. To add an extension config to the API, the steps below should be followed: 1. If this is still WiP and subject to breaking changes, use `vNalpha` instead of `vN` in steps - below. Refer to the [Cache filter config](envoy/extensions/filter/http/cache/v3alpha/cache.proto) + below. Refer to the [Cache filter config](envoy/extensions/filters/http/cache/v3alpha/cache.proto) as an example of `v3alpha`, and the - [Buffer filter config](envoy/extensions/filter/http/buffer/v3/buffer.proto) as an example of `v3`. + [Buffer filter config](envoy/extensions/filters/http/buffer/v3/buffer.proto) as an example of `v3`. 1. Place the v3 extension configuration `.proto` in `api/envoy/extensions`, e.g. - `api/envoy/extensions/filter/http/foobar/v3/foobar.proto` together with an initial BUILD file: + `api/envoy/extensions/filters/http/foobar/v3/foobar.proto` together with an initial BUILD file: ```bazel load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") diff --git a/envoy/extensions/filters/http/bandwidth_limit/v3alpha/BUILD b/envoy/extensions/filters/http/bandwidth_limit/v3alpha/BUILD new file mode 100644 index 00000000..1c1a6f6b --- /dev/null +++ b/envoy/extensions/filters/http/bandwidth_limit/v3alpha/BUILD @@ -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", + ], +) diff --git a/envoy/extensions/filters/http/bandwidth_limit/v3alpha/bandwidth_limit.proto b/envoy/extensions/filters/http/bandwidth_limit/v3alpha/bandwidth_limit.proto new file mode 100644 index 00000000..4cd5f826 --- /dev/null +++ b/envoy/extensions/filters/http/bandwidth_limit/v3alpha/bandwidth_limit.proto @@ -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 `. +// [#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. + REQUEST = 1; + + // Filter enabled only for outgoing traffic. + RESPONSE = 2; + + // Filter enabled for both incoming and outgoing traffic. + REQUEST_AND_RESPONSE = 3; + } + + // 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; +} diff --git a/versioning/BUILD b/versioning/BUILD index 0703d9ee..90f48a6b 100644 --- a/versioning/BUILD +++ b/versioning/BUILD @@ -60,6 +60,7 @@ proto_library( "//envoy/extensions/filters/http/admission_control/v3alpha:pkg", "//envoy/extensions/filters/http/aws_lambda/v3:pkg", "//envoy/extensions/filters/http/aws_request_signing/v3:pkg", + "//envoy/extensions/filters/http/bandwidth_limit/v3alpha:pkg", "//envoy/extensions/filters/http/buffer/v3:pkg", "//envoy/extensions/filters/http/cache/v3alpha:pkg", "//envoy/extensions/filters/http/cdn_loop/v3alpha:pkg",