Improve tty error logging when buildkit vertex is unknown (#2188)

* Improve tty error logging when buildkit vertex is unknown

Creates a generic "system" group in the tty output which captures
buildkit events that report a non-dagger vertex name. This happens
currently when using core.#Dockerfile actions since Dagger delegates the
LLB generation to buildkit through it's frontend and we don't get
meaningful events that we can correlate from Dagger's side

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
This commit is contained in:
Marcos Nils
2022-04-18 21:50:34 -03:00
committed by GitHub
parent 437f4517b6
commit 27d878456f
8 changed files with 163 additions and 87 deletions

View File

@@ -23,6 +23,8 @@ type PlainOutput struct {
Out io.Writer
}
const systemGroup = "system"
func (c *PlainOutput) Write(p []byte) (int, error) {
event := map[string]interface{}{}
d := json.NewDecoder(bytes.NewReader(p))
@@ -117,7 +119,7 @@ func formatMessage(event map[string]interface{}) string {
}
func parseSource(event map[string]interface{}) string {
source := "system"
source := systemGroup
if task, ok := event["task"].(string); ok && task != "" {
source = task
}

View File

@@ -43,8 +43,14 @@ func (l *Logs) Add(event Event) error {
l.l.Lock()
defer l.l.Unlock()
// same thing as in plain.go group all the non-identified tasks
// into a general group called system
source := systemGroup
taskPath, ok := event["task"].(string)
if !ok {
if ok && len(taskPath) > 0 {
source = taskPath
} else if !ok {
l.Messages = append(l.Messages, Message{
Event: event,
})
@@ -53,7 +59,7 @@ func (l *Logs) Add(event Event) error {
}
// Hide hidden fields (e.g. `._*`) from log group names
groupKey := strings.Split(taskPath, "._")[0]
groupKey := strings.Split(source, "._")[0]
group := l.groups[groupKey]
@@ -78,12 +84,20 @@ func (l *Logs) Add(event Event) error {
// For each task in a group, the status will transition from computing to complete, then back to computing and so on.
// The transition is fast enough not to cause a problem.
if st, ok := event["state"].(string); ok {
group.State = task.State(st)
if group.State == task.StateComputing {
group.Completed = nil
} else {
now := time.Now()
group.Completed = &now
if t, err := task.ParseState(st); err != nil {
return err
// concurrent "system" tasks are the only exception to transition
// from another state to failed since we need to show the error to
// the user
} else if group.State.CanTransition(t) ||
(group.Name == systemGroup && t == task.StateFailed) {
group.State = t
if group.State == task.StateComputing {
group.Completed = nil
} else {
now := time.Now()
group.Completed = &now
}
}
return nil
@@ -262,52 +276,57 @@ func (c *TTYOutput) printLine(w io.Writer, event Event, width int) int {
func (c *TTYOutput) printGroup(group *Group, width, maxLines int) int {
lineCount := 0
prefix := ""
switch group.State {
case task.StateComputing:
prefix = "[+]"
case task.StateCanceled:
prefix = "[✗]"
case task.StateFailed:
prefix = "[]"
case task.StateCompleted:
prefix = "[]"
var out string
// treat the "system" group as a special case as we don't
// want it to be displayed as an action in the output
if group.Name != systemGroup {
prefix := ""
switch group.State {
case task.StateComputing:
prefix = "[+]"
case task.StateCanceled:
prefix = "[]"
case task.StateFailed:
prefix = "[✗]"
case task.StateCompleted:
prefix = "[✔]"
}
out = prefix + " " + group.Name
endTime := time.Now()
if group.Completed != nil {
endTime = *group.Completed
}
dt := endTime.Sub(*group.Started).Seconds()
if dt < 0.05 {
dt = 0
}
timer := fmt.Sprintf("%3.1fs", dt)
// align
out += strings.Repeat(" ", width-utf8.RuneCountInString(out)-len(timer))
out += timer
out += "\n"
// color
switch group.State {
case task.StateComputing:
out = aec.Apply(out, aec.LightBlueF)
case task.StateCanceled:
out = aec.Apply(out, aec.LightYellowF)
case task.StateFailed:
out = aec.Apply(out, aec.LightRedF)
case task.StateCompleted:
out = aec.Apply(out, aec.LightGreenF)
}
// Print
fmt.Fprint(c.cons, out)
lineCount++
}
out := prefix + " " + group.Name
endTime := time.Now()
if group.Completed != nil {
endTime = *group.Completed
}
dt := endTime.Sub(*group.Started).Seconds()
if dt < 0.05 {
dt = 0
}
timer := fmt.Sprintf("%3.1fs", dt)
// align
out += strings.Repeat(" ", width-utf8.RuneCountInString(out)-len(timer))
out += timer
out += "\n"
// color
switch group.State {
case task.StateComputing:
out = aec.Apply(out, aec.LightBlueF)
case task.StateCanceled:
out = aec.Apply(out, aec.LightYellowF)
case task.StateFailed:
out = aec.Apply(out, aec.LightRedF)
case task.StateCompleted:
out = aec.Apply(out, aec.LightGreenF)
}
// Print
fmt.Fprint(c.cons, out)
lineCount++
printEvents := []Event{}
switch group.State {
case task.StateComputing: