You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add config option to compress Datadog payload #2297
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.
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.
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().
AFAIU, compress uses gzip, but Datadog expects zlib style compression, so using java.util.zip.Deflater instead. There is meaningful difference in the wrapping.
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.
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.
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 compressionhttpClient.compress(CompressionType.GZIP);
// or// Backward compatible (defaults to GZIP)httpClient.compress(); // Still works// ZLIB compressionhttpClient.compress(CompressionType.ZLIB);
// Conditional compression with GZIPhttpClient.compressWhen(CompressionType.GZIP, () -> someCondition());
// Conditional compression with ZLIBhttpClient.compressWhen(CompressionType.ZLIB, () -> someCondition());
In case of the DataDog, we should do something like this
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
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.
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.
@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.
@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.
Activity
shakuzen commentedon Oct 15, 2020
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.
dbingham commentedon Oct 28, 2020
Has anyone tried this yet? I wrote my own
HttpSenderto wrapHttpUrlConnectionSenderand in my send method I intercepted theRequest, copied all the relevant info to a newRequest.Builder, did the call tocompress(), then didsend()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-Encodingheader to bedeflateso 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/seriesjust doesn't accept the compression provided bycompress().shakuzen commentedon Oct 29, 2020
I have not tried it yet. Perhaps @therve can shed some light on the previous comment.
therve commentedon Oct 29, 2020
AFAIU,
compressuses gzip, but Datadog expects zlib style compression, so usingjava.util.zip.Deflaterinstead. There is meaningful difference in the wrapping.shakuzen commentedon Oct 29, 2020
That would explain it. Thank you for the details. We'd need to add support for that.
dbingham commentedon Oct 29, 2020
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.Deflaterinstead ofcompress()and it works just fine.Thanks.
1 remaining item
filip-cubic commentedon Jun 10, 2025
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.
shakuzen commentedon Jun 11, 2025
A pull request would be welcome to help move this along. I've marked the issue as
help wantedantonio-pedro99 commentedon May 13, 2026
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.
In case of the DataDog, we should do something like this
shakuzen commentedon May 14, 2026
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.
antonio-pedro99 commentedon May 14, 2026
Yes, I totally agree with you. I was thinking, and believe compress everything exceeding a threshold makes the work easier and clean.
shakuzen commentedon May 19, 2026
@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.
antonio-pedro99 commentedon May 19, 2026
This is clear to me. I am working on a PR.
Compress datadog metrics payloads by default (micrometer-metrics#7502)
Adapt to changes in micrometer snapshots
Adapt to changes in micrometer snapshots