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

feat(compression): Add the option of configuring compression levels #11084

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

rnishtala-sumo
Copy link
Contributor

@rnishtala-sumo rnishtala-sumo commented Sep 9, 2024

Description

Add the option of configuring compression levels. This is not intended to be a breaking change for the user.

Link to tracking issue

Issue - #10467

Testing

Unit tests were added/changed

Documentation

https://github.com/rnishtala-sumo/opentelemetry-collector/blob/configure-compression-levels/config/confighttp/README.md#client-configuration

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 79.01235% with 17 lines in your changes missing coverage. Please review.

Project coverage is 92.08%. Comparing base (4f79e0d) to head (427a8ed).

Files with missing lines Patch % Lines
config/confighttp/compressor.go 62.22% 14 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11084      +/-   ##
==========================================
- Coverage   92.14%   92.08%   -0.06%     
==========================================
  Files         433      433              
  Lines       20389    20437      +48     
==========================================
+ Hits        18787    18819      +32     
- Misses       1238     1251      +13     
- Partials      364      367       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rnishtala-sumo rnishtala-sumo force-pushed the configure-compression-levels branch 3 times, most recently from 2ff904d to e39d5e7 Compare September 10, 2024 15:25
@rnishtala-sumo rnishtala-sumo marked this pull request as ready for review September 10, 2024 15:26
@rnishtala-sumo rnishtala-sumo requested review from a team and codeboten September 10, 2024 15:26
@rnishtala-sumo rnishtala-sumo force-pushed the configure-compression-levels branch 2 times, most recently from 2165697 to f478e7d Compare September 10, 2024 19:02
@rnishtala-sumo rnishtala-sumo requested a review from a team as a code owner September 20, 2024 22:02
@rnishtala-sumo
Copy link
Contributor Author

@dmitrii Anoshin @alex Boten @mx-psi would appreciate some attention to this PR. It doesn't have any breaking changes.

config/confighttp/compressor.go Outdated Show resolved Hide resolved
config/confighttp/README.md Show resolved Hide resolved
config/configcompression/compressiontype.go Show resolved Hide resolved
config/configcompression/compressiontype.go Outdated Show resolved Hide resolved
config/configcompression/compressiontype.go Outdated Show resolved Hide resolved
config/confighttp/compressor.go Outdated Show resolved Hide resolved
@@ -216,8 +216,13 @@ func (hcs *ClientConfig) ToClient(ctx context.Context, host component.Host, sett

// 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.
var compressionTypeWithLevel configcompression.TypeWithLevel
err = compressionTypeWithLevel.UnmarshalText([]byte(hcs.Compression))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to call UnmarshalText explicitly. Changing ClientConfig.Compression field from configcompression.Type to configcompression.TypeWithLevel should be enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing that seemed to be a breaking change. There are errors like this seen in multiple contrib components

Error: config/config.go:147:24: invalid operation: cfg.Compression != "" (mismatched types configcompression.TypeWithLevel and untyped string)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is a Go API breaking change, but not an end-user breaking change. I think this is the cleanest solution. @open-telemetry/collector-approvers let me know if you have other ideas

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we make the API breaking change, are going to mute all the failing tests (in this repo) and have the contrib component owners fix that later. Sorry, I'm not clear on this process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitryax would appreciate some clarity on this. The suggested API breaking change is going to break collector tests that reference components from the contrib repo. Are we ok fixing those later in a separate PR?

Copy link
Contributor Author

@rnishtala-sumo rnishtala-sumo Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about keeping this as is (non-breaking) for this PR? and handle all breaking changes (core and contrib) in 2 other PRs. The only reason is, it seems to affect multiple contrib components (almost all)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitryax I have pushed the API breaking changes and the contrib tests(contrib-tests / contrib-tests-matrix) seem to be failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have an idea how to make it in several steps without breaking contrib and get this result, that would be great. I'm not aware of any

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only thing I can think of is keeping Compression as it original type in this PR i.e configcompression.Type as suggested in a previous comment, and handling the breaking changes together.

#11084 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can stick to the current plan. These are the only changes that need to go into the contrib repository

https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/35843/files

config/confighttp/README.md Outdated Show resolved Hide resolved
config/confighttp/README.md Outdated Show resolved Hide resolved
config/configcompression/compressiontype.go Outdated Show resolved Hide resolved

return fmt.Errorf("unsupported compression type/level %s/%d", compressionTyp, ct.Level)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be confusing output if user didn't provide level

Copy link
Contributor Author

@rnishtala-sumo rnishtala-sumo Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should print the default level, which I think is fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a change to the error message, please let me know if you think this is clearer

c7f36ad

Comment on lines 48 to 49
if gZipCompressor.pool.Get() == nil {
gZipCompressor.pool = sync.Pool{New: func() any { w, _ := gzip.NewWriterLevel(nil, int(compressionType.Level)); return w }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect. We are taking compressor with any level from the pool. If user picks zlib/1 first and it goes back to the pool, the second call with any other level like zlib/2 would still give the same zlib/1 instance from the pool. We cannot reuse them compressors with different levels.

We might need a map of pools built dynamically here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitryax it doesn't look like the user can change the compression level dynamically? Because they would need to restart the collector to change this configuration. Wouldn't the sync.pool be cleared when this happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a map of compressor pools for compressors that support levels, all the tests pass with this change
c7f36ad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants