Skip to content

Commit

Permalink
gzip filter: allow setting zlib compressor's chunk size (#10508)
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Gutierrez Segales <rgs@pinterest.com>
  • Loading branch information
Raúl Gutiérrez Segalés authored Apr 25, 2020
1 parent 52ce75f commit 0b0213f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
7 changes: 6 additions & 1 deletion api/envoy/extensions/filters/http/gzip/v3/gzip.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// Gzip :ref:`configuration overview <config_http_filters_gzip>`.
// [#extension: envoy.filters.http.gzip]

// [#next-free-field: 11]
// [#next-free-field: 12]
message Gzip {
option (udpa.annotations.versioning).previous_message_type =
"envoy.config.filter.http.gzip.v2.Gzip";
Expand Down Expand Up @@ -76,4 +76,9 @@ message Gzip {
// the fields `content_length`, `content_type`, `disable_on_etag_header` and
// `remove_accept_encoding_header` are ignored.
compressor.v3.Compressor compressor = 10;

// Value for Zlib's next output buffer. If not set, defaults to 4096.
// See https://www.zlib.net/manual.html for more details. Also see
// https://github.com/envoyproxy/envoy/issues/8448 for context on this filter's performance.
google.protobuf.UInt32Value chunk_size = 11 [(validate.rules).uint32 = {lte: 65536 gte: 4096}];
}
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changes
Disabled by default and can be enabled via :ref:`enable_upstream_stats <envoy_v3_api_field_extensions.filters.http.grpc_stats.v3.FilterConfig.enable_upstream_stats>`.
* grpc-json: added support for streaming response using
`google.api.HttpBody <https://github.com/googleapis/googleapis/blob/master/google/api/httpbody.proto>`_.
* gzip filter: added option to set zlib's next output buffer size.
* http: fixed a bug where in some cases slash was moved from path to query string when :ref:`merging of adjacent slashes<envoy_api_field_config.filter.network.http_connection_manager.v2.HttpConnectionManager.merge_slashes>` is enabled.
* http: fixed a bug where the upgrade header was not cleared on responses to non-upgrade requests.
Can be reverted temporarily by setting runtime feature `envoy.reloadable_features.fix_upgrade_response` to false.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions source/extensions/filters/http/gzip/gzip_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ GzipFilterConfig::GzipFilterConfig(const envoy::extensions::filters::http::gzip:
compression_level_(compressionLevelEnum(gzip.compression_level())),
compression_strategy_(compressionStrategyEnum(gzip.compression_strategy())),
memory_level_(memoryLevelUint(gzip.memory_level().value())),
window_bits_(windowBitsUint(gzip.window_bits().value())) {}
window_bits_(windowBitsUint(gzip.window_bits().value())),
chunk_size_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(gzip, chunk_size, 4096)) {}

std::unique_ptr<Compressor::Compressor> GzipFilterConfig::makeCompressor() {
auto compressor = std::make_unique<Compressor::ZlibCompressorImpl>();
auto compressor = std::make_unique<Compressor::ZlibCompressorImpl>(chunk_size_);
compressor->init(compressionLevel(), compressionStrategy(), windowBits(), memoryLevel());
return compressor;
}
Expand Down
6 changes: 4 additions & 2 deletions source/extensions/filters/http/gzip/gzip_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class GzipFilterConfig : public Common::Compressors::CompressorFilterConfig {

uint64_t memoryLevel() const { return memory_level_; }
uint64_t windowBits() const { return window_bits_; }
uint32_t chunkSize() const { return chunk_size_; }

private:
static Compressor::ZlibCompressorImpl::CompressionLevel compressionLevelEnum(
Expand All @@ -48,8 +49,9 @@ class GzipFilterConfig : public Common::Compressors::CompressorFilterConfig {
Compressor::ZlibCompressorImpl::CompressionLevel compression_level_;
Compressor::ZlibCompressorImpl::CompressionStrategy compression_strategy_;

int32_t memory_level_;
int32_t window_bits_;
const int32_t memory_level_;
const int32_t window_bits_;
const uint32_t chunk_size_;
};

} // namespace Gzip
Expand Down
15 changes: 15 additions & 0 deletions test/extensions/filters/http/gzip/gzip_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,21 @@ TEST(GzipFilterConfigTest, DEPRECATED_FEATURE_TEST(DeprecatedExtensionFilterName
deprecated_name));
}

// Test setting zlib's chunk size.
TEST_F(GzipFilterTest, ChunkSize) {
// Default
setUpFilter("{}");
EXPECT_EQ(config_->chunkSize(), 4096);

// Override
setUpFilter(R"EOF(
{
"chunk_size": 8192
}
)EOF");
EXPECT_EQ(config_->chunkSize(), 8192);
}

} // namespace Gzip
} // namespace HttpFilters
} // namespace Extensions
Expand Down

0 comments on commit 0b0213f

Please sign in to comment.