Skip to content

Add config option to compress Datadog payload #2297

Closed

Description

@shakuzen

Compression cannot be enabled with DatadogConfig right now, but we do have the compress method on our abstract Request.Builder for HttpSender. Enabling compression by default seems reasonable and would help avoid the issue of going over the max payload size as mentioned in #1500.

Originally posted by @shakuzen in https://github.com/micrometer-metrics/micrometer/issue_comments/705314786

Activity

  1. added
    enhancement
    registry: datadog
    on Oct 15, 2020
  2. added this to the 1.6.0 milestone on Oct 15, 2020
  3. added
    release notes
    on Oct 15, 2020
  4. shakuzen commented on Oct 15, 2020

    @shakuzen
    MemberAuthor

    If there's no good reason to not compress the payload, we could do this without a config option. For small payloads, it could cost more CPU cycles to compress it than it is worth, but since publishing is done in a background thread, I'm not sure the cost is significant enough to warrant the added config option.

  5. dbingham commented on Oct 28, 2020

    @dbingham

    Has anyone tried this yet? I wrote my own HttpSender to wrap HttpUrlConnectionSender and in my send method I intercepted the Request, copied all the relevant info to a new Request.Builder, did the call to compress(), then did send() on my new object. When I did that the send failed and I saw this in the logs: failed to send metrics to datadog: Unable to decompress compressed payload.

    I also tried overriding the Content-Encoding header to be deflate so as to match the datadog python library but it still didn't work with the same error message.

    I'm hoping I'm missing something but I sure don't see what it would be. It looks like the datadog /api/v1/series just doesn't accept the compression provided by compress().

  6. shakuzen commented on Oct 29, 2020

    @shakuzen
    MemberAuthor

    I have not tried it yet. Perhaps @therve can shed some light on the previous comment.

  7. modified the milestones: 1.6.0, 1.7.0 on Oct 29, 2020
  8. therve commented on Oct 29, 2020

    @therve
    Contributor

    AFAIU, compress uses gzip, but Datadog expects zlib style compression, so using java.util.zip.Deflater instead. There is meaningful difference in the wrapping.

  9. shakuzen commented on Oct 29, 2020

    @shakuzen
    MemberAuthor

    That would explain it. Thank you for the details. We'd need to add support for that.

  10. dbingham commented on Oct 29, 2020

    @dbingham

    Yep, that's the ticket. I made a bad assumption that the server side would handle both zlib and gzip since they both use deflate internally. Updated my impl to use java.util.zip.Deflater instead of compress() and it works just fine.

    Thanks.

  11. modified the milestones: 1.7.0-M1, on Mar 8, 2021
  12. removed this from the milestone on May 12, 2021
  13. 1 remaining item

  14. filip-cubic commented on Jun 10, 2025

    @filip-cubic

    Any news on this? @dbingham did you make a PR with your changes? Compression would be extremely helpful, the effective allowed payload-size is several orders of magnitude larger.

  15. added
    help wanted
    on Jun 11, 2025
  16. shakuzen commented on Jun 11, 2025

    @shakuzen
    MemberAuthor

    A pull request would be welcome to help move this along. I've marked the issue as help wanted

  17. antonio-pedro99 commented on May 13, 2026

    @antonio-pedro99
    Contributor

    A pull request would be welcome to help move this along. I've marked the issue as help wanted

    Hi @shakuzen, I am new here. I was reading the micrometer docs(we use it at our company), and I thought it would be nice to contribute back to this project. I am currently working on synthentic monitoring component as part of my work, and I have solid understading of metrics and observability. This issue seems to be a good start for me. Do you mind assign it to me?

    And also, I wonder if it would be a good idea to add support for both zlib and gzip in the Request.Builder's compress() method. For example, the API would look something like this.

    // GZIP compression
    httpClient.compress(CompressionType.GZIP);
    // or
    // Backward compatible (defaults to GZIP)
    httpClient.compress(); // Still works
    
    // ZLIB compression
    httpClient.compress(CompressionType.ZLIB);
    
    // Conditional compression with GZIP
    httpClient.compressWhen(CompressionType.GZIP, () -> someCondition());
    
    // Conditional compression with ZLIB
    httpClient.compressWhen(CompressionType.ZLIB, () -> someCondition());

    In case of the DataDog, we should do something like this

    httpClient.compressWhen(() -> config.compressionEnabled() && bodyBytes.length > 512000)

    Note: bodyBytes.length > 512000 here is kind late and acts as emergency rescue only, just for demonstration. The actual implementation should compress earlier before the payload exceeds the max uncompressed payload allowed by DataDog We should maybe rely on a threshold: if the payload's size exceeds our threshold, we compress it and send it right away.

    Edit: since we use api/v1, the max size of a payload is 3200000

  18. shakuzen commented on May 14, 2026

    @shakuzen
    MemberAuthor

    Thanks for the offer to help @antonio-pedro99. Let me discuss with @jonatan-ivanov the direction we want to go on this. In general, I'd like to not make it more complicated than it needs to be. The absolute simplest thing would be to compress everything always with no configuration option. Maybe that's too simple. I'm not sure. If anyone can offer some perspective on real world workloads and thoughts around this, that would be helpful.

  19. antonio-pedro99 commented on May 14, 2026

    @antonio-pedro99
    Contributor

    Thanks for the offer to help @antonio-pedro99. Let me discuss with @jonatan-ivanov the direction we want to go on this. In general, I'd like to not make it more complicated than it needs to be. The absolute simplest thing would be to compress everything always with no configuration option. Maybe that's too simple. I'm not sure. If anyone can offer some perspective on real world workloads and thoughts around this, that would be helpful.

    Yes, I totally agree with you. I was thinking, and believe compress everything exceeding a threshold makes the work easier and clean.

  20. shakuzen commented on May 19, 2026

    @shakuzen
    MemberAuthor

    @jonatan-ivanov and I discussed this. The direction we would like to go is: add a boolean configuration option to enable compression on DatadogConfig and enable it by default. While the payload size heuristic as a trigger for enabling or disabling compression is clever, I'm not sure the complexity is warranted. In general, we expect metric payloads to be big enough to benefit from compression. If that is not the case for a user, they can disable compression with the configuration option. We can reconsider any of this based on user feedback, but that's what we're thinking currently. If that sounds alright to you, feel free to work on a pull request.

  21. antonio-pedro99 commented on May 19, 2026

    @antonio-pedro99
    Contributor

    @jonatan-ivanov and I discussed this. The direction we would like to go is: add a boolean configuration option to enable compression on DatadogConfig and enable it by default. While the payload size heuristic as a trigger for enabling or disabling compression is clever, I'm not sure the complexity is warranted. In general, we expect metric payloads to be big enough to benefit from compression. If that is not the case for a user, they can disable compression with the configuration option. We can reconsider any of this based on user feedback, but that's what we're thinking currently. If that sounds alright to you, feel free to work on a pull request.

    This is clear to me. I am working on a PR.

  22. removed
    help wanted
    on Aug 10, 2026
  23. modified the milestones: 1.x, 1.18.0-M1 on Aug 10, 2026
  24. added a commit that references this issue on Aug 10, 2026
    8b060cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementregistry: datadogrelease notes

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions