Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
fix(multiline): use proper advance and strip new line whitespaces fro…
Browse files Browse the repository at this point in the history
…m beginning of log

Signed-off-by: Dominik Rosiek <[email protected]>
  • Loading branch information
Dominik Rosiek committed Jul 7, 2021
1 parent fd4dbb8 commit e67e78e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions operator/helper/multiline.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewLineStartSplitFunc(re *regexp.Regexp, flushAtEOF bool) bufio.SplitFunc {
// Flush if no more data is expected
if len(data) != 0 && atEOF && flushAtEOF {
token = trimWhitespaces(data)
advance = len(token)
advance = len(data)
return
}
return 0, nil, nil // read more data and try again.
Expand All @@ -103,7 +103,7 @@ func NewLineStartSplitFunc(re *regexp.Regexp, flushAtEOF bool) bufio.SplitFunc {
// Flush if no more data is expected
if atEOF && flushAtEOF {
token = trimWhitespaces(data)
advance = len(token)
advance = len(data)
return
}

Expand All @@ -130,7 +130,7 @@ func NewLineEndSplitFunc(re *regexp.Regexp, flushAtEOF bool) bufio.SplitFunc {
// Flush if no more data is expected
if len(data) != 0 && atEOF && flushAtEOF {
token = trimWhitespaces(data)
advance = len(token)
advance = len(data)
return
}
return 0, nil, nil // read more data and try again
Expand Down Expand Up @@ -175,7 +175,7 @@ func NewNewlineSplitFunc(encoding encoding.Encoding, flushAtEOF bool) (bufio.Spl
// Flush if no more data is expected
if atEOF && flushAtEOF {
token = trimWhitespaces(data)
advance = len(token)
advance = len(data)
return
}

Expand All @@ -197,5 +197,8 @@ func encodedCarriageReturn(encoding encoding.Encoding) ([]byte, error) {
}

func trimWhitespaces(data []byte) []byte {
return bytes.TrimRight(data, "\r\n\t ")
// TrimLeft to strip EOF whitespaces in case of using $ in regex
// For some reason newline and carriage return are being moved to beginning of next log
// TrimRight to strip all whitespaces from the end of log
return bytes.TrimLeft(bytes.TrimRight(data, "\r\n\t "), "\r\n")
}
2 changes: 1 addition & 1 deletion operator/helper/multiline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestLineEndSplitFunc(t *testing.T) {
Raw: []byte("log1 LOGEND LOGEND\nlog2 LOGEND\n"),
ExpectedTokenized: []string{
"log1 LOGEND LOGEND",
"\nlog2 LOGEND",
"log2 LOGEND",
},
},
{
Expand Down

0 comments on commit e67e78e

Please sign in to comment.