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

[EXPORTER] Gzip compression support for OTLP/HTTP and OTLP/gRPC exporter #2530

Merged
merged 31 commits into from
Feb 29, 2024

Conversation

perhapsmaple
Copy link
Contributor

@perhapsmaple perhapsmaple commented Feb 12, 2024

Fixes #2351

Changes

Added gzip compression as an option for the OtlpHttp and OtlpGrpc exporters.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
@perhapsmaple
Copy link
Contributor Author

perhapsmaple commented Feb 12, 2024

I'm not completely sure about why some builds pass and some fail. Do we need to add a separate find_package command for ZLIB. I'm a little new to CMake and Bazel and would appreciate any help.

Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
@lalitb
Copy link
Member

lalitb commented Feb 12, 2024

I'm not completely sure about why some builds pass and some fail. Do we need to add a separate find_package command for ZLIB. I'm a little new to CMake and Bazel and would appreciate any help.

Yes, you need to use find_package for CMake. For Bazel, see if this helps - https://stackoverflow.com/questions/70877000/bazel-c-how-to-include-a-library-that-needs-to-be-cloned-from-github-then-buil

perhapsmaple and others added 5 commits February 13, 2024 19:47
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
@lalitb
Copy link
Member

lalitb commented Feb 14, 2024

@perhapsmaple - The CI seems to be successful. Is this ready for review?

@perhapsmaple perhapsmaple marked this pull request as ready for review February 14, 2024 01:53
@perhapsmaple perhapsmaple requested a review from a team February 14, 2024 01:53
Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

Thanks for the feature.

It is nicely done, I must say you have a pretty good grasp of the code organization, and the patch fits nicely in the code base.

Please update file docs/requirements.md, to detail the new dependency on ZLIB.

Please provide a CHANGELOG.md entry, with an important notice that the build now depends on a new ZLIB dependency.

Typically, new features need to be protected by a ENABLE_COMPRESSION_PREVIEW flag.

In this case:

  • ZLIB itself is very mature, and introduces low risks
  • compression is set to none by default

so I think we can do without a ENABLE_COMPRESSION_PREVIEW build option, which adds complexity when adding it, and would add complexity when removing it in one or two releases.

We will discuss this in maintainers meeting, with approval to follow.

@marcalff
Copy link
Member

@perhapsmaple

Also, please indicate how testing was done.

For OTLP HTTP, a possibility is to change locally functional/otlp/func_http_main.cc to use gzip compression, and run tests against an opentelemetry-collector.

@marcalff marcalff changed the title Gzip compression support for OTLP/HTTP and OTLP/gRPC exporter [EXPORTER] Gzip compression support for OTLP/HTTP and OTLP/gRPC exporter Feb 14, 2024
ThomsonTan and others added 4 commits February 14, 2024 14:29
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
@perhapsmaple
Copy link
Contributor Author

@marcalff

Testing was done with an internal message queue which collects logs from multiple services with gzip compression enabled. However, I did find a major issue in my implementation. Because I was using the simple wrappers provided by zlib for compression and decompression, it turns out the zlib does not add the gzip headers by default unless you increase the windows size manually by 16. This was not a problem during my testing as my server uses the decompress wrapper function from zlib and does not require the gzip headers to be present. The opentelemetry-collector seems to require these headers. I have pushed a commit (excuse the typos) which does solve the issue and includes the proper gzip headers. I tested it with the otlp examples and it now works properly with the opentelemetry-collector. I am also investigating whether it will be beneficial to reuse one z_stream rather than create a new z_stream object for each export. It should not matter much but I will benchmark to verify the same.

I will update the rest of the documentation, and change functional/otlp/func_http_main.cc to add tests by tomorrow.

Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
@marcalff
Copy link
Member

@perhapsmaple

This PR was discussed in the maintainers meeting today.

To avoid disruption in makefiles and build scripts, we do need to define a feature flag.

Please implement the following:

  • Add a WITH_OTLP_HTTP_COMPRESSION option in CMakeLists.txt, OFF by default
  • Add a ENABLE_OTLP_HTTP_COMPRESSION_PREVIEW define in api/CMakeLists.txt
  • In http_operation_curl.cc
    • Protects the zlib path with ifdef ENABLE_OTLP_COMPRESSION_PREVIEW
    • Raise an error otherwise, if asking for compression without the preview option
  • Link with zlib only when WITH_OTLP_COMPRESSION is set

