-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Implement HTTP Output Compression #4807
Implement HTTP Output Compression #4807
Conversation
I'm curious to know, and would wait to find out, what @danielnelson has to say on the matter though. |
We could move the shared code under I would rather avoid a pool for gzip.Writer. If it is a performance bottleneck, it may make sense to reuse the Writer between calls to Write, within a plugin instance, but I would want to see some benchmarks showing the gzip.Writer as a significant portion of write time first. On brotli, I don't think it has enough adoption to warrant, I'm just hearing of it for the first time now. |
8954aff
to
a53e591
Compare
@glinton @danielnelson Thanks for answering my questions! I have implemented Studying this Regarding Regarding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setting of the error in CompressWithGzip is definitely wrong, but I don't think an error channel would be the right approach here as we really want any reader errors passed though the Pipe, this way the user of the pipe (http package in this case) gets the error. This would give consistent behavior with other errors in the Reader.
I'm not immediately sure how to implement this, but we shouldn't return the error from CompressWithGzip since we can't detect an error at this point. Also, fixing the error handling is optional for this PR, since it wouldn't be a step backwards.
plugins/outputs/http/http.go
Outdated
var reqBodyBuffer io.Reader = bytes.NewBuffer(reqBody) | ||
var err error | ||
|
||
if h.ContentEncoding == "gzip" && h.Method == http.MethodPost { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only for POST method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what was requested in #4472. It will add a bit of overhead to requests which don't have a body, but I wouldn't normally consider such small optimisations. Maybe @madisonleavo can offer additional insight. If not, I can delete that condition. Just let me know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the requests currently have a body in this plugin, and it is hard to imagine a new data format that wouldn't produce it, perhaps a null data format? At any rate we currently do POST and PUT and I think they should both use the encoding if it is requested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Done in 26ee478.
plugins/outputs/http/README.md
Outdated
|
||
## HTTP Content-Encoding for write request body, can be set to "gzip" to | ||
## compress body or empty string to not apply any encoding. | ||
# content_encoding = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is minor but can you document like the influxdb option with the identity
setting as default, no code needs to change:
## HTTP Content-Encoding for write request body, can be set to "gzip" to
## compress body or "identity" to apply no encoding.
# content_encoding = "identity"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a53e591
to
4a49fee
Compare
Indeed, you are right! I got carried away thinking that it would be enough to return an error in the How about calling
I agree. Will open a new issue. |
That sounds perfect |
4a49fee
to
1e0a10a
Compare
@danielnelson OK, I believe I have addressed all the required changes in this PR. Please let me know if I missed anything. |
Did you do the CloseWithError idea, I'm not seeing it? |
Propagate io.Copy errors through the io.Pipe
Oops, communication issue. I thought you preferred to have a new PR for it. Added it in 11cdf77. |
Thanks! |
Fixes #4472.
TODO:
compressWithGzip
here, since it's already present in influxdb and in influxdb_v2?Required for all PRs: