Skip to content

Commit

Permalink
Fix build for all OS after #8424 (#8717)
Browse files Browse the repository at this point in the history
* Fix build for all OS after #8424

* Apply PR comments
  • Loading branch information
exekias authored Oct 24, 2018
1 parent 948c17b commit 1da9636
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 62 deletions.
28 changes: 26 additions & 2 deletions libbeat/reader/readjson/docker_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package readjson
import (
"bytes"
"encoding/json"
"runtime"
"time"

"github.com/elastic/beats/libbeat/common"
Expand All @@ -42,6 +43,8 @@ type DockerJSONReader struct {

// parse CRI flags
criflags bool

stripNewLine func(msg *reader.Message)
}

type logLine struct {
Expand All @@ -54,13 +57,21 @@ type logLine struct {

// New creates a new reader renaming a field
func New(r reader.Reader, stream string, partial bool, forceCRI bool, CRIFlags bool) *DockerJSONReader {
return &DockerJSONReader{
reader := DockerJSONReader{
stream: stream,
partial: partial,
reader: r,
forceCRI: forceCRI,
criflags: CRIFlags,
}

if runtime.GOOS == "windows" {
reader.stripNewLine = stripNewLineWin
} else {
reader.stripNewLine = stripNewLine
}

return &reader
}

// parseCRILog parses logs in CRI log format.
Expand Down Expand Up @@ -112,7 +123,7 @@ func (p *DockerJSONReader) parseCRILog(message *reader.Message, msg *logLine) er
// Remove \n ending for partial messages
message.Content = log[i]
if partial {
stripNewLine(message)
p.stripNewLine(message)
}

return nil
Expand Down Expand Up @@ -192,3 +203,16 @@ func (p *DockerJSONReader) Next() (reader.Message, error) {
return message, err
}
}

func stripNewLine(msg *reader.Message) {
l := len(msg.Content)
if l > 0 && msg.Content[l-1] == '\n' {
msg.Content = msg.Content[:l-1]
}
}

func stripNewLineWin(msg *reader.Message) {
msg.Content = bytes.TrimRightFunc(msg.Content, func(r rune) bool {
return r == '\n' || r == '\r'
})
}
30 changes: 0 additions & 30 deletions libbeat/reader/readjson/docker_json_unix.go

This file was deleted.

30 changes: 0 additions & 30 deletions libbeat/reader/readjson/docker_json_windows.go

This file was deleted.

0 comments on commit 1da9636

Please sign in to comment.