-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
compressor: expose generic compressor filter to users #10553
Changes from 5 commits
47139ba
4bc9660
b7cfac0
fd7fab2
7bfd623
153f97e
09f10a9
d9b33cc
90d02d5
05a8541
c3c26b6
ece1755
3323683
b7e1d28
85676a2
681d7c4
79051a7
9bcc469
21fb4eb
2f48548
63085ac
edbe6b5
da5a305
76c2b1f
bc086c0
3f89444
801bdcf
8e12669
79ac3b9
2bdbee3
d72e015
85ae344
d833c1a
388d8bc
6ea514a
d43fb14
1498c20
4d09cd2
eabd93d
c69e0bb
63a6e46
cf473a7
02024a3
590167c
680ae29
dd93ad6
e6f9c79
9aaf9ff
d9ee8e0
503c81a
b3a49d2
6ede080
c5149d2
9b59cac
a271f28
bc77b25
4a9bff7
5f683bd
786ab77
6a9b477
4b4cfda
00fc997
8c37ff1
152a6b7
6b23035
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 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 = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
syntax = "proto3"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does this relate to https://github.com/envoyproxy/envoy/blob/master/api/envoy/config/filter/http/gzip/v2/gzip.proto? Which one should service operators configure and when? Is the former deprecated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, exactly, the former is deprecated. We need to make that clear as @htuch points out, have text in deprecated.rst, and also make sure the deprecated feature warning/stat is incremented so that operators know thy need to upgrade. |
||
|
||
package envoy.config.filter.http.compressor.gzip.v2; | ||
|
||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "udpa/annotations/migrate.proto"; | ||
import "udpa/annotations/status.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.config.filter.http.compressor.gzip.v2"; | ||
option java_outer_classname = "GzipProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_migrate).move_to_package = | ||
"envoy.extensions.filters.http.compressor.gzip.v3"; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Gzip] | ||
// [#extension: envoy.filters.http.compressor.gzip] | ||
|
||
// [#next-free-field: 10] | ||
message Gzip { | ||
enum CompressionStrategy { | ||
DEFAULT = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you comment on what the DEFAULTs are here and below? These should be fixed in the API. |
||
FILTERED = 1; | ||
HUFFMAN = 2; | ||
RLE = 3; | ||
} | ||
|
||
message CompressionLevel { | ||
enum Enum { | ||
DEFAULT = 0; | ||
BEST = 1; | ||
SPEED = 2; | ||
} | ||
} | ||
htuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Value from 1 to 9 that controls the amount of internal memory used by zlib. Higher values | ||
// use more memory, but are faster and produce better compression results. The default value is 5. | ||
google.protobuf.UInt32Value memory_level = 1 [(validate.rules).uint32 = {lte: 9 gte: 1}]; | ||
|
||
// A value used for selecting the zlib compression level. This setting will affect speed and | ||
// amount of compression applied to the content. "BEST" provides higher compression at the cost of | ||
// higher latency, "SPEED" provides lower compression with minimum impact on response time. | ||
// "DEFAULT" provides an optimal result between speed and compression. This field will be set to | ||
// "DEFAULT" if not specified. | ||
CompressionLevel.Enum compression_level = 3 [(validate.rules).enum = {defined_only: true}]; | ||
|
||
// A value used for selecting the zlib compression strategy which is directly related to the | ||
// characteristics of the content. Most of the time "DEFAULT" will be the best choice, though | ||
// there are situations which changing this parameter might produce better results. For example, | ||
// run-length encoding (RLE) is typically used when the content is known for having sequences | ||
// which same data occurs many consecutive times. For more information about each strategy, please | ||
// refer to zlib manual. | ||
CompressionStrategy compression_strategy = 4 [(validate.rules).enum = {defined_only: true}]; | ||
|
||
// Value from 9 to 15 that represents the base two logarithmic of the compressor's window size. | ||
// Larger window results in better compression at the expense of memory usage. The default is 12 | ||
// which will produce a 4096 bytes window. For more details about this parameter, please refer to | ||
// zlib manual > deflateInit2. | ||
google.protobuf.UInt32Value window_bits = 9 [(validate.rules).uint32 = {lte: 15 gte: 9}]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,13 @@ package envoy.config.filter.http.compressor.v2; | |
|
||
import "envoy/api/v2/core/base.proto"; | ||
|
||
import "google/protobuf/any.proto"; | ||
import "google/protobuf/struct.proto"; | ||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "udpa/annotations/migrate.proto"; | ||
import "udpa/annotations/status.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.config.filter.http.compressor.v2"; | ||
option java_outer_classname = "CompressorProto"; | ||
|
@@ -17,8 +20,10 @@ option (udpa.annotations.file_migrate).move_to_package = | |
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Compressor] | ||
// Compressor :ref:`configuration overview <config_http_filters_compressor>`. | ||
// [#extension: envoy.filters.http.compressor] | ||
|
||
// [#next-free-field: 6] | ||
// [#next-free-field: 7] | ||
message Compressor { | ||
// Minimum response length, in bytes, which will trigger compression. The default value is 30. | ||
google.protobuf.UInt32Value content_length = 1; | ||
|
@@ -45,4 +50,25 @@ message Compressor { | |
// Runtime flag that controls whether the filter is enabled or not. If set to false, the | ||
// filter will operate as a pass-through filter. If not specified, defaults to enabled. | ||
api.v2.core.RuntimeFeatureFlag runtime_enabled = 5; | ||
|
||
// A compressor library to use for compression. By default | ||
// :ref:`envoy.filters.http.compressor.gzip<envoy_api_msg_config.filter.http.compressor.gzip.v2.Gzip>` | ||
// is used. | ||
// | ||
// This field is ignored when used in the context of the deprecated "envoy.filters.http.gzip" | ||
// filter. | ||
CompressorLibrary compressor_library = 6; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure it makes sense to have a default here. Can we require this and then make the gzip config explicit for clarity? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, this field is required now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make it required via annotation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm... This message is used also in the deprecated
|
||
} | ||
|
||
message CompressorLibrary { | ||
// The name of the compressor library to instantiate for the filter. | ||
string name = 1 [(validate.rules).string = {min_bytes: 1}]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove this for new extensions as the extension will be looked up via the typed_config. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeap, removed. |
||
|
||
// Compressor library specific configuration. See the supported libraries for further | ||
// documentation. | ||
oneof config_type { | ||
google.protobuf.Struct config = 2 [deprecated = true]; | ||
rojkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
google.protobuf.Any typed_config = 3; | ||
} | ||
} |
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/config/filter/http/compressor/gzip/v2:pkg", | ||
"@com_github_cncf_udpa//udpa/annotations:pkg", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.filters.http.compressor.gzip.v3; | ||
|
||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "udpa/annotations/versioning.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.filters.http.compressor.gzip.v3"; | ||
option java_outer_classname = "GzipProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = NEXT_MAJOR_VERSION_CANDIDATE; | ||
|
||
// [#protodoc-title: Gzip] | ||
// [#extension: envoy.filters.http.compressor.gzip] | ||
|
||
// [#next-free-field: 10] | ||
message Gzip { | ||
option (udpa.annotations.versioning).previous_message_type = | ||
"envoy.config.filter.http.compressor.gzip.v2.Gzip"; | ||
|
||
enum CompressionStrategy { | ||
DEFAULT = 0; | ||
FILTERED = 1; | ||
HUFFMAN = 2; | ||
RLE = 3; | ||
} | ||
|
||
message CompressionLevel { | ||
option (udpa.annotations.versioning).previous_message_type = | ||
"envoy.config.filter.http.compressor.gzip.v2.Gzip.CompressionLevel"; | ||
|
||
enum Enum { | ||
DEFAULT = 0; | ||
BEST = 1; | ||
SPEED = 2; | ||
} | ||
} | ||
|
||
// Value from 1 to 9 that controls the amount of internal memory used by zlib. Higher values | ||
// use more memory, but are faster and produce better compression results. The default value is 5. | ||
google.protobuf.UInt32Value memory_level = 1 [(validate.rules).uint32 = {lte: 9 gte: 1}]; | ||
|
||
// A value used for selecting the zlib compression level. This setting will affect speed and | ||
// amount of compression applied to the content. "BEST" provides higher compression at the cost of | ||
// higher latency, "SPEED" provides lower compression with minimum impact on response time. | ||
// "DEFAULT" provides an optimal result between speed and compression. This field will be set to | ||
// "DEFAULT" if not specified. | ||
CompressionLevel.Enum compression_level = 3 [(validate.rules).enum = {defined_only: true}]; | ||
|
||
// A value used for selecting the zlib compression strategy which is directly related to the | ||
// characteristics of the content. Most of the time "DEFAULT" will be the best choice, though | ||
// there are situations which changing this parameter might produce better results. For example, | ||
// run-length encoding (RLE) is typically used when the content is known for having sequences | ||
// which same data occurs many consecutive times. For more information about each strategy, please | ||
// refer to zlib manual. | ||
CompressionStrategy compression_strategy = 4 [(validate.rules).enum = {defined_only: true}]; | ||
|
||
// Value from 9 to 15 that represents the base two logarithmic of the compressor's window size. | ||
// Larger window results in better compression at the expense of memory usage. The default is 12 | ||
// which will produce a 4096 bytes window. For more details about this parameter, please refer to | ||
// zlib manual > deflateInit2. | ||
google.protobuf.UInt32Value window_bits = 9 [(validate.rules).uint32 = {lte: 15 gte: 9}]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,19 +4,24 @@ package envoy.extensions.filters.http.compressor.v3; | |
|
||
import "envoy/config/core/v3/base.proto"; | ||
|
||
import "google/protobuf/any.proto"; | ||
import "google/protobuf/struct.proto"; | ||
import "google/protobuf/wrappers.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "udpa/annotations/versioning.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.filters.http.compressor.v3"; | ||
option java_outer_classname = "CompressorProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = NEXT_MAJOR_VERSION_CANDIDATE; | ||
|
||
// [#protodoc-title: Compressor] | ||
// Compressor :ref:`configuration overview <config_http_filters_compressor>`. | ||
// [#extension: envoy.filters.http.compressor] | ||
|
||
// [#next-free-field: 6] | ||
// [#next-free-field: 7] | ||
message Compressor { | ||
option (udpa.annotations.versioning).previous_message_type = | ||
"envoy.config.filter.http.compressor.v2.Compressor"; | ||
|
@@ -46,4 +51,30 @@ message Compressor { | |
// Runtime flag that controls whether the filter is enabled or not. If set to false, the | ||
// filter will operate as a pass-through filter. If not specified, defaults to enabled. | ||
config.core.v3.RuntimeFeatureFlag runtime_enabled = 5; | ||
|
||
// A compressor library to use for compression. By default | ||
// :ref:`envoy.filters.http.compressor.gzip<envoy_api_msg_extensions.filters.http.compressor.gzip.v3.Gzip>` | ||
// is used. | ||
// | ||
// This field is ignored when used in the context of the deprecated "envoy.filters.http.gzip" | ||
// filter. | ||
CompressorLibrary compressor_library = 6; | ||
} | ||
|
||
message CompressorLibrary { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
option (udpa.annotations.versioning).previous_message_type = | ||
"envoy.config.filter.http.compressor.v2.CompressorLibrary"; | ||
|
||
reserved 2; | ||
|
||
reserved "config"; | ||
|
||
// The name of the compressor library to instantiate for the filter. | ||
string name = 1 [(validate.rules).string = {min_bytes: 1}]; | ||
|
||
// Compressor library specific configuration. See the supported libraries for further | ||
// documentation. | ||
oneof config_type { | ||
google.protobuf.Any typed_config = 3; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ HTTP filters | |
*/v2/* | ||
*/v2alpha/* | ||
*/v2alpha1/* | ||
compressor/*/v2/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ HTTP filters | |
|
||
*/empty/* | ||
../../../extensions/filters/http/*/v3/* | ||
../../../extensions/filters/http/compressor/*/v3/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
.. _config_http_filters_compressor: | ||
|
||
Compressor | ||
rojkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
========== | ||
Compressor is an HTTP filter which enables Envoy to compress dispatched data | ||
mattklein123 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from an upstream service upon client request. Compression is useful in | ||
situations where large payloads need to be transmitted without | ||
compromising the response time. | ||
htuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Configuration | ||
------------- | ||
* :ref:`v2 API reference <envoy_api_msg_config.filter.http.compressor.v2.Compressor>` | ||
* This filter should be configured with the name *envoy.filters.http.compressor*. | ||
|
||
How it works | ||
------------ | ||
When compressor filter is enabled, request and response headers are inspected to | ||
determine whether or not the content should be compressed. The content is | ||
compressed and then sent to the client with the appropriate headers, if | ||
response and request allow. | ||
|
||
Currently the filter supports :ref:`gzip compression<envoy_api_msg_config.filter.http.compressor.gzip.v2.Gzip>` | ||
only. Other compression libraries can be supported as extensions. | ||
|
||
By *default* compression will be *skipped* when: | ||
|
||
- A request does NOT contain *accept-encoding* header. | ||
- A request includes *accept-encoding* header, but it does not contain "gzip" or "\*". | ||
- A request includes *accept-encoding* with "gzip" or "\*" with the weight "q=0". Note | ||
that the "gzip" will have a higher weight then "\*". For example, if *accept-encoding* | ||
is "gzip;q=0,\*;q=1", the filter will not compress. But if the header is set to | ||
"\*;q=0,gzip;q=1", the filter will compress. | ||
- A request whose *accept-encoding* header includes any encoding type with a higher | ||
weight than "gzip"'s given the corresponding compression filter is present in the chain. | ||
- A response contains a *content-encoding* header. | ||
- A response contains a *cache-control* header whose value includes "no-transform". | ||
- A response contains a *transfer-encoding* header whose value includes "gzip". | ||
- A response does not contain a *content-type* value that matches one of the selected | ||
mime-types, which default to *application/javascript*, *application/json*, | ||
*application/xhtml+xml*, *image/svg+xml*, *text/css*, *text/html*, *text/plain*, | ||
*text/xml*. | ||
- Neither *content-length* nor *transfer-encoding* headers are present in | ||
the response. | ||
- Response size is smaller than 30 bytes (only applicable when *transfer-encoding* | ||
is not chunked). | ||
|
||
Please note that in case the filter is configured to use a compression library extension | ||
other than gzip it looks for content encoding in the *accept-encoding* header provided by | ||
the extension. | ||
|
||
When compression is *applied*: | ||
|
||
- The *content-length* is removed from response headers. | ||
- Response headers contain "*transfer-encoding: chunked*" and do not contain | ||
"*content-encoding*" header. | ||
- The "*vary: accept-encoding*" header is inserted on every response. | ||
|
||
.. _compressor-statistics: | ||
|
||
Statistics | ||
---------- | ||
|
||
Every configured Compressor filter has statistics rooted at <stat_prefix>.<compression_library_stat_prefix>.* with the following: | ||
|
||
.. csv-table:: | ||
:header: Name, Type, Description | ||
:widths: 1, 1, 2 | ||
|
||
compressed, Counter, Number of requests compressed. | ||
not_compressed, Counter, Number of requests not compressed. | ||
no_accept_header, Counter, Number of requests with no accept header sent. | ||
header_identity, Counter, Number of requests sent with "identity" set as the *accept-encoding*. | ||
header_compressor_used, Counter, Number of requests sent with "gzip" set as the *accept-encoding*. | ||
header_compressor_overshadowed, Counter, Number of requests skipped by this filter instance because they were handled by another filter in the same filter chain. | ||
header_wildcard, Counter, Number of requests sent with "\*" set as the *accept-encoding*. | ||
header_not_valid, Counter, Number of requests sent with a not valid *accept-encoding* header (aka "q=0" or an unsupported encoding type). | ||
total_uncompressed_bytes, Counter, The total uncompressed bytes of all the requests that were marked for compression. | ||
total_compressed_bytes, Counter, The total compressed bytes of all the requests that were marked for compression. | ||
content_length_too_small, Counter, Number of requests that accepted gzip encoding but did not compress because the payload was too small. | ||
not_compressed_etag, Counter, Number of requests that were not compressed due to the etag header. *disable_on_etag_header* must be turned on for this to happen. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this and line 25 be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the line 27, but 25 is still needed according to
check_format.py fix