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

feat: supports more compression methods for configgrpc #4088

Merged
merged 11 commits into from
Nov 5, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

## 🛑 Breaking changes 🛑

- Supports more compression methods for configgrpc (#4088)
- Move configcheck.ValidateConfigFromFactories as internal function in service package (#3876).
- Rename `configparser.Parser` as `config.Map` (#4075)

Expand Down
2 changes: 1 addition & 1 deletion config/configgrpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ configuration. For more information, see [configtls
README](../configtls/README.md).

- [`balancer_name`](https://github.com/grpc/grpc-go/blob/master/examples/features/load_balancing/README.md)
- `compression` (default = gzip): Compression type to use (only gzip is supported today)
- `compression` Compression type to use among `gzip`, `lz4`, `snappy` and `zstd`
- `endpoint`: Valid value syntax available [here](https://github.com/grpc/grpc/blob/master/doc/naming.md)
- [`tls`](../configtls/README.md)
- `headers`: name/value pairs added to the request
Expand Down
14 changes: 11 additions & 3 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"strings"
"time"

"github.com/mostynb/go-grpc-compression/lz4"
"github.com/mostynb/go-grpc-compression/snappy"
"github.com/mostynb/go-grpc-compression/zstd"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
"google.golang.org/grpc"
Expand All @@ -40,12 +43,18 @@ import (
const (
CompressionUnsupported = ""
CompressionGzip = "gzip"
CompressionLz4 = "lz4"
CompressionSnappy = "snappy"
CompressionZstd = "zstd"
)

var (
// Map of opentelemetry compression types to grpc registered compression types.
gRPCCompressionKeyMap = map[string]string{
CompressionGzip: gzip.Name,
CompressionGzip: gzip.Name,
CompressionLz4: lz4.Name,
CompressionSnappy: snappy.Name,
CompressionZstd: zstd.Name,
}
)

Expand All @@ -68,8 +77,7 @@ type GRPCClientSettings struct {
// https://github.com/grpc/grpc/blob/master/doc/naming.md.
Endpoint string `mapstructure:"endpoint"`

// The compression key for supported compression types within
// collector. Currently the only supported mode is `gzip`.
// The compression key for supported compression types within collector.
Compression string `mapstructure:"compression"`

// TLSSetting struct exposes TLS client configuration.
Expand Down
24 changes: 24 additions & 0 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,30 @@ func TestGetGRPCCompressionKey(t *testing.T) {
t.Error("Capitalization of CompressionGzip should not matter")
}

if GetGRPCCompressionKey("lz4") != CompressionLz4 {
t.Error("lz4 is marked as supported but returned unsupported")
}

if GetGRPCCompressionKey("Lz4") != CompressionLz4 {
t.Error("Capitalization of CompressionLz4 should not matter")
}

if GetGRPCCompressionKey("snappy") != CompressionSnappy {
t.Error("snappy is marked as supported but returned unsupported")
}

if GetGRPCCompressionKey("Snappy") != CompressionSnappy {
t.Error("Capitalization of CompressionSnappy should not matter")
}

if GetGRPCCompressionKey("zstd") != CompressionZstd {
t.Error("zstd is marked as supported but returned unsupported")
}

if GetGRPCCompressionKey("Zstd") != CompressionZstd {
t.Error("Capitalization of CompressionZstd should not matter")
}

if GetGRPCCompressionKey("badType") != CompressionUnsupported {
t.Error("badType is not supported but was returned as supported")
}
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/cfg-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fields:
kind: string
doc: |
The compression key for supported compression types within
collector. Currently the only supported mode is `gzip`.
collector. Supports `gzip`, `lz4`, `snappy` and `zstd`.
- name: ca_file
kind: string
doc: |
Expand Down
29 changes: 28 additions & 1 deletion exporter/otlpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestCreateTracesExporter(t *testing.T) {
},
},
{
name: "Compression",
name: "GzipCompression",
config: Config{
ExporterSettings: config.NewExporterSettings(config.NewID(typeStr)),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Expand All @@ -108,6 +108,33 @@ func TestCreateTracesExporter(t *testing.T) {
},
},
},
{
name: "Lz4Compression",
config: Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: configgrpc.CompressionLz4,
},
},
},
{
name: "SnappyCompression",
config: Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: configgrpc.CompressionSnappy,
},
},
},
{
name: "ZstdCompression",
config: Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: configgrpc.CompressionZstd,
},
},
},
{
name: "Headers",
config: Config{
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/knadh/koanf v1.2.3
github.com/magiconair/properties v1.8.5
github.com/mitchellh/mapstructure v1.4.2
github.com/mostynb/go-grpc-compression v1.1.13
github.com/prometheus/common v0.30.0
github.com/rs/cors v1.8.0
github.com/shirou/gopsutil v3.21.8+incompatible
Expand Down Expand Up @@ -50,11 +51,14 @@ require (
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/klauspost/compress v1.13.4 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand Down
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/felixge/httpsnoop v1.0.2 h1:+nS9g82KMXccJ/wp0zyRW9ZBHFETmMGtkk+2CTTrW4o=
github.com/felixge/httpsnoop v1.0.2/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/frankban/quicktest v1.10.1 h1:y7Vn4YH/rfUHOCwNhvkAcA0gMQvFdKzSE8Ri3qtcFlc=
github.com/frankban/quicktest v1.10.1/go.mod h1:z7wHrVXJKCWP1Ev7B3iy2DivmuL5uGeeJDWYz/6LLhY=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -157,6 +159,9 @@ github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
Expand Down Expand Up @@ -248,6 +253,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.13.4 h1:0zhec2I8zGnjWcKyLl6i3gPqKANCCn5e9xmviEEeX6s=
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
github.com/knadh/koanf v1.2.3 h1:2Rkr0YhhYk+4QEOm800Q3Pu0Wi87svTxM6uuEb4WhYw=
github.com/knadh/koanf v1.2.3/go.mod h1:xpPTwMhsA/aaQLAilyCCqfpEiY1gpa160AiCuWHJUjY=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
Expand Down Expand Up @@ -294,6 +301,8 @@ github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJ
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mostynb/go-grpc-compression v1.1.13 h1:aQ9mPIUhL9B4Yu963GTlw7TQwaTYjxJPUkVbB3TOafs=
github.com/mostynb/go-grpc-compression v1.1.13/go.mod h1:DChotlqmlfp8i3zll4c+jUWtA3UJijPsOjDpkHNtgK4=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
Expand All @@ -303,6 +312,8 @@ github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAv
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down