This applies only to the OTLP HTTP exporter, because the link changed to depend on a new library (zlib).

The OTLP GRPC exporter is not affected.

The plan is to:

  • release version 1.15.0 with WITH_OTLP_HTTP_COMPRESSION = OFF by default
  • later, release version 1.16.0 or better with WITH_OTLP_HTTP_COMPRESSION = ON by default
  • much later, release version 1.17.0 or better with the flag removed.

Signed-off-by: perhapsmaple <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: perhapsmaple <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: perhapsmaple <140232061+perhapsmaple@users.noreply.github.com>
Signed-off-by: Harish S <140232061+perhapsmaple@users.noreply.github.com>
Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

Now that compression support is optional, the CI no longer tests with it.

See file ci/do_ci.sh

See entries like

elif [[ "$1" == "cmake.maintainer.sync.test" ]]; then

and friends (cmake.maintainer.*)

Add:

-DWITH_OTLP_HTTP_COMPRESSION=ON

This will run maintainer tests with compression.

@marcalff
Copy link
Member

@perhapsmaple See previous comment for ci/do_ci.sh.

Signed-off-by: perhapsmaple <140232061+perhapsmaple@users.noreply.github.com>
@perhapsmaple
Copy link
Contributor Author

@marcalff I have update the CI accordingly. I think the bazel build also has to be updated to link zlib only when built with the otlp compression flag. I'm not very familiar with bazel and would appreciate any help.

@marcalff
Copy link
Member

@perhapsmaple Thanks for the CMake fixes in CI.

About bazel, you are correct this should also include a feature flag in the bazel build.

We lack experience with bazel as well, and looking closely, in fact, none of the feature flags provided in CMake have a bazel equivalent in opentelemetry.

I think this PR can go as is:

  • optional feature in CMake, opt in currently
  • no option available for bazel

When later the code is changed to have the feature by default, the bazel build will be expanded to include zlib.

For bazel, this should be less intrusive compared to CMake, because the bazel build in general already depends on the OTLP GRPC exporter, which depends on grpc, which depends on zlib.

@marcalff
Copy link
Member

Approving review, and adding a temporary do-not-merge flag (don't worry), because we are making a 1.14.2 release right now.

@marcalff marcalff added the pr:do-not-merge This PR is not ready to be merged. label Feb 27, 2024
Copy link
Member

@marcalff marcalff left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the compression support.

@ThomsonTan ThomsonTan removed the pr:do-not-merge This PR is not ready to be merged. label Feb 27, 2024
const int window_bits = 15 + 16;

int stream =
deflateInit2(&zs, Z_DEFAULT_COMPRESSION, Z_DEFLATED, window_bits, 8, Z_DEFAULT_STRATEGY);
Copy link
Member

@lalitb lalitb Feb 28, 2024

Choose a reason for hiding this comment

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

@perhapsmaple - Do you think we can use the in-place compression of the data without using a separate output buffer compressed_body, as suggested here - https://stackoverflow.com/questions/12398377/is-it-possible-to-have-zlib-read-from-and-write-to-the-same-memory-buffer/12412863#12412863. This is suggested by "Mark Adler", the author of zlib, and would be better memory optimzation in the hot-path of upload.

If not feasible in this PR., good to add a TODO and create an issue for tracking, so some one can pick it up.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

LGTM. Excellent work. Would be great to have more contributions from you :)

@lalitb lalitb added the ok-to-merge The PR is ok to merge (has two approves or raised by a maintainer/approver and has one approve) label Feb 29, 2024
@perhapsmaple
Copy link
Contributor Author

@lalitb Sorry for the late reply, I'm a little busy till next week. I think the in place compression technique would very much help with allocations. I will take a look and implement it as soon as possible.

@marcalff
Copy link
Member

@perhapsmaple

No rush, thanks for all the work done already.

I am merging this PR now then, the optimization can be done separately (and at your own pace).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-merge The PR is ok to merge (has two approves or raised by a maintainer/approver and has one approve)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OTLP Exporter] Add gzip compression support for OTLP/HTTP and OTLP/gRPC exporter.
5 participants