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

Make gzip default for otlp gRPC/HTTP exporters #4632

Merged
merged 9 commits into from
Feb 3, 2022
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
in 0.11.0 are no longer converted to the messages and fields that replaced the deprecated ones.
Received deprecated messages and fields will be now ignored. In OTLP/JSON in the
instrumentationLibraryLogs object the "logs" field is now named "logRecords" (#4724)
- `otlphttp` and `otlp` exporters enable gzip compression by default (#4632)

## 💡 Enhancements 💡

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` Compression type to use among `gzip`, `snappy` and `zstd`
- `compression` Compression type to use among `gzip`, `snappy`, `zstd`, and `none`.
- `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
9 changes: 9 additions & 0 deletions exporter/otlpexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ exporters:
insecure: true
```

By default `gzip` compression is enabled. See [compression comparison](../../config/configgrpc/README.md#compression-comparison) for details benchmark information. To disable, configure as follows:

```yaml
exporters:
otlp:
...
compression: none
```

## Advanced Configuration

Several helper files are leveraged to provide additional capabilities automatically:
Expand Down
3 changes: 3 additions & 0 deletions exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/configgrpc"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -47,6 +48,8 @@ func createDefaultConfig() config.Exporter {
QueueSettings: exporterhelper.DefaultQueueSettings(),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Headers: map[string]string{},
// Default to gzip compression
Compression: configcompression.Gzip,
// We almost read 0 bytes, so no need to tune ReadBufferSize.
WriteBufferSize: 512 * 1024,
},
Expand Down
11 changes: 11 additions & 0 deletions exporter/otlpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestCreateDefaultConfig(t *testing.T) {
assert.Equal(t, ocfg.RetrySettings, exporterhelper.DefaultRetrySettings())
assert.Equal(t, ocfg.QueueSettings, exporterhelper.DefaultQueueSettings())
assert.Equal(t, ocfg.TimeoutSettings, exporterhelper.DefaultTimeoutSettings())
assert.Equal(t, ocfg.Compression, configcompression.Gzip)
}

func TestCreateMetricsExporter(t *testing.T) {
Expand Down Expand Up @@ -100,6 +101,16 @@ func TestCreateTracesExporter(t *testing.T) {
},
},
},
{
name: "NoneCompression",
config: Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: "none",
},
},
},
{
name: "GzipCompression",
config: Config{
Expand Down
9 changes: 9 additions & 0 deletions exporter/otlphttpexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,14 @@ exporters:
endpoint: https://example.com:4318/v1/traces
```

By default `gzip` compression is enabled. See [compression comparison](../../config/configgrpc/README.md#compression-comparison) for details benchmark information. To disable, configure as follows:

```yaml
exporters:
otlphttp:
...
compression: none
```

The full list of settings exposed for this exporter are documented [here](./config.go)
with detailed sample configurations [here](./testdata/config.yaml).
3 changes: 3 additions & 0 deletions exporter/otlphttpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter/exporterhelper"
Expand Down Expand Up @@ -51,6 +52,8 @@ func createDefaultConfig() config.Exporter {
Endpoint: "",
Timeout: 30 * time.Second,
Headers: map[string]string{},
// Default to gzip compression
Compression: configcompression.Gzip,
// We almost read 0 bytes, so no need to tune ReadBufferSize.
WriteBufferSize: 512 * 1024,
},
Expand Down
42 changes: 42 additions & 0 deletions exporter/otlphttpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/config/configcompression"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/config/configtest"
"go.opentelemetry.io/collector/config/configtls"
Expand All @@ -45,6 +46,7 @@ func TestCreateDefaultConfig(t *testing.T) {
assert.Equal(t, ocfg.RetrySettings.InitialInterval, 5*time.Second, "default retry InitialInterval")
assert.Equal(t, ocfg.RetrySettings.MaxInterval, 30*time.Second, "default retry MaxInterval")
assert.Equal(t, ocfg.QueueSettings.Enabled, true, "default sending queue is enabled")
assert.Equal(t, ocfg.Compression, configcompression.Gzip)
}

func TestCreateMetricsExporter(t *testing.T) {
Expand Down Expand Up @@ -132,6 +134,46 @@ func TestCreateTracesExporter(t *testing.T) {
mustFailOnCreate: false,
mustFailOnStart: true,
},
{
name: "NoneCompression",
config: Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: endpoint,
Compression: "none",
},
},
},
{
name: "GzipCompression",
config: Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: endpoint,
Compression: configcompression.Gzip,
},
},
},
{
name: "SnappyCompression",
config: Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: endpoint,
Compression: configcompression.Snappy,
},
},
},
{
name: "ZstdCompression",
config: Config{
ExporterSettings: config.NewExporterSettings(config.NewComponentID(typeStr)),
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: endpoint,
Compression: configcompression.Zstd,
},
},
},
}

for _, tt := range tests {
Expand Down
8 changes: 7 additions & 1 deletion exporter/otlphttpexporter/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package otlphttpexporter

import (
"bytes"
"compress/gzip"
"context"
"encoding/base64"
"encoding/hex"
Expand Down Expand Up @@ -243,7 +245,11 @@ func TestLogsRoundTrip(t *testing.T) {
func TestIssue_4221(t *testing.T) {
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() { assert.NoError(t, r.Body.Close()) }()
data, err := ioutil.ReadAll(r.Body)
compressedData, err := ioutil.ReadAll(r.Body)
require.NoError(t, err)
gzipReader, err := gzip.NewReader(bytes.NewReader(compressedData))
require.NoError(t, err)
data, err := ioutil.ReadAll(gzipReader)
require.NoError(t, err)
base64Data := base64.StdEncoding.EncodeToString(data)
// Verify same base64 encoded string is received.
Expand Down