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 9fd0858
Showing 1 changed file with 8 additions and 5 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")
}

0 comments on commit 9fd0858

Please sign in to comment.