Skip to content

Commit f5a7315

Browse files
TylerHelmuthmx-psi
andauthored
[configcompression] Rename CompressionType to Type (#9416)
**Description:** If we choose to go with the rename. **Link to tracking Issue:** <Issue number if applicable> Related to #9388 --------- Co-authored-by: Pablo Baeyens <[email protected]>
1 parent cae7e2a commit f5a7315

File tree

14 files changed

+107
-57
lines changed

14 files changed

+107
-57
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: deprecation
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: configcompression
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Deprecate `CompressionType`, use `Type` instead.
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [9416]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# Optional: The change log or logs in which this entry should be included.
21+
# e.g. '[user]' or '[user, api]'
22+
# Include 'user' if the change is relevant to end users.
23+
# Include 'api' if there is a change to a library API.
24+
# Default: '[user]'
25+
change_logs: [api]

config/configcompression/compressiontype.go

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,41 @@ package configcompression // import "go.opentelemetry.io/collector/config/config
55

66
import "fmt"
77

8-
type CompressionType string
8+
// CompressionType represents a compression method
9+
// Deprecated [0.94.0]: use Type instead.
10+
type CompressionType = Type
11+
12+
// Type represents a compression method
13+
type Type string
914

1015
const (
11-
Gzip CompressionType = "gzip"
12-
Zlib CompressionType = "zlib"
16+
TypeGzip Type = "gzip"
17+
TypeZlib Type = "zlib"
18+
TypeDeflate Type = "deflate"
19+
TypeSnappy Type = "snappy"
20+
TypeZstd Type = "zstd"
21+
typeNone Type = "none"
22+
typeEmpty Type = ""
23+
24+
// Gzip
25+
// Deprecated [0.94.0]: use TypeGzip instead.
26+
Gzip CompressionType = "gzip"
27+
28+
// Zlib
29+
// Deprecated [0.94.0]: use TypeZlib instead.
30+
Zlib CompressionType = "zlib"
31+
32+
// Deflate
33+
// Deprecated [0.94.0]: use TypeDeflate instead.
1334
Deflate CompressionType = "deflate"
14-
Snappy CompressionType = "snappy"
15-
Zstd CompressionType = "zstd"
16-
none CompressionType = "none"
17-
empty CompressionType = ""
35+
36+
// Snappy
37+
// Deprecated [0.94.0]: use TypeSnappy instead.
38+
Snappy CompressionType = "snappy"
39+
40+
// Zstd
41+
// Deprecated [0.94.0]: use TypeZstd instead.
42+
Zstd CompressionType = "zstd"
1843
)
1944

2045
// IsCompressed returns false if CompressionType is nil, none, or empty. Otherwise it returns true.
@@ -26,19 +51,19 @@ func IsCompressed(compressionType CompressionType) bool {
2651

2752
// IsCompressed returns false if CompressionType is nil, none, or empty.
2853
// Otherwise, returns true.
29-
func (ct *CompressionType) IsCompressed() bool {
30-
return ct != nil && *ct != empty && *ct != none
54+
func (ct *Type) IsCompressed() bool {
55+
return *ct != typeEmpty && *ct != typeNone
3156
}
3257

33-
func (ct *CompressionType) UnmarshalText(in []byte) error {
34-
switch typ := CompressionType(in); typ {
35-
case Gzip,
36-
Zlib,
37-
Deflate,
38-
Snappy,
39-
Zstd,
40-
none,
41-
empty:
58+
func (ct *Type) UnmarshalText(in []byte) error {
59+
switch typ := Type(in); typ {
60+
case TypeGzip,
61+
TypeZlib,
62+
TypeDeflate,
63+
TypeSnappy,
64+
TypeZstd,
65+
typeNone,
66+
typeEmpty:
4267
*ct = typ
4368
return nil
4469
default:

config/configcompression/compressiontype_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ func TestUnmarshalText(t *testing.T) {
6565
}
6666
for _, tt := range tests {
6767
t.Run(tt.name, func(t *testing.T) {
68-
temp := none
68+
temp := typeNone
6969
err := temp.UnmarshalText(tt.compressionName)
7070
if tt.shouldError {
7171
assert.Error(t, err)
7272
return
7373
}
7474
require.NoError(t, err)
75-
ct := CompressionType(tt.compressionName)
75+
ct := Type(tt.compressionName)
7676
assert.Equal(t, temp, ct)
7777
assert.Equal(t, tt.isCompressed, ct.IsCompressed())
7878
})

config/configgrpc/configgrpc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type ClientConfig struct {
5959
Endpoint string `mapstructure:"endpoint"`
6060

6161
// The compression key for supported compression types within collector.
62-
Compression configcompression.CompressionType `mapstructure:"compression"`
62+
Compression configcompression.Type `mapstructure:"compression"`
6363

6464
// TLSSetting struct exposes TLS client configuration.
6565
TLSSetting configtls.TLSClientSetting `mapstructure:"tls"`
@@ -390,13 +390,13 @@ func (gss *ServerConfig) toServerOption(host component.Host, settings component.
390390
}
391391

392392
// getGRPCCompressionName returns compression name registered in grpc.
393-
func getGRPCCompressionName(compressionType configcompression.CompressionType) (string, error) {
393+
func getGRPCCompressionName(compressionType configcompression.Type) (string, error) {
394394
switch compressionType {
395-
case configcompression.Gzip:
395+
case configcompression.TypeGzip:
396396
return gzip.Name, nil
397-
case configcompression.Snappy:
397+
case configcompression.TypeSnappy:
398398
return snappy.Name, nil
399-
case configcompression.Zstd:
399+
case configcompression.TypeZstd:
400400
return zstd.Name, nil
401401
default:
402402
return "", fmt.Errorf("unsupported compression type %q", compressionType)

config/configgrpc/configgrpc_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
8989
"test": "test",
9090
},
9191
Endpoint: "localhost:1234",
92-
Compression: configcompression.Gzip,
92+
Compression: configcompression.TypeGzip,
9393
TLSSetting: configtls.TLSClientSetting{
9494
Insecure: false,
9595
},
@@ -118,7 +118,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
118118
"test": "test",
119119
},
120120
Endpoint: "localhost:1234",
121-
Compression: configcompression.Snappy,
121+
Compression: configcompression.TypeSnappy,
122122
TLSSetting: configtls.TLSClientSetting{
123123
Insecure: false,
124124
},
@@ -147,7 +147,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
147147
"test": "test",
148148
},
149149
Endpoint: "localhost:1234",
150-
Compression: configcompression.Zstd,
150+
Compression: configcompression.TypeZstd,
151151
TLSSetting: configtls.TLSClientSetting{
152152
Insecure: false,
153153
},

config/confighttp/compression.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import (
2020

2121
type compressRoundTripper struct {
2222
rt http.RoundTripper
23-
compressionType configcompression.CompressionType
23+
compressionType configcompression.Type
2424
compressor *compressor
2525
}
2626

27-
func newCompressRoundTripper(rt http.RoundTripper, compressionType configcompression.CompressionType) (*compressRoundTripper, error) {
27+
func newCompressRoundTripper(rt http.RoundTripper, compressionType configcompression.Type) (*compressRoundTripper, error) {
2828
encoder, err := newCompressor(compressionType)
2929
if err != nil {
3030
return nil, err

config/confighttp/compression_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestHTTPClientCompression(t *testing.T) {
3333

3434
tests := []struct {
3535
name string
36-
encoding configcompression.CompressionType
36+
encoding configcompression.Type
3737
reqBody []byte
3838
shouldError bool
3939
}{
@@ -51,31 +51,31 @@ func TestHTTPClientCompression(t *testing.T) {
5151
},
5252
{
5353
name: "ValidGzip",
54-
encoding: configcompression.Gzip,
54+
encoding: configcompression.TypeGzip,
5555
reqBody: compressedGzipBody.Bytes(),
5656
shouldError: false,
5757
},
5858
{
5959
name: "ValidZlib",
60-
encoding: configcompression.Zlib,
60+
encoding: configcompression.TypeZlib,
6161
reqBody: compressedZlibBody.Bytes(),
6262
shouldError: false,
6363
},
6464
{
6565
name: "ValidDeflate",
66-
encoding: configcompression.Deflate,
66+
encoding: configcompression.TypeDeflate,
6767
reqBody: compressedDeflateBody.Bytes(),
6868
shouldError: false,
6969
},
7070
{
7171
name: "ValidSnappy",
72-
encoding: configcompression.Snappy,
72+
encoding: configcompression.TypeSnappy,
7373
reqBody: compressedSnappyBody.Bytes(),
7474
shouldError: false,
7575
},
7676
{
7777
name: "ValidZstd",
78-
encoding: configcompression.Zstd,
78+
encoding: configcompression.TypeZstd,
7979
reqBody: compressedZstdBody.Bytes(),
8080
shouldError: false,
8181
},
@@ -274,7 +274,7 @@ func TestHTTPContentCompressionRequestWithNilBody(t *testing.T) {
274274
require.NoError(t, err, "failed to create request to test handler")
275275

276276
client := http.Client{}
277-
client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.Gzip)
277+
client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.TypeGzip)
278278
require.NoError(t, err)
279279
res, err := client.Do(req)
280280
require.NoError(t, err)
@@ -305,7 +305,7 @@ func TestHTTPContentCompressionCopyError(t *testing.T) {
305305
require.NoError(t, err)
306306

307307
client := http.Client{}
308-
client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.Gzip)
308+
client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.TypeGzip)
309309
require.NoError(t, err)
310310
_, err = client.Do(req)
311311
require.Error(t, err)
@@ -329,7 +329,7 @@ func TestHTTPContentCompressionRequestBodyCloseError(t *testing.T) {
329329
require.NoError(t, err)
330330

331331
client := http.Client{}
332-
client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.Gzip)
332+
client.Transport, err = newCompressRoundTripper(http.DefaultTransport, configcompression.TypeGzip)
333333
require.NoError(t, err)
334334
_, err = client.Do(req)
335335
require.Error(t, err)

config/confighttp/compressor.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ type compressor struct {
3939

4040
// writerFactory defines writer field in CompressRoundTripper.
4141
// The validity of input is already checked when NewCompressRoundTripper was called in confighttp,
42-
func newCompressor(compressionType configcompression.CompressionType) (*compressor, error) {
42+
func newCompressor(compressionType configcompression.Type) (*compressor, error) {
4343
switch compressionType {
44-
case configcompression.Gzip:
44+
case configcompression.TypeGzip:
4545
return gZipPool, nil
46-
case configcompression.Snappy:
46+
case configcompression.TypeSnappy:
4747
return snappyPool, nil
48-
case configcompression.Zstd:
48+
case configcompression.TypeZstd:
4949
return zStdPool, nil
50-
case configcompression.Zlib, configcompression.Deflate:
50+
case configcompression.TypeZlib, configcompression.TypeDeflate:
5151
return zLibPool, nil
5252
}
5353
return nil, errors.New("unsupported compression type, ")

config/confighttp/confighttp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type ClientConfig struct {
6565
Auth *configauth.Authentication `mapstructure:"auth"`
6666

6767
// The compression key for supported compression types within collector.
68-
Compression configcompression.CompressionType `mapstructure:"compression"`
68+
Compression configcompression.Type `mapstructure:"compression"`
6969

7070
// MaxIdleConns is used to set a limit to the maximum idle HTTP connections the client can keep open.
7171
// There's an already set value, and we want to override it only if an explicit value provided

config/confighttp/confighttp_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
423423
name: "with_auth_configuration_has_extension_and_compression",
424424
settings: ClientConfig{
425425
Endpoint: "localhost:1234",
426-
Auth: &configauth.Authentication{AuthenticatorID: mockID},
427-
Compression: configcompression.Gzip,
426+
Auth: &configauth.Authentication{AuthenticatorID: component.NewID("mock")},
427+
Compression: configcompression.TypeGzip,
428428
},
429429
shouldErr: false,
430430
host: &mockHost{

exporter/otlpexporter/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func createDefaultConfig() component.Config {
3636
ClientConfig: configgrpc.ClientConfig{
3737
Headers: map[string]configopaque.String{},
3838
// Default to gzip compression
39-
Compression: configcompression.Gzip,
39+
Compression: configcompression.TypeGzip,
4040
// We almost read 0 bytes, so no need to tune ReadBufferSize.
4141
WriteBufferSize: 512 * 1024,
4242
},

exporter/otlpexporter/factory_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestCreateDefaultConfig(t *testing.T) {
3333
assert.Equal(t, ocfg.RetryConfig, configretry.NewDefaultBackOffConfig())
3434
assert.Equal(t, ocfg.QueueConfig, exporterhelper.NewDefaultQueueSettings())
3535
assert.Equal(t, ocfg.TimeoutSettings, exporterhelper.NewDefaultTimeoutSettings())
36-
assert.Equal(t, ocfg.Compression, configcompression.Gzip)
36+
assert.Equal(t, ocfg.Compression, configcompression.TypeGzip)
3737
}
3838

3939
func TestCreateMetricsExporter(t *testing.T) {
@@ -102,7 +102,7 @@ func TestCreateTracesExporter(t *testing.T) {
102102
config: &Config{
103103
ClientConfig: configgrpc.ClientConfig{
104104
Endpoint: endpoint,
105-
Compression: configcompression.Gzip,
105+
Compression: configcompression.TypeGzip,
106106
},
107107
},
108108
},
@@ -111,7 +111,7 @@ func TestCreateTracesExporter(t *testing.T) {
111111
config: &Config{
112112
ClientConfig: configgrpc.ClientConfig{
113113
Endpoint: endpoint,
114-
Compression: configcompression.Snappy,
114+
Compression: configcompression.TypeSnappy,
115115
},
116116
},
117117
},
@@ -120,7 +120,7 @@ func TestCreateTracesExporter(t *testing.T) {
120120
config: &Config{
121121
ClientConfig: configgrpc.ClientConfig{
122122
Endpoint: endpoint,
123-
Compression: configcompression.Zstd,
123+
Compression: configcompression.TypeZstd,
124124
},
125125
},
126126
},

exporter/otlphttpexporter/factory.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func createDefaultConfig() component.Config {
4141
Timeout: 30 * time.Second,
4242
Headers: map[string]configopaque.String{},
4343
// Default to gzip compression
44-
Compression: configcompression.Gzip,
44+
Compression: configcompression.TypeGzip,
4545
// We almost read 0 bytes, so no need to tune ReadBufferSize.
4646
WriteBufferSize: 512 * 1024,
4747
},

exporter/otlphttpexporter/factory_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestCreateDefaultConfig(t *testing.T) {
3535
assert.Equal(t, ocfg.RetryConfig.InitialInterval, 5*time.Second, "default retry InitialInterval")
3636
assert.Equal(t, ocfg.RetryConfig.MaxInterval, 30*time.Second, "default retry MaxInterval")
3737
assert.Equal(t, ocfg.QueueConfig.Enabled, true, "default sending queue is enabled")
38-
assert.Equal(t, ocfg.Compression, configcompression.Gzip)
38+
assert.Equal(t, ocfg.Compression, configcompression.TypeGzip)
3939
}
4040

4141
func TestCreateMetricsExporter(t *testing.T) {
@@ -132,7 +132,7 @@ func TestCreateTracesExporter(t *testing.T) {
132132
config: &Config{
133133
ClientConfig: confighttp.ClientConfig{
134134
Endpoint: endpoint,
135-
Compression: configcompression.Gzip,
135+
Compression: configcompression.TypeGzip,
136136
},
137137
},
138138
},
@@ -141,7 +141,7 @@ func TestCreateTracesExporter(t *testing.T) {
141141
config: &Config{
142142
ClientConfig: confighttp.ClientConfig{
143143
Endpoint: endpoint,
144-
Compression: configcompression.Snappy,
144+
Compression: configcompression.TypeSnappy,
145145
},
146146
},
147147
},
@@ -150,7 +150,7 @@ func TestCreateTracesExporter(t *testing.T) {
150150
config: &Config{
151151
ClientConfig: confighttp.ClientConfig{
152152
Endpoint: endpoint,
153-
Compression: configcompression.Zstd,
153+
Compression: configcompression.TypeZstd,
154154
},
155155
},
156156
},

0 commit comments

Comments
 (0)