Skip to content

Commit

Permalink
[configcompression] make IsCompressed a member function (#9435)
Browse files Browse the repository at this point in the history
**Description:** 
Updates `IsCompressed` to be a member function. 

**Link to tracking Issue:** <Issue number if applicable>

Closes
#9434

---------

Co-authored-by: Bogdan Drutu <bogdandrutu@gmail.com>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
  • Loading branch information
3 people committed Feb 1, 2024
1 parent cc7265d commit 923cba6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
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]
11 changes: 10 additions & 1 deletion config/configcompression/compressiontype.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@ const (
empty CompressionType = ""
)

// IsCompressed returns false if CompressionType is nil, none, or empty. Otherwise it returns true.
//
// Deprecated: [0.94.0] use member function CompressionType.IsCompressed instead
func IsCompressed(compressionType CompressionType) bool {
return compressionType != empty && compressionType != none
return compressionType.IsCompressed()
}

// 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 {
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

0 comments on commit 923cba6

Please sign in to comment.