diff --git a/.chloggen/configcompression-rename-enum.yaml b/.chloggen/configcompression-rename-enum.yaml new file mode 100755 index 00000000000..103a128bd18 --- /dev/null +++ b/.chloggen/configcompression-rename-enum.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: deprecation + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: configcompression + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Deprecate `CompressionType`, use `Type` instead. + +# One or more tracking issues or pull requests related to the change +issues: [9416] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] \ No newline at end of file diff --git a/config/configcompression/compressiontype.go b/config/configcompression/compressiontype.go index 2c595ac7737..9589d6e9ecc 100644 --- a/config/configcompression/compressiontype.go +++ b/config/configcompression/compressiontype.go @@ -5,16 +5,41 @@ package configcompression // import "go.opentelemetry.io/collector/config/config import "fmt" -type CompressionType string +// CompressionType represents a compression method +// Deprecated [0.94.0]: use Type instead. +type CompressionType = Type + +// Type represents a compression method +type Type string const ( - Gzip CompressionType = "gzip" - Zlib CompressionType = "zlib" + TypeGzip Type = "gzip" + TypeZlib Type = "zlib" + TypeDeflate Type = "deflate" + TypeSnappy Type = "snappy" + TypeZstd Type = "zstd" + typeNone Type = "none" + typeEmpty Type = "" + + // Gzip + // Deprecated [0.94.0]: use TypeGzip instead. + Gzip CompressionType = "gzip" + + // Zlib + // Deprecated [0.94.0]: use TypeZlib instead. + Zlib CompressionType = "zlib" + + // Deflate + // Deprecated [0.94.0]: use TypeDeflate instead. Deflate CompressionType = "deflate" - Snappy CompressionType = "snappy" - Zstd CompressionType = "zstd" - none CompressionType = "none" - empty CompressionType = "" + + // Snappy + // Deprecated [0.94.0]: use TypeSnappy instead. + Snappy CompressionType = "snappy" + + // Zstd + // Deprecated [0.94.0]: use TypeZstd instead. + Zstd CompressionType = "zstd" ) // IsCompressed returns false if CompressionType is nil, none, or empty. Otherwise it returns true. @@ -26,19 +51,19 @@ func IsCompressed(compressionType CompressionType) bool { // IsCompressed returns false if CompressionType is nil, none, or empty. // Otherwise, returns true. -func (ct *CompressionType) IsCompressed() bool { - return ct != nil && *ct != empty && *ct != none +func (ct *Type) IsCompressed() bool { + return *ct != typeEmpty && *ct != 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 229d54f4d33..cf8166d5a24 100644 --- a/config/configcompression/compressiontype_test.go +++ b/config/configcompression/compressiontype_test.go @@ -65,14 +65,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) - ct := CompressionType(tt.compressionName) + ct := Type(tt.compressionName) assert.Equal(t, temp, ct) assert.Equal(t, tt.isCompressed, ct.IsCompressed()) }) diff --git a/config/configgrpc/configgrpc.go b/config/configgrpc/configgrpc.go index eac3d22c634..92708209a22 100644 --- a/config/configgrpc/configgrpc.go +++ b/config/configgrpc/configgrpc.go @@ -59,7 +59,7 @@ type ClientConfig 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"` @@ -390,13 +390,13 @@ func (gss *ServerConfig) toServerOption(host component.Host, settings component. } // 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 1455824b14f..914f99d4f98 100644 --- a/config/configgrpc/configgrpc_test.go +++ b/config/configgrpc/configgrpc_test.go @@ -89,7 +89,7 @@ func TestAllGrpcClientSettings(t *testing.T) { "test": "test", }, Endpoint: "localhost:1234", - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, TLSSetting: configtls.TLSClientSetting{ Insecure: false, }, @@ -118,7 +118,7 @@ func TestAllGrpcClientSettings(t *testing.T) { "test": "test", }, Endpoint: "localhost:1234", - Compression: configcompression.Snappy, + Compression: configcompression.TypeSnappy, TLSSetting: configtls.TLSClientSetting{ Insecure: false, }, @@ -147,7 +147,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 faa716c4414..c219a1becba 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 d7fc44cd474..4e1c8d9f63a 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 0ff951d4130..3e085bead0d 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 44b15695f46..e0a6f34f8f2 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -65,7 +65,7 @@ type ClientConfig 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 7eaf1cb314f..8b9970df110 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -423,8 +423,8 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) { name: "with_auth_configuration_has_extension_and_compression", settings: ClientConfig{ Endpoint: "localhost:1234", - Auth: &configauth.Authentication{AuthenticatorID: mockID}, - Compression: configcompression.Gzip, + Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")}, + Compression: configcompression.TypeGzip, }, shouldErr: false, host: &mockHost{ diff --git a/exporter/otlpexporter/factory.go b/exporter/otlpexporter/factory.go index 3144cc4594b..dfb06073d93 100644 --- a/exporter/otlpexporter/factory.go +++ b/exporter/otlpexporter/factory.go @@ -36,7 +36,7 @@ func createDefaultConfig() component.Config { ClientConfig: configgrpc.ClientConfig{ 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 311f4b838f0..a3232a4094b 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{ ClientConfig: configgrpc.ClientConfig{ Endpoint: endpoint, - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, }, }, }, @@ -111,7 +111,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ ClientConfig: configgrpc.ClientConfig{ Endpoint: endpoint, - Compression: configcompression.Snappy, + Compression: configcompression.TypeSnappy, }, }, }, @@ -120,7 +120,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ ClientConfig: configgrpc.ClientConfig{ Endpoint: endpoint, - Compression: configcompression.Zstd, + Compression: configcompression.TypeZstd, }, }, }, diff --git a/exporter/otlphttpexporter/factory.go b/exporter/otlphttpexporter/factory.go index 6aeac2dcd93..39cf084c612 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 89526ed5fb7..04d2027f655 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{ ClientConfig: confighttp.ClientConfig{ Endpoint: endpoint, - Compression: configcompression.Gzip, + Compression: configcompression.TypeGzip, }, }, }, @@ -141,7 +141,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ ClientConfig: confighttp.ClientConfig{ Endpoint: endpoint, - Compression: configcompression.Snappy, + Compression: configcompression.TypeSnappy, }, }, }, @@ -150,7 +150,7 @@ func TestCreateTracesExporter(t *testing.T) { config: &Config{ ClientConfig: confighttp.ClientConfig{ Endpoint: endpoint, - Compression: configcompression.Zstd, + Compression: configcompression.TypeZstd, }, }, },