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

Fix gzip support in socket_listener with tcp sockets #7446

Merged
merged 2 commits into from
May 4, 2020

Conversation

danielnelson
Copy link
Contributor

closes #7377

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@danielnelson danielnelson added the fix pr to fix corresponding bug label May 1, 2020
@danielnelson danielnelson added this to the 1.15.0 milestone May 1, 2020
@danielnelson danielnelson requested a review from reimda May 1, 2020 01:09
"bytes"
"compress/gzip"
"errors"
"io"
)

// NewStreamContentEncoder returns a writer that will encode the stream
// according to the encoding type.
func NewStreamContentEncoder(encoding string, w io.Writer) (io.Writer, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't used outside of tests. Are you planning to use it later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove it for now, originally was planning to use it in the socket_writer but ended up leaving it with the batching version. Potentially we could use something like this to reduce memory usage.

}

func (w *GzipWriter) Write(p []byte) (int, error) {
w.z.Reset(w.w)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why we start a new gzip stream for each write. Doesn't this prevent the gzip algorithm from getting enough state to compress well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would if the write is small, my idea here was that it would be nice to be able to read each batch. I'm going to remove the Writer completely for now since it isn't used and we can sort this out later.

ssl.Log.Error("Read error: %v", err)
}

scnr := bufio.NewScanner(decoder)
Copy link
Contributor

Choose a reason for hiding this comment

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

We always wrap with decoder here. Wrapping makes sense to me for gzip, but not for identity. If identity, why not pass in c and not wrap at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the 'identity' case, internal.NewStreamContentDecoder is just returning the reader unwrapped. I thought it would be a bit nicer to push the switch logic into this factory function.

@danielnelson
Copy link
Contributor Author

I removed the GzipWriter related code, didn't end up using it for now so we can revive and complete it when we have the need.

@danielnelson danielnelson requested a review from reimda May 4, 2020 22:49
@danielnelson danielnelson merged commit d16485e into master May 4, 2020
@danielnelson danielnelson deleted the gzip-tcp-socket-listener branch May 4, 2020 23:26
@m4ce
Copy link
Contributor

m4ce commented May 18, 2020

@danielnelson - I tested this PR and I am seeing issues. I see random TCP disconnects when sending data.


Update: ignore, I had some code that was adding a newline at the end of the compressed payload. It was based on the old tests and forgot to remove it. It's all working as expected. Thank you!

idohalevi pushed a commit to idohalevi/telegraf that referenced this pull request Sep 29, 2020
arstercz pushed a commit to arstercz/telegraf that referenced this pull request Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix pr to fix corresponding bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

socket_listener unable to decode compressed TCP payloads
3 participants