Skip to content
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

compression: create a decompressor extensibility point and move gzip decompressor #10744

Merged
merged 26 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,6 @@ extensions/filters/common/original_src @snowp @klarose
/*/extensions/filters/network/local_ratelimit @mattklein123 @junr03
/*/extensions/filters/http/aws_request_signing @rgs1 @derekargueta @mattklein123 @marcomagdy
/*/extensions/filters/http/aws_lambda @mattklein123 @marcomagdy @lavignes
# Compression
/*/extensions/compression/common @junr03 @rojkov
/*/extensions/compression/gzip @junr03 @rojkov
1 change: 1 addition & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ proto_library(
"//envoy/extensions/common/ratelimit/v3:pkg",
"//envoy/extensions/common/tap/v3:pkg",
"//envoy/extensions/compression/gzip/compressor/v3:pkg",
"//envoy/extensions/compression/gzip/decompressor/v3:pkg",
"//envoy/extensions/filters/common/fault/v3:pkg",
"//envoy/extensions/filters/http/adaptive_concurrency/v3:pkg",
"//envoy/extensions/filters/http/aws_lambda/v3:pkg",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option java_outer_classname = "GzipProto";
option java_multiple_files = true;
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Gzip]
// [#protodoc-title: Gzip Compressor]
// [#extension: envoy.compression.gzip.compressor]

// [#next-free-field: 6]
Expand Down
9 changes: 9 additions & 0 deletions api/envoy/extensions/compression/gzip/decompressor/v3/BUILD
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"],
)
30 changes: 30 additions & 0 deletions api/envoy/extensions/compression/gzip/decompressor/v3/gzip.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
syntax = "proto3";

package envoy.extensions.compression.gzip.decompressor.v3;

import "google/protobuf/wrappers.proto";

import "udpa/annotations/migrate.proto";
import "udpa/annotations/status.proto";
import "udpa/annotations/versioning.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.compression.gzip.decompressor.v3";
option java_outer_classname = "GzipProto";
option java_multiple_files = true;
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Gzip Decompressor]
// [#extension: envoy.compression.gzip.decompressor]

message Gzip {
// Value from 9 to 15 that represents the base two logarithmic of the decompressor's window size.
// The decompression window size needs to be equal or larger than the compression window size.
// The default is 15 per zlib's manual. For more details about this parameter, please refer to
// zlib manual > inflateInit2.
google.protobuf.UInt32Value window_bits = 1 [(validate.rules).uint32 = {lte: 15 gte: 9}];

// Value for zlib's decompressor output buffer. If not set, defaults to 4096.
// See https://www.zlib.net/manual.html for more details.
google.protobuf.UInt32Value chunk_size = 2 [(validate.rules).uint32 = {lte: 65536 gte: 4096}];
}
1 change: 1 addition & 0 deletions api/versioning/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ proto_library(
"//envoy/extensions/common/ratelimit/v3:pkg",
"//envoy/extensions/common/tap/v3:pkg",
"//envoy/extensions/compression/gzip/compressor/v3:pkg",
"//envoy/extensions/compression/gzip/decompressor/v3:pkg",
"//envoy/extensions/filters/common/fault/v3:pkg",
"//envoy/extensions/filters/http/adaptive_concurrency/v3:pkg",
"//envoy/extensions/filters/http/aws_lambda/v3:pkg",
Expand Down

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

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

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

2 changes: 2 additions & 0 deletions include/envoy/compression/compressor/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class NamedCompressorLibraryConfigFactory : public Config::TypedFactory {
virtual CompressorFactoryPtr
createCompressorFactoryFromProto(const Protobuf::Message& config,
Server::Configuration::FactoryContext& context) PURE;

std::string category() const override { return "envoy.compression.compressor"; }
};

} // namespace Compressor
Expand Down
35 changes: 35 additions & 0 deletions include/envoy/compression/decompressor/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_library",
"envoy_package",
)

envoy_package()

envoy_cc_library(
name = "decompressor_config_interface",
hdrs = ["config.h"],
deps = [
":decompressor_factory_interface",
"//include/envoy/config:typed_config_interface",
"//include/envoy/server:filter_config_interface",
],
)

envoy_cc_library(
name = "decompressor_factory_interface",
hdrs = ["factory.h"],
deps = [
":decompressor_interface",
],
)

envoy_cc_library(
name = "decompressor_interface",
hdrs = ["decompressor.h"],
deps = [
"//include/envoy/buffer:buffer_interface",
],
)
24 changes: 24 additions & 0 deletions include/envoy/compression/decompressor/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "envoy/compression/decompressor/factory.h"
#include "envoy/config/typed_config.h"
#include "envoy/server/filter_config.h"

namespace Envoy {
namespace Compression {
namespace Decompressor {

class NamedDecompressorLibraryConfigFactory : public Config::TypedFactory {
public:
~NamedDecompressorLibraryConfigFactory() override = default;

virtual DecompressorFactoryPtr
createDecompressorFactoryFromProto(const Protobuf::Message& config,
Server::Configuration::FactoryContext& context) PURE;

std::string category() const override { return "envoy.compression.decompressor"; }
};

} // namespace Decompressor
} // namespace Compression
} // namespace Envoy
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "envoy/buffer/buffer.h"

namespace Envoy {
namespace Compression {
namespace Decompressor {

/**
Expand All @@ -21,5 +22,8 @@ class Decompressor {
Buffer::Instance& output_buffer) PURE;
};

using DecompressorPtr = std::unique_ptr<Decompressor>;

} // namespace Decompressor
} // namespace Compression
} // namespace Envoy
25 changes: 25 additions & 0 deletions include/envoy/compression/decompressor/factory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include "envoy/compression/decompressor/decompressor.h"

namespace Envoy {
namespace Compression {
namespace Decompressor {

class DecompressorFactory {
public:
virtual ~DecompressorFactory() = default;

virtual DecompressorPtr createDecompressor() PURE;
virtual const std::string& statsPrefix() const PURE;
// TODO(junr03): this method assumes that decompressors are used on http messages.
// A more generic method might be `hint()` which gives the user of the decompressor a hint about
// the type of decompression that it can perform.
virtual const std::string& contentEncoding() const PURE;
};

using DecompressorFactoryPtr = std::unique_ptr<DecompressorFactory>;

} // namespace Decompressor
} // namespace Compression
} // namespace Envoy
1 change: 1 addition & 0 deletions source/common/common/zlib/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Zlib {
/**
* Shared code between the compressor and the decompressor.
*/
// TODO(junr03): move to extensions tree once the compressor side is moved to extensions.
class Base {
public:
Base(uint64_t chunk_size, std::function<void(z_stream*)> zstream_deleter);
Expand Down
23 changes: 0 additions & 23 deletions source/common/decompressor/BUILD

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class CompressorLibraryFactoryBase
return std::make_unique<ConfigProto>();
}

