[docker plugin] Refactor pipeline reader for data safety#14375
Merged
fearful-symmetry merged 8 commits intoelastic:feature/dockerbeatfrom Nov 13, 2019
Merged
Conversation
26 tasks
sayden
reviewed
Nov 7, 2019
urso
reviewed
Nov 9, 2019
urso
reviewed
Nov 9, 2019
urso
reviewed
Nov 9, 2019
Contributor
Author
|
Removed a bunch of dependencies that are no longer needed with this PR, hence the impressive diff. |
urso
reviewed
Nov 12, 2019
| if err != nil { | ||
| return errors.Wrap(err, "error getting length frame") | ||
| } | ||
| fmt.Fprintf(os.Stderr, "Got header specifying length %d\n", lenFrame) |
Contributor
Author
There was a problem hiding this comment.
Bah, I completely forgot I put those in.
urso
reviewed
Nov 12, 2019
urso
reviewed
Nov 12, 2019
urso
reviewed
Nov 13, 2019
| return nil, errors.Wrapf(err, "error opening logger fifo: %q", file) | ||
| } | ||
|
|
||
| return &PipeReader{fifoPipe: inputFile, byteOrder: binary.BigEndian, lenFrameBuf: make([]byte, 4), bodyBuf: nil, maxSize: 2e6}, nil |
urso
reviewed
Nov 13, 2019
| if err != nil { | ||
| return errors.Wrap(err, "error reading buffer") | ||
| } | ||
| return proto.Unmarshal(readBuf[:lenFrame], log) |
There was a problem hiding this comment.
nit: given len(readBuf) == lenFrame we don't need readBuf[:lenFrame].
urso
approved these changes
Nov 13, 2019
leweafan
pushed a commit
to leweafan/beats
that referenced
this pull request
Apr 28, 2023
* refactor pipeline reader for data safety
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks a ton to @urso for helping me understand what was actually going on here.
What is this?
This addresses an item mentioned in #13990 :
The issue is that the original reader,
Uint32DelimitedReader, can improperly scroll through the buffer and leave it in an invalid state.A FIFO reader from docker is a stream, consisting of a length header and a body. This new reader takes a three-step approach when it comes to scrolling through the buffer:
lengthbytes and continue.How do I test this?
On a host that has docker, run
mage buildandmage install. After that, connect to a running container with a command like:docker run --log-driver=ossifrage/dockerlogbeat:0.0.1 --log-opt output.elasticsearch.hosts="172.18.0.2:9200" --log-opt output.elasticsearch.index="dockerbeat-test" -it debian:jessie /bin/bash