Skip to content

Commit

Permalink
Rename CompressionType
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerHelmuth committed Jan 29, 2024
1 parent 8b95295 commit ace7fdd
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 57 deletions.
41 changes: 22 additions & 19 deletions config/configcompression/compressiontype.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 24 in config/configcompression/compressiontype.go

View check run for this annotation

Codecov / codecov/patch

config/configcompression/compressiontype.go#L23-L24

Added lines #L23 - L24 were not covered by tests
}

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:
Expand Down
4 changes: 2 additions & 2 deletions config/configcompression/compressiontype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}
}
10 changes: 5 additions & 5 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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,
},
Expand Down
4 changes: 2 additions & 2 deletions config/confighttp/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions config/confighttp/compression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestHTTPClientCompression(t *testing.T) {

tests := []struct {
name string
encoding configcompression.CompressionType
encoding configcompression.Type
reqBody []byte
shouldError bool
}{
Expand All @@ -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,
},
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions config/confighttp/compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ")
Expand Down
2 changes: 1 addition & 1 deletion config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
8 changes: 4 additions & 4 deletions exporter/otlpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestCreateTracesExporter(t *testing.T) {
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: configcompression.Gzip,
Compression: configcompression.TypeGzip,
},
},
},
Expand All @@ -111,7 +111,7 @@ func TestCreateTracesExporter(t *testing.T) {
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: configcompression.Snappy,
Compression: configcompression.TypeSnappy,
},
},
},
Expand All @@ -120,7 +120,7 @@ func TestCreateTracesExporter(t *testing.T) {
config: &Config{
GRPCClientSettings: configgrpc.GRPCClientSettings{
Endpoint: endpoint,
Compression: configcompression.Zstd,
Compression: configcompression.TypeZstd,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion exporter/otlphttpexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
8 changes: 4 additions & 4 deletions exporter/otlphttpexporter/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestCreateTracesExporter(t *testing.T) {
config: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: endpoint,
Compression: configcompression.Gzip,
Compression: configcompression.TypeGzip,
},
},
},
Expand All @@ -141,7 +141,7 @@ func TestCreateTracesExporter(t *testing.T) {
config: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: endpoint,
Compression: configcompression.Snappy,
Compression: configcompression.TypeSnappy,
},
},
},
Expand All @@ -150,7 +150,7 @@ func TestCreateTracesExporter(t *testing.T) {
config: &Config{
HTTPClientSettings: confighttp.HTTPClientSettings{
Endpoint: endpoint,
Compression: configcompression.Zstd,
Compression: configcompression.TypeZstd,
},
},
},
Expand Down

0 comments on commit ace7fdd

Please sign in to comment.