std::string category() const override { return "envoy.compression.compressor"; }

std::string name() const override { return name_; }

protected:
Expand All @@ -36,6 +34,7 @@ class CompressorLibraryFactoryBase
private:
virtual Envoy::Compression::Compressor::CompressorFactoryPtr
createCompressorFactoryFromProtoTyped(const ConfigProto&) PURE;

const std::string name_;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ load(
envoy_package()

envoy_cc_library(
name = "decompressor_interface",
hdrs = ["decompressor.h"],
name = "decompressor_factory_base_lib",
hdrs = ["factory_base.h"],
deps = [
"//include/envoy/buffer:buffer_interface",
"//include/envoy/compression/decompressor:decompressor_config_interface",
],
)
43 changes: 43 additions & 0 deletions source/extensions/compression/common/decompressor/factory_base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include "envoy/compression/decompressor/config.h"

namespace Envoy {
namespace Extensions {
namespace Compression {
namespace Common {
namespace Decompressor {

template <class ConfigProto>
class DecompressorLibraryFactoryBase
: public Envoy::Compression::Decompressor::NamedDecompressorLibraryConfigFactory {
public:
Envoy::Compression::Decompressor::DecompressorFactoryPtr
createDecompressorFactoryFromProto(const Protobuf::Message& proto_config,
Server::Configuration::FactoryContext& context) override {
return createDecompressorFactoryFromProtoTyped(
MessageUtil::downcastAndValidate<const ConfigProto&>(proto_config,
context.messageValidationVisitor()));
}

ProtobufTypes::MessagePtr createEmptyConfigProto() override {
return std::make_unique<ConfigProto>();
}

std::string name() const override { return name_; }

protected:
DecompressorLibraryFactoryBase(const std::string& name) : name_(name) {}

private:
virtual Envoy::Compression::Decompressor::DecompressorFactoryPtr
createDecompressorFactoryFromProtoTyped(const ConfigProto&) PURE;

const std::string name_;
};

} // namespace Decompressor
} // namespace Common
} // namespace Compression
} // namespace Extensions
} // namespace Envoy
37 changes: 37 additions & 0 deletions source/extensions/compression/gzip/decompressor/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
"envoy_cc_library",
"envoy_package",
)

envoy_package()

envoy_cc_library(
name = "zlib_decompressor_impl_lib",
srcs = ["zlib_decompressor_impl.cc"],
hdrs = ["zlib_decompressor_impl.h"],
external_deps = ["zlib"],
deps = [
"//include/envoy/compression/decompressor:decompressor_interface",
"//source/common/buffer:buffer_lib",
"//source/common/common:assert_lib",
"//source/common/common:minimal_logger_lib",
"//source/common/common:zlib_base_lib",
],
)

envoy_cc_extension(
name = "config",
srcs = ["config.cc"],
hdrs = ["config.h"],
security_posture = "robust_to_untrusted_downstream",
deps = [
":zlib_decompressor_impl_lib",
"//source/common/http:headers_lib",
"//source/extensions/compression/common/decompressor:decompressor_factory_base_lib",
"@envoy_api//envoy/extensions/compression/gzip/decompressor/v3:pkg_cc_proto",
],
)
Loading