Skip to content

Commit

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

* Apply PR comments
  • Loading branch information
exekias authored and Carlos Pérez-Aradros Herce committed Oct 24, 2018
1 parent 5fd661b commit 4a2b572
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 62 deletions.
28 changes: 26 additions & 2 deletions filebeat/reader/docker_json/docker_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package docker_json
import (
"bytes"
"encoding/json"
"runtime"
"time"

"github.com/elastic/beats/filebeat/reader"
Expand All @@ -42,6 +43,8 @@ type Reader 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) *Reader {
return &Reader{
reader := Reader{
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 *Reader) parseCRILog(message *reader.Message, msg *logLine) error {
// 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 *Reader) 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 filebeat/reader/docker_json/docker_json_unix.go

This file was deleted.

30 changes: 0 additions & 30 deletions filebeat/reader/docker_json/docker_json_windows.go

This file was deleted.

0 comments on commit 4a2b572

Please sign in to comment.