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

Adds snappy support for http_listener_v2 #8966

Merged
merged 10 commits into from
Mar 18, 2021
Merged

Conversation

helenosheaa
Copy link
Member

@helenosheaa helenosheaa commented Mar 10, 2021

Adds snappy support plus test

Relates to #8682, #8967 - one use is for with prometheus remote write parsing

Copy link
Contributor

@telegraf-tiger telegraf-tiger bot left a comment

Choose a reason for hiding this comment

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

🤝 ✅ CLA has been signed. Thank you!

@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Mar 10, 2021
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

I would prefer to match the pattern of gzip and construct a reader. Is there any reason to not do it this way?

@helenosheaa
Copy link
Member Author

Thanks for the review, I'll take a look at matching the gzip pattern

@helenosheaa
Copy link
Member Author

helenosheaa commented Mar 11, 2021

So after just having another look at the docs, we want to use Decode rather than a NewReader as we need the block format rather than streaming format (specifically for the prometheus remote write use case). Bit more context here

Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@srebhan srebhan self-assigned this Mar 12, 2021
@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Mar 12, 2021
@@ -268,6 +269,17 @@ func (h *HTTPListenerV2) collectBody(res http.ResponseWriter, req *http.Request)
return nil, false
}

// Handle snappy request bodies
if req.Header.Get("Content-Encoding") == "snappy" {
Copy link
Contributor

Choose a reason for hiding this comment

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

About 20 lines above there's a similar block for gzip. It looks like we should change the "if content-encoding == gzip" to a switch statement that also handles snappy, then move this new block into the switch statement. The snappy decoding needs to happen at the same place gzip does, namely before the MaxBytesReader.

Copy link
Member Author

Choose a reason for hiding this comment

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

The NewReader function of snappy would return a reader such as the gzip implementation so the switch would work but the block implementation of snappy that we need (for prometheus remote write) is a Decode which takes in bytes and returns bytes. So I think it needs to be after the reader on 266 unless I'm missing something.

@helenosheaa helenosheaa merged commit cc6c51c into master Mar 18, 2021
@helenosheaa helenosheaa deleted the snappy-http-support branch March 18, 2021 15:33
jblesener pushed a commit to jblesener/telegraf that referenced this pull request Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants