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

[configcompression] make IsCompressed a member function #9435

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/configcompression-make-member-func.yaml
Original file line number Diff line number Diff line change
@@ -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: configcompressions

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate `IsCompressed`. Use `CompressionType.IsCompressed instead` instead.

# One or more tracking issues or pull requests related to the change
issues: [9435]

# (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]
7 changes: 7 additions & 0 deletions config/configcompression/compressiontype.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ const (
empty CompressionType = ""
)

// IsCompressed Deprecated [0.94.0] use member function CompressionType.IsCompressed instead
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
func IsCompressed(compressionType CompressionType) bool {
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
return compressionType != empty && compressionType != none
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved
}

// 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 *CompressionType) UnmarshalText(in []byte) error {
switch typ := CompressionType(in); typ {
case Gzip,
Expand Down
10 changes: 9 additions & 1 deletion config/configcompression/compressiontype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,37 @@ func TestUnmarshalText(t *testing.T) {
name string
compressionName []byte
shouldError bool
isCompressed bool
}{
{
name: "ValidGzip",
compressionName: []byte("gzip"),
shouldError: false,
isCompressed: true,
},
{
name: "ValidZlib",
compressionName: []byte("zlib"),
shouldError: false,
isCompressed: true,
},
{
name: "ValidDeflate",
compressionName: []byte("deflate"),
shouldError: false,
isCompressed: true,
},
{
name: "ValidSnappy",
compressionName: []byte("snappy"),
shouldError: false,
isCompressed: true,
},
{
name: "ValidZstd",
compressionName: []byte("zstd"),
shouldError: false,
isCompressed: true,
},
{
name: "ValidEmpty",
Expand All @@ -66,7 +72,9 @@ func TestUnmarshalText(t *testing.T) {
return
}
require.NoError(t, err)
assert.Equal(t, temp, CompressionType(tt.compressionName))
ct := CompressionType(tt.compressionName)
assert.Equal(t, temp, ct)
assert.Equal(t, tt.isCompressed, ct.IsCompressed())
})
}
}
2 changes: 1 addition & 1 deletion config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (gcs *GRPCClientSettings) ToClientConn(ctx context.Context, host component.

func (gcs *GRPCClientSettings) toDialOptions(host component.Host, settings component.TelemetrySettings) ([]grpc.DialOption, error) {
var opts []grpc.DialOption
if configcompression.IsCompressed(gcs.Compression) {
if gcs.Compression.IsCompressed() {
cp, err := getGRPCCompressionName(gcs.Compression)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (hcs *HTTPClientConfig) ToClient(host component.Host, settings component.Te

// Compress the body using specified compression methods if non-empty string is provided.
// Supporting gzip, zlib, deflate, snappy, and zstd; none is treated as uncompressed.
if configcompression.IsCompressed(hcs.Compression) {
if hcs.Compression.IsCompressed() {
clientTransport, err = newCompressRoundTripper(clientTransport, hcs.Compression)
if err != nil {
return nil, err
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 @@ -454,7 +454,7 @@ func TestHTTPClientSettingWithAuthConfig(t *testing.T) {
transport := client.Transport

// Compression should wrap Auth, unwrap it
if configcompression.IsCompressed(test.settings.Compression) {
if test.settings.Compression.IsCompressed() {
ct, ok := transport.(*compressRoundTripper)
assert.True(t, ok)
assert.Equal(t, test.settings.Compression, ct.compressionType)
Expand Down