Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

progressui: print logs for failed step as summary in plain mode #2214

Merged
merged 1 commit into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions util/progress/progressui/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package progressui

import (
"bytes"
"container/ring"
"context"
"fmt"
"io"
Expand Down Expand Up @@ -130,6 +131,7 @@ type vertex struct {
logs [][]byte
logsPartial bool
logsOffset int
logsBuffer *ring.Ring // stores last logs to print them on error
prev *client.Vertex
events []string
lastBlockTime *time.Time
Expand Down Expand Up @@ -295,10 +297,20 @@ func (t *trace) printErrorLogs(f io.Writer) {
if v.Error != "" && !strings.HasSuffix(v.Error, context.Canceled.Error()) {
fmt.Fprintln(f, "------")
fmt.Fprintf(f, " > %s:\n", v.Name)
// tty keeps original logs
for _, l := range v.logs {
f.Write(l)
fmt.Fprintln(f)
}
// printer keeps last logs buffer
if v.logsBuffer != nil {
for i := 0; i < v.logsBuffer.Len(); i++ {
if v.logsBuffer.Value != nil {
fmt.Fprintln(f, string(v.logsBuffer.Value.([]byte)))
}
v.logsBuffer = v.logsBuffer.Next()
}
}
fmt.Fprintln(f, "------")
}
}
Expand Down
10 changes: 10 additions & 0 deletions util/progress/progressui/printer.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package progressui

import (
"container/ring"
"context"
"fmt"
"io"
Expand All @@ -18,6 +19,8 @@ const maxDelay = 10 * time.Second
const minTimeDelta = 5 * time.Second
const minProgressDelta = 0.05 // %

const logsBufferSize = 10

type lastStatus struct {
Current int64
Timestamp time.Time
Expand Down Expand Up @@ -130,6 +133,13 @@ func (p *textMux) printVtx(t *trace, dgst digest.Digest) {
if i != len(v.logs)-1 || !v.logsPartial {
fmt.Fprintln(p.w, "")
}
if v.logsBuffer == nil {
v.logsBuffer = ring.New(logsBufferSize)
}
v.logsBuffer.Value = l
if !v.logsPartial {
v.logsBuffer = v.logsBuffer.Next()
}
}

if len(v.logs) > 0 {
Expand Down