Skip to content

Commit

Permalink
Improve journalctl version compat
Browse files Browse the repository at this point in the history
**What**
- Remove the `output-fields` flag because not all journalctl versions
  support it
- Add a short sleep to the start of the log stream to avoid some kind of
  race/buffering condition with the Handler

Signed-off-by: Lucas Roesler <[email protected]>
  • Loading branch information
LucasRoesler authored and alexellis committed Mar 7, 2020
1 parent 22882e2 commit cece6cf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ test-e2e:
sleep 3
/usr/local/bin/faas-cli list
sleep 1
/usr/local/bin/faas-cli logs figlet | grep Forking
/usr/local/bin/faas-cli logs figlet --follow=false | grep Forking
5 changes: 4 additions & 1 deletion pkg/logs/requestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func buildCmd(ctx context.Context, req logs.Request) *exec.Cmd {
"--utc",
"--no-pager",
"--output=json",
"--output-fields=SYSLOG_IDENTIFIER,MESSAGE,_PID,_SOURCE_REALTIME_TIMESTAMP",
"--identifier=" + namespace + ":" + req.Name,
fmt.Sprintf("--since=%s", since.UTC().Format("2006-01-02 15:04:05")),
}
Expand All @@ -103,6 +102,10 @@ func buildCmd(ctx context.Context, req logs.Request) *exec.Cmd {
// the loop is based on the Decoder example in the docs
// https://golang.org/pkg/encoding/json/#Decoder.Decode
func streamLogs(ctx context.Context, cmd *exec.Cmd, out io.ReadCloser, msgs chan logs.Message) {
// without this sleep the channel seems to get stuck. This results in either no log messages
// being read by the Handler _or_ the messages are read but only flushed when the request
// timesout
time.Sleep(time.Millisecond)
log.Println("starting journal stream using ", cmd.String())

// will ensure `out` is closed and all related resources cleaned up
Expand Down

0 comments on commit cece6cf

Please sign in to comment.