-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Properly update offset in case of unparasable line #22685
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3d45fdc
Properly update offset in case of unparasable line
ChrsMark 015d379
add changelog
ChrsMark 6102bee
Update metrics state
ChrsMark f625a58
Merge remote-tracking branch 'upstream/master' into fix_docker_json_i…
ChrsMark d58c350
Ignore parseline error
ChrsMark 324b490
fmt
ChrsMark 67dcd5f
fix
ChrsMark e59afad
Add test
ChrsMark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{"log":"Fetching main repository github.com/elastic/beats...\n","stream":"stdout","time":"2016-03-02T22:58:51.338462311Z"} | ||
{"log":"Fetching dependencies...\n","stream":"stdout","time":"2016-03-02T22:59:04.609292428Z"} | ||
{"log":"Execute /scripts/packetbeat_before_build.sh\n","stream":"stdout","time":"2016-03-02T22:59:04.617434682Z"} | ||
{"log":"patching file vendor/github.com/tsg/gopacket/pcap/pcap.go\n","stream":"stdout","time":"2016-03-02T22:59:04.626534779Z"} | ||
{"log":"cp etc/packetbeat.template.json /build/packetbeat.template.json\n","stream":"stdout","time":"2016-03-02T22:59:04.639782988Z"} | ||
{"log":"# linux\n","stream":"stdout","time":"2016-03-02T22:59:04.646276053Z"} | ||
"log":"cp packetbeat.yml /build/packetbeat-linux.yml\n","stream":"stdout","time":"2016-03-02T22:59:04.647847045Z"} | ||
{"log":"# binary\n","stream":"stdout","time":"2016-03-02T22:59:04.653740138Z"} | ||
{"log":"cp packetbeat.yml /build/packetbeat-binary.yml\n","stream":"stdout","time":"2016-03-02T22:59:04.655979016Z"} | ||
{"log":"# darwin\n","stream":"stdout","time":"2016-03-02T22:59:04.661181197Z"} | ||
{"log":"cp packetbeat.yml /build/packetbeat-darwin.yml\n","stream":"stdout","time":"2016-03-02T22:59:04.662859769Z"} | ||
{"log":"sed -i.bk 's/device: any/device: en0/' /build/packetbeat-darwin.yml\n","stream":"stdout","time":"2016-03-02T22:59:04.66649744Z"} | ||
{"log":"rm /build/packetbeat-darwin.yml.bk\n","stream":"stdout","time":"2016-03-02T22:59:04.701199002Z"} | ||
{"log":"# win\n","stream":"stdout","time":"2016-03-02T22:59:04.705067809Z"} | ||
{"log":"cp packetbeat.yml /build/packetbeat-win.yml\n","stream":"stdout","time":"2016-03-02T22:59:04.706629907Z"} | ||
{"log":"sed -i.bk 's/device: any/device: 0/' /build/packetbeat-win.yml\n","stream":"stdout","time":"2016-03-02T22:59:04.711993313Z"} | ||
{"log":"rm /build/packetbeat-win.yml.bk\n","stream":"stdout","time":"2016-03-02T22:59:04.757913979Z"} | ||
{"log":"Compiling for windows/amd64...\n","stream":"stdout","time":"2016-03-02T22:59:04.761895467Z"} | ||
{"log":"Compiling for windows/386...\n","stream":"stdout","time":"2016-03-02T22:59:29.481736885Z"} | ||
{"log":"Compiling for darwin/amd64...\n","stream":"stdout","time":"2016-03-02T22:59:55.205334574Z"} | ||
{"log":"Moving binaries to host...\n","stream":"stdout","time":"2016-03-02T23:00:15.140397826Z"} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
package readjson | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
"time" | ||
|
||
|
@@ -53,7 +54,7 @@ func TestDockerJSON(t *testing.T) { | |
name: "Wrong JSON", | ||
input: [][]byte{[]byte(`this is not JSON`)}, | ||
stream: "all", | ||
expectedError: reader.ErrLineUnparsable, | ||
expectedError: io.EOF, | ||
expectedMessage: reader.Message{ | ||
Bytes: 16, | ||
}, | ||
|
@@ -73,7 +74,7 @@ func TestDockerJSON(t *testing.T) { | |
name: "Wrong CRI", | ||
input: [][]byte{[]byte(`2017-09-12T22:32:21.212861448Z stdout`)}, | ||
stream: "all", | ||
expectedError: reader.ErrLineUnparsable, | ||
expectedError: io.EOF, | ||
expectedMessage: reader.Message{ | ||
Bytes: 37, | ||
}, | ||
|
@@ -82,7 +83,7 @@ func TestDockerJSON(t *testing.T) { | |
name: "Wrong CRI", | ||
input: [][]byte{[]byte(`{this is not JSON nor CRI`)}, | ||
stream: "all", | ||
expectedError: reader.ErrLineUnparsable, | ||
expectedError: io.EOF, | ||
expectedMessage: reader.Message{ | ||
Bytes: 25, | ||
}, | ||
|
@@ -91,7 +92,7 @@ func TestDockerJSON(t *testing.T) { | |
name: "Missing time", | ||
input: [][]byte{[]byte(`{"log":"1:M 09 Nov 13:27:36.276 # User requested shutdown...\n","stream":"stdout"}`)}, | ||
stream: "all", | ||
expectedError: reader.ErrLineUnparsable, | ||
expectedError: io.EOF, | ||
expectedMessage: reader.Message{ | ||
Bytes: 82, | ||
}, | ||
|
@@ -218,7 +219,7 @@ func TestDockerJSON(t *testing.T) { | |
input: [][]byte{[]byte(`{"log":"1:M 09 Nov 13:27:36.276 # User requested shutdown...\n","stream":"stdout"}`)}, | ||
stream: "all", | ||
format: "cri", | ||
expectedError: reader.ErrLineUnparsable, | ||
expectedError: io.EOF, | ||
expectedMessage: reader.Message{ | ||
Bytes: 82, | ||
}, | ||
|
@@ -228,7 +229,7 @@ func TestDockerJSON(t *testing.T) { | |
input: [][]byte{[]byte(`2017-09-12T22:32:21.212861448Z stdout 2017-09-12 22:32:21.212 [INFO][88] table.go 710: Invalidating dataplane cache`)}, | ||
stream: "all", | ||
format: "docker", | ||
expectedError: reader.ErrLineUnparsable, | ||
expectedError: io.EOF, | ||
expectedMessage: reader.Message{ | ||
Bytes: 115, | ||
}, | ||
|
@@ -300,7 +301,7 @@ func TestDockerJSON(t *testing.T) { | |
[]byte(`{"log":"shutdown...\n","stream`), | ||
}, | ||
stream: "stdout", | ||
expectedError: reader.ErrLineUnparsable, | ||
expectedError: io.EOF, | ||
expectedMessage: reader.Message{ | ||
Bytes: 139, | ||
}, | ||
|
@@ -324,11 +325,25 @@ func TestDockerJSON(t *testing.T) { | |
name: "Corrupted log message line", | ||
input: [][]byte{[]byte(`36.276 # User requested shutdown...\n","stream":"stdout","time":"2017-11-09T13:27:36.277747246Z"}`)}, | ||
stream: "all", | ||
expectedError: reader.ErrLineUnparsable, | ||
expectedError: io.EOF, | ||
expectedMessage: reader.Message{ | ||
Bytes: 97, | ||
}, | ||
}, | ||
{ | ||
name: "Corrupted log message line is skipped, keep correct bytes count", | ||
input: [][]byte{ | ||
[]byte(`36.276 # User requested shutdown...\n","stream":"stdout","time":"2017-11-09T13:27:36.277747246Z"}`), | ||
[]byte(`{"log":"1:M 09 Nov 13:27:36.276 # User requested","stream":"stdout","time":"2017-11-09T13:27:36.277747246Z"}`), | ||
}, | ||
stream: "all", | ||
expectedMessage: reader.Message{ | ||
Content: []byte("1:M 09 Nov 13:27:36.276 # User requested"), | ||
Fields: common.MapStr{"stream": "stdout"}, | ||
Ts: time.Date(2017, 11, 9, 13, 27, 36, 277747246, time.UTC), | ||
Bytes: 205, | ||
}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
|
@@ -358,6 +373,12 @@ type mockReader struct { | |
} | ||
|
||
func (m *mockReader) Next() (reader.Message, error) { | ||
if len(m.messages) < 1 { | ||
return reader.Message{ | ||
Content: []byte{}, | ||
Bytes: 0, | ||
}, io.EOF | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a test were the first line is broken (from a truncate) but the next one is valid? we should get the content from the valid one only but bytes should account for both |
||
message := m.messages[0] | ||
m.messages = m.messages[1:] | ||
return reader.Message{ | ||
|
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.
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.
I love when issues get solved by removing code 🙂