From ace7fdddcdb96b70d8e7bf84a1d86585071c8c43 Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Mon, 29 Jan 2024 14:42:56 -0700 Subject: [PATCH] Rename CompressionType --- config/configcompression/compressiontype.go | 41 ++++++++++--------- .../configcompression/compressiontype_test.go | 4 +- config/configgrpc/configgrpc.go | 10 ++--- config/configgrpc/configgrpc_test.go | 6 +-- config/confighttp/compression.go | 4 +- config/confighttp/compression_test.go | 18 ++++---- config/confighttp/compressor.go | 10 ++--- config/confighttp/confighttp.go | 2 +- config/confighttp/confighttp_test.go | 2 +- exporter/otlpexporter/factory.go | 2 +- exporter/otlpexporter/factory_test.go | 8 ++-- exporter/otlphttpexporter/factory.go | 2 +- exporter/otlphttpexporter/factory_test.go | 8 ++-- 13 files changed, 60 insertions(+), 57 deletions(-) diff --git a/config/configcompression/compressiontype.go b/config/configcompression/compressiontype.go index ed0a979420a1..5c0d281f9316 100644 --- a/config/configcompression/compressiontype.go +++ b/config/configcompression/compressiontype.go @@ -5,31 +5,34 @@ package configcompression // import "go.opentelemetry.io/collector/config/config import "fmt" -type CompressionType string +// CompressionType Deprecated [0.94.0]: use Type instead. +type CompressionType = Type + +type Type string const ( - Gzip CompressionType = "gzip" - Zlib CompressionType = "zlib" - Deflate CompressionType = "deflate" - Snappy CompressionType = "snappy" - Zstd CompressionType = "zstd" - none CompressionType = "none" - empty CompressionType = "" + TypeGzip Type = "gzip" + TypeZlib Type = "zlib" + TypeDeflate Type = "deflate" + TypeSnappy Type = "snappy" + TypeZstd Type = "zstd" + typeNone Type = "none" + typeEmpty Type = "" ) -func IsCompressed(compressionType CompressionType) bool { - return compressionType != empty && compressionType != none +func IsCompressed(compressionType Type) bool { + return compressionType != typeEmpty && compressionType != typeNone } -func (ct *CompressionType) UnmarshalText(in []byte) error { - switch typ := CompressionType(in); typ { - case Gzip, - Zlib, - Deflate, - Snappy, - Zstd, - none, - empty: +func (ct *Type) UnmarshalText(in []byte) error { + switch typ := Type(in); typ { + case TypeGzip, + TypeZlib, + TypeDeflate, + TypeSnappy, + TypeZstd, + typeNone, + typeEmpty: *ct = typ return nil default: diff --git a/config/configcompression/compressiontype_test.go b/config/configcompression/compressiontype_test.go index dcf3350861e8..7c0ab986861d 100644 --- a/config/configcompression/compressiontype_test.go +++ b/config/configcompression/compressiontype_test.go @@ -59,14 +59,14 @@ func TestUnmarshalText(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - temp := none + temp := typeNone err := temp.UnmarshalText(tt.compressionName) if tt.shouldError { assert.Error(t, err) return } require.NoError(t, err) - assert.Equal(t, temp, CompressionType(tt.compressionName)) + assert.Equal(t, temp, Type(tt.compressionName)) }) } } diff --git a/config/configgrpc/configgrpc.go b/config/configgrpc/configgrpc.go index f570097ff4b4..e5f0dfc5fb01 100644 --- a/config/configgrpc/configgrpc.go +++ b/config/configgrpc/configgrpc.go @@ -55,7 +55,7 @@ type GRPCClientSettings struct { Endpoint string `mapstructure:"endpoint"` // The compression key for supported compression types within collector. - Compression configcompression.CompressionType `mapstructure:"compression"` + Compression configcompression.Type `mapstructure:"compression"` // TLSSetting struct exposes TLS client configuration. TLSSetting configtls.TLSClientSetting `mapstructure:"tls"` @@ -382,13 +382,13 @@ func (gss *GRPCServerSettings) toServerOption(host component.Host, settings comp } // getGRPCCompressionName returns compression name registered in grpc. -func getGRPCCompressionName(compressionType configcompression.CompressionType) (string, error) { +func getGRPCCompressionName(compressionType configcompression.Type) (string, error) { switch compressionType { - case configcompression.Gzip: + case configcompression.TypeGzip: return gzip.Name, nil - case configcompression.Snappy: + case configcompression.TypeSnappy: return snappy.Name, nil - case configcompression.Zstd: + case configcompression.TypeZstd: return zstd.Name, nil default: return "", fmt.Errorf("unsupported compression type %q", compressionType) diff --git a/config/configgrpc/configgrpc_test.go b/config/configgrpc/configgrpc_test.go index a3c6b089b93a..93d74dd650b9 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -82,7 +82,7 @@ func TestAllGrpcClientSettings(t *testing.T) { "test": "test", }, Endpoint: "localhost:1234", - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, TLSSetting: configtls.TLSClientSetting{ Insecure: false, }, @@ -111,7 +111,7 @@ func TestAllGrpcClientSettings(t *testing.T) { "test": "test", }, Endpoint: "localhost:1234", - Compression: configcompression.Snappy, + Compression: configcompression.TypeSnappy, TLSSetting: configtls.TLSClientSetting{ Insecure: false, }, @@ -140,7 +140,7 @@ func TestAllGrpcClientSettings(t *testing.T) { "test": "test", }, Endpoint: "localhost:1234", - Compression: configcompression.Zstd, + Compression: configcompression.TypeZstd, TLSSetting: configtls.TLSClientSetting{ Insecure: false, }, diff --git a/config/confighttp/compression.go b/config/confighttp/compression.go index faa716c44145..c219a1becba5 100644 --- a/config/confighttp/compression.go +++ b/config/confighttp/compression.go @@ -20,11 +20,11 @@ import ( type compressRoundTripper struct { rt http.RoundTripper - compressionType configcompression.CompressionType + compressionType configcompression.Type compressor *compressor } -func newCompressRoundTripper(rt http.RoundTripper, compressionType configcompression.CompressionType) (*compressRoundTripper, error) { +func newCompressRoundTripper(rt http.RoundTripper, compressionType configcompression.Type) (*compressRoundTripper, error) { encoder, err := newCompressor(compressionType) if err != nil { return nil, err diff --git a/config/confighttp/compression_test.go b/config/confighttp/compression_test.go index 091d9faff128..05fa3e3212bf 100644 --- a/config/confighttp/compression_test.go +++ b/config/confighttp/compression_test.go @@ -33,7 +33,7 @@ func TestHTTPClientCompression(t *testing.T) { tests := []struct { name string - encoding configcompression.CompressionType + encoding configcompression.Type reqBody []byte shouldError bool }{ @@ -51,31 +51,31 @@ func TestHTTPClientCompression(t *testing.T) { }, { name: "ValidGzip", - encoding: configcompression.Gzip, + encoding: configcompression.TypeGzip, reqBody: compressedGzipBody.Bytes(), shouldError: false, }, { name: "ValidZlib", - encoding: configcompression.Zlib, + encoding: configcompression.TypeZlib, reqBody: compressedZlibBody.Bytes(), shouldError: false, }, { name: "ValidDeflate", - encoding: configcompression.Deflate, + encoding: configcompression.TypeDeflate, reqBody: compressedDeflateBody.Bytes(), shouldError: false, }, { name: "ValidSnappy", - encoding: configcompression.Snappy, + encoding: configcompression.TypeSnappy, reqBody: compressedSnappyBody.Bytes(), shouldError: false, }, { name: "ValidZstd", - encoding: configcompression.Zstd, + encoding: configcompression.TypeZstd, reqBody: compressedZstdBody.Bytes(), shouldError: false, }, @@ -274,7 +274,7 @@ func TestHTTPContentCompressionRequestWithNilBody(t *testing.T) { require.NoError(t, err, "failed to create request to test handler") client := http.Client{} - client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.Gzip) + client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.TypeGzip) require.NoError(t, err) res, err := client.Do(req) require.NoError(t, err) @@ -305,7 +305,7 @@ func TestHTTPContentCompressionCopyError(t *testing.T) { require.NoError(t, err) client := http.Client{} - client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.Gzip) + client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.TypeGzip) require.NoError(t, err) _, err = client.Do(req) require.Error(t, err) @@ -329,7 +329,7 @@ func TestHTTPContentCompressionRequestBodyCloseError(t *testing.T) { require.NoError(t, err) client := http.Client{} - client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.Gzip) + client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.TypeGzip) require.NoError(t, err) _, err = client.Do(req) require.Error(t, err) diff --git a/config/confighttp/compressor.go b/config/confighttp/compressor.go index 0ff951d4130e..3e085bead0da 100644 --- a/config/confighttp/compressor.go +++ b/config/confighttp/compressor.go @@ -39,15 +39,15 @@ type compressor struct { // writerFactory defines writer field in CompressRoundTripper. // The validity of input is already checked when NewCompressRoundTripper was called in confighttp, -func newCompressor(compressionType configcompression.CompressionType) (*compressor, error) { +func newCompressor(compressionType configcompression.Type) (*compressor, error) { switch compressionType { - case configcompression.Gzip: + case configcompression.TypeGzip: return gZipPool, nil - case configcompression.Snappy: + case configcompression.TypeSnappy: return snappyPool, nil - case configcompression.Zstd: + case configcompression.TypeZstd: return zStdPool, nil - case configcompression.Zlib, configcompression.Deflate: + case configcompression.TypeZlib, configcompression.TypeDeflate: return zLibPool, nil } return nil, errors.New("unsupported compression type, ") diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index 894d6d85501b..3399cf6842fb 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -61,7 +61,7 @@ type HTTPClientSettings struct { Auth *configauth.Authentication `mapstructure:"auth"` // The compression key for supported compression types within collector. - Compression configcompression.CompressionType `mapstructure:"compression"` + Compression configcompression.Type `mapstructure:"compression"` // MaxIdleConns is used to set a limit to the maximum idle HTTP connections the client can keep open. // There's an already set value, and we want to override it only if an explicit value provided diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index ce0e43bbe18d..9d618d743a9d 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -417,7 +417,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { settings: HTTPClientSettings{ Endpoint: "localhost:1234", Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, }, shouldErr: false, host: &mockHost{ diff --git a/exporter/otlpexporter/factory.go b/exporter/otlpexporter/factory.go index 95685eae5a9e..ef09959235cc 100644 --- a/exporter/otlpexporter/factory.go +++ b/exporter/otlpexporter/factory.go @@ -36,7 +36,7 @@ func createDefaultConfig() component.Config { GRPCClientSettings: configgrpc.GRPCClientSettings{ Headers: map[string]configopaque.String{}, // Default to gzip compression - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, // We almost read 0 bytes, so no need to tune ReadBufferSize. WriteBufferSize: 512 * 1024, }, diff --git a/exporter/otlpexporter/factory_test.go b/exporter/otlpexporter/factory_test.go index c9fabc13b930..2cbcedbf43e0 100644 --- a/exporter/otlpexporter/factory_test.go +++ b/exporter/otlpexporter/factory_test.go @@ -33,7 +33,7 @@ func TestCreateDefaultConfig(t *testing.T) { assert.Equal(t, ocfg.RetryConfig, configretry.NewDefaultBackOffConfig()) assert.Equal(t, ocfg.QueueConfig, exporterhelper.NewDefaultQueueSettings()) assert.Equal(t, ocfg.TimeoutSettings, exporterhelper.NewDefaultTimeoutSettings()) - assert.Equal(t, ocfg.Compression, configcompression.Gzip) + assert.Equal(t, ocfg.Compression, configcompression.TypeGzip) } func TestCreateMetricsExporter(t *testing.T) { @@ -102,7 +102,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, }, }, }, @@ -111,7 +111,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, - Compression: configcompression.Snappy, + Compression: configcompression.TypeSnappy, }, }, }, @@ -120,7 +120,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ GRPCClientSettings: configgrpc.GRPCClientSettings{ Endpoint: endpoint, - Compression: configcompression.Zstd, + Compression: configcompression.TypeZstd, }, }, }, diff --git a/exporter/otlphttpexporter/factory.go b/exporter/otlphttpexporter/factory.go index 3ed71d626d02..c5e4376a2863 100644 --- a/exporter/otlphttpexporter/factory.go +++ b/exporter/otlphttpexporter/factory.go @@ -41,7 +41,7 @@ func createDefaultConfig() component.Config { Timeout: 30 * time.Second, Headers: map[string]configopaque.String{}, // Default to gzip compression - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, // We almost read 0 bytes, so no need to tune ReadBufferSize. WriteBufferSize: 512 * 1024, }, diff --git a/exporter/otlphttpexporter/factory_test.go b/exporter/otlphttpexporter/factory_test.go index 69749831c5ed..4909fbc54664 100644 --- a/exporter/otlphttpexporter/factory_test.go +++ b/exporter/otlphttpexporter/factory_test.go @@ -35,7 +35,7 @@ func TestCreateDefaultConfig(t *testing.T) { assert.Equal(t, ocfg.RetryConfig.InitialInterval, 5*time.Second, "default retry InitialInterval") assert.Equal(t, ocfg.RetryConfig.MaxInterval, 30*time.Second, "default retry MaxInterval") assert.Equal(t, ocfg.QueueConfig.Enabled, true, "default sending queue is enabled") - assert.Equal(t, ocfg.Compression, configcompression.Gzip) + assert.Equal(t, ocfg.Compression, configcompression.TypeGzip) } func TestCreateMetricsExporter(t *testing.T) { @@ -132,7 +132,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, }, }, }, @@ -141,7 +141,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, - Compression: configcompression.Snappy, + Compression: configcompression.TypeSnappy, }, }, }, @@ -150,7 +150,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ HTTPClientSettings: confighttp.HTTPClientSettings{ Endpoint: endpoint, - Compression: configcompression.Zstd, + Compression: configcompression.TypeZstd, }, }, },