-
Notifications
You must be signed in to change notification settings - Fork 5.3k
compression: add zstd compressor and decompressor #20434
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
9 commits
Select commit
Hold shift + click to select a range
4c20fcd
compression: add zstd compressor and decompressor
rainingmaster 1647dfb
chore: fix for review
rainingmaster fae7ee9
chore: remove top level const params
rainingmaster 92e6ad2
chore: fix decompressor_filter rst
rainingmaster e3835e3
update docs for reviews
rainingmaster 8a3151c
fix typo
rainingmaster e60dd1e
fix for review
rainingmaster 73bdb15
fix example test, follow 20397
rainingmaster 2689679
fix link in docs
rainingmaster 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
| 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", | ||
| ], | ||
| ) |
64 changes: 64 additions & 0 deletions
64
api/envoy/extensions/compression/zstd/compressor/v3/zstd.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,64 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.compression.zstd.compressor.v3; | ||
|
|
||
| import "envoy/config/core/v3/base.proto"; | ||
|
|
||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.compression.zstd.compressor.v3"; | ||
| option java_outer_classname = "ZstdProto"; | ||
| option java_multiple_files = true; | ||
| option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/compression/zstd/compressor/v3;compressorv3"; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Zstd Compressor] | ||
| // [#extension: envoy.compression.zstd.compressor] | ||
|
|
||
| // [#next-free-field: 6] | ||
| message Zstd { | ||
| // Reference to http://facebook.github.io/zstd/zstd_manual.html | ||
| enum Strategy { | ||
| DEFAULT = 0; | ||
| FAST = 1; | ||
| DFAST = 2; | ||
| GREEDY = 3; | ||
| LAZY = 4; | ||
| LAZY2 = 5; | ||
| BTLAZY2 = 6; | ||
| BTOPT = 7; | ||
| BTULTRA = 8; | ||
| BTULTRA2 = 9; | ||
| } | ||
|
|
||
| // Set compression parameters according to pre-defined compression level table. | ||
| // Note that exact compression parameters are dynamically determined, | ||
| // depending on both compression level and source content size (when known). | ||
| // Value 0 means default, and default level is 3. | ||
| // Setting a level does not automatically set all other compression parameters | ||
| // to default. Setting this will however eventually dynamically impact the compression | ||
| // parameters which have not been manually set. The manually set | ||
| // ones will 'stick'. | ||
| google.protobuf.UInt32Value compression_level = 1; | ||
|
|
||
| // A 32-bits checksum of content is written at end of frame. If not set, defaults to false. | ||
| bool enable_checksum = 2; | ||
|
|
||
| // The higher the value of selected strategy, the more complex it is, | ||
| // resulting in stronger and slower compression. | ||
| // Special: value 0 means "use default strategy". | ||
| Strategy strategy = 3 [(validate.rules).enum = {defined_only: true}]; | ||
|
|
||
| // A dictionary for compression. Zstd offers dictionary compression, which greatly improves | ||
| // efficiency on small files and messages. Each dictionary will be generated with a dictionary ID | ||
| // that can be used to search the same dictionary during decompression. | ||
| // Please refer to `zstd manual <https://github.com/facebook/zstd/blob/dev/programs/zstd.1.md#dictionary-builder>`_ | ||
| // to train a specific dictionary for compression. | ||
| config.core.v3.DataSource dictionary = 4; | ||
|
|
||
| // Value for compressor's next output buffer. If not set, defaults to 4096. | ||
| google.protobuf.UInt32Value chunk_size = 5 [(validate.rules).uint32 = {lte: 65536 gte: 4096}]; | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
api/envoy/extensions/compression/zstd/decompressor/v3/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", | ||
| ], | ||
| ) |
33 changes: 33 additions & 0 deletions
33
api/envoy/extensions/compression/zstd/decompressor/v3/zstd.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,33 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.compression.zstd.decompressor.v3; | ||
|
|
||
| import "envoy/config/core/v3/base.proto"; | ||
|
|
||
| import "google/protobuf/wrappers.proto"; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
| import "validate/validate.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.compression.zstd.decompressor.v3"; | ||
| option java_outer_classname = "ZstdProto"; | ||
| option java_multiple_files = true; | ||
| option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/compression/zstd/decompressor/v3;decompressorv3"; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Zstd Decompressor] | ||
| // [#extension: envoy.compression.zstd.decompressor] | ||
|
|
||
| message Zstd { | ||
| // Dictionaries for decompression. Zstd offers dictionary compression, which greatly improves | ||
| // efficiency on small files and messages. It is necessary to ensure that the dictionary used for | ||
| // decompression is the same as the compression dictionary. Multiple dictionaries can be set, and the | ||
| // dictionary will be automatically selected for decompression according to the dictionary ID in the | ||
| // source content. | ||
| // Please refer to `zstd manual <https://github.com/facebook/zstd/blob/dev/programs/zstd.1.md#dictionary-builder>`_ | ||
| // to train specific dictionaries for decompression. | ||
| repeated config.core.v3.DataSource dictionaries = 1; | ||
|
|
||
| // Value for decompressor's next output buffer. If not set, defaults to 4096. | ||
| google.protobuf.UInt32Value chunk_size = 2 [(validate.rules).uint32 = {lte: 65536 gte: 4096}]; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,3 +75,4 @@ The following sandboxes are available: | |
| websocket | ||
| win32_front_proxy | ||
| zipkin_tracing | ||
| zstd | ||
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,95 @@ | ||
| .. _install_sandboxes_zstd: | ||
|
|
||
| Zstd | ||
| ====== | ||
|
|
||
| .. sidebar:: Requirements | ||
|
|
||
| .. include:: _include/docker-env-setup-link.rst | ||
|
|
||
| :ref:`curl <start_sandboxes_setup_curl>` | ||
| Used to make ``HTTP`` requests. | ||
|
|
||
| By enabling compression in Envoy you can save some network bandwidth, at the expense of increased processor usage. | ||
|
|
||
| Envoy supports compression and decompression for both requests and responses. | ||
|
|
||
| This sandbox provides an example of response compression served over ``HTTPS``. | ||
|
|
||
| The sandbox covers two scenarios: | ||
|
|
||
| - compression of files from an upstream server | ||
| - compression of Envoy's own statistics | ||
|
|
||
| Step 1: Start all of our containers | ||
| *********************************** | ||
|
|
||
| Change to the ``examples/zstd`` directory and bring up the docker composition. | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ pwd | ||
| envoy/examples/zstd | ||
| $ docker-compose build --pull | ||
| $ docker-compose up -d | ||
| $ docker-compose ps | ||
| Name Command State Ports | ||
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
| zstd_envoy-stats_1 /docker-entrypoint.sh /usr ... Up 0.0.0.0:10000->10000/tcp,:::10000->10000/tcp, 0.0.0.0:9901->9901/tcp,:::9901->9901/tcp, 0.0.0.0:9902->9902/tcp,:::9902->9902/tcp | ||
| zstd_service_1 python3 /code/service.py Up | ||
|
|
||
| Step 2: Test Envoy’s compression of upstream files | ||
| ************************************************** | ||
|
|
||
| The sandbox is configured with two endpoints on port ``10000`` for serving upstream files: | ||
|
|
||
| - ``/file.txt`` | ||
| - ``/file.json`` | ||
|
|
||
| Only ``/file.json`` is configured to be compressed. | ||
|
|
||
| Use ``curl`` to check that the response from requesting ``file.json`` contains the ``content-encoding: zstd`` header. | ||
|
|
||
| You will need to add an ``accept-encoding: zstd`` request header. | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ curl -ski -H "Accept-Encoding: zstd" https://localhost:10000/file.json | grep "content-encoding" | ||
| content-encoding: zstd | ||
|
|
||
| As only files with a content-type of ``application/json`` are configured to be compressed, the response from requesting ``file.txt`` should not contain the ``content-encoding: zstd`` header, and the file will not be compressed: | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ curl -ski -H "Accept-Encoding: zstd" https://localhost:10000/file.txt | grep "content-encoding" | ||
|
|
||
| Step 3: Test compression of Envoy’s statistics | ||
| ********************************************** | ||
|
|
||
| The sandbox is configured with two ports serving Envoy’s admin and statistics interface: | ||
|
|
||
| - ``9901`` exposes the standard admin interface without tls | ||
| - ``9902`` exposes a compressed version of the admin interface with tls | ||
|
|
||
| Use ``curl`` to make a request for uncompressed statistics on port ``9901``, it should not contain the ``content-encoding`` header in the response: | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ curl -ski -H "Accept-Encoding: zstd" http://localhost:9901/stats/prometheus | grep "content-encoding" | ||
|
|
||
| Now, use ``curl`` to make a request for the compressed statistics: | ||
|
|
||
| .. code-block:: console | ||
|
|
||
| $ curl -ski -H "Accept-Encoding: zstd" https://localhost:9902/stats/prometheus | grep "content-encoding" | ||
| content-encoding: zstd | ||
|
|
||
| .. seealso:: | ||
| :ref:`Zstd API <envoy_v3_api_msg_extensions.compression.zstd.compressor.v3.Zstd>` | ||
| API and configuration reference for Envoy's zstd compression. | ||
|
|
||
| :ref:`Compression configuration <config_http_filters_compressor>` | ||
| Reference documentation for Envoy's compressor filter. | ||
|
|
||
| :ref:`Envoy admin quick start guide <start_quick_start_admin>` | ||
| Quick start guide to the Envoy admin interface. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| FROM debian:buster-slim | ||
|
|
||
| RUN apt-get update \ | ||
| && apt-get install --no-install-recommends -y python3 python3-pip python3-setuptools \ | ||
| && apt-get autoremove -y && apt-get clean \ | ||
| && rm -rf /tmp/* /var/tmp/* \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
| RUN pip3 install -q Flask==2.0.3 | ||
| RUN mkdir -p /code/data | ||
| RUN dd if=/dev/zero of="/code/data/file.txt" bs=1024 count=10240 \ | ||
| && dd if=/dev/zero of="/code/data/file.json" bs=1024 count=10240 | ||
| ADD ./service.py /code | ||
| ENTRYPOINT ["python3", "/code/service.py"] |
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,5 @@ | ||
| FROM envoyproxy/envoy-dev:latest | ||
|
|
||
| COPY ./zstd-envoy.yaml /etc/zstd-envoy.yaml | ||
| RUN chmod go+r /etc/zstd-envoy.yaml | ||
| CMD ["/usr/local/bin/envoy", "-c", "/etc/zstd-envoy.yaml", "--service-cluster", "zstd"] |
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,2 @@ | ||
| To learn about this sandbox and for instructions on how to run it please head over | ||
| to the [envoy docs](https://www.envoyproxy.io/docs/envoy/latest/start/sandboxes/zstd.html) |
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.