-
Notifications
You must be signed in to change notification settings - Fork 86
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
ssa: Improve wait error reporting #722
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package ssa | |
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
@@ -83,7 +84,6 @@ func (m *ResourceManager) WaitForSet(set object.ObjMetadataSet, opts WaitOptions | |
eventsChan := m.poller.Poll(ctx, set, pollingOpts) | ||
|
||
lastStatus := make(map[object.ObjMetadata]*event.ResourceStatus) | ||
var failedResources int | ||
|
||
done := statusCollector.ListenWithObserver(eventsChan, collector.ObserverFunc( | ||
func(statusCollector *collector.ResourceStatusCollector, e event.Event) { | ||
|
@@ -96,7 +96,7 @@ func (m *ResourceManager) WaitForSet(set object.ObjMetadataSet, opts WaitOptions | |
// skip DeadlineExceeded errors because kstatus emits that error | ||
// for every resource it's monitoring even when only one of them | ||
// actually fails. | ||
if rs.Error != context.DeadlineExceeded { | ||
if !errors.Is(rs.Error, context.DeadlineExceeded) { | ||
lastStatus[rs.Identifier] = rs | ||
} | ||
|
||
|
@@ -105,7 +105,6 @@ func (m *ResourceManager) WaitForSet(set object.ObjMetadataSet, opts WaitOptions | |
} | ||
rss = append(rss, rs) | ||
} | ||
failedResources = countFailed | ||
|
||
desired := status.CurrentStatus | ||
aggStatus := aggregator.AggregateStatus(rss, desired) | ||
|
@@ -122,32 +121,36 @@ func (m *ResourceManager) WaitForSet(set object.ObjMetadataSet, opts WaitOptions | |
return statusCollector.Error | ||
} | ||
|
||
if ctx.Err() == context.DeadlineExceeded || (opts.FailFast && failedResources > 0) { | ||
msg := "failed early due to stalled resources" | ||
if ctx.Err() == context.DeadlineExceeded { | ||
msg = "timeout waiting for" | ||
} | ||
|
||
var errors = []string{} | ||
for id, rs := range statusCollector.ResourceStatuses { | ||
if rs == nil { | ||
errors = append(errors, fmt.Sprintf("can't determine status for %s", utils.FmtObjMetadata(id))) | ||
continue | ||
var errs []string | ||
for id, rs := range statusCollector.ResourceStatuses { | ||
switch { | ||
case rs == nil || lastStatus[id] == nil: | ||
errs = append(errs, fmt.Sprintf("can't determine status for %s", utils.FmtObjMetadata(id))) | ||
case lastStatus[id].Status == status.FailedStatus: | ||
var builder strings.Builder | ||
builder.WriteString(fmt.Sprintf("%s status: '%s'", | ||
utils.FmtObjMetadata(rs.Identifier), lastStatus[id].Status)) | ||
if rs.Error != nil { | ||
builder.WriteString(fmt.Sprintf(": %s", rs.Error)) | ||
} | ||
if lastStatus[id] == nil { | ||
// this is only nil in the rare case where no status can be determined for the resource at all | ||
errors = append(errors, fmt.Sprintf("%s (unknown status)", utils.FmtObjMetadata(rs.Identifier))) | ||
} else if lastStatus[id].Status != status.CurrentStatus { | ||
var builder strings.Builder | ||
builder.WriteString(fmt.Sprintf("%s status: '%s'", | ||
utils.FmtObjMetadata(rs.Identifier), lastStatus[id].Status)) | ||
if rs.Error != nil { | ||
builder.WriteString(fmt.Sprintf(": %s", rs.Error)) | ||
} | ||
errors = append(errors, builder.String()) | ||
errs = append(errs, builder.String()) | ||
case errors.Is(ctx.Err(), context.DeadlineExceeded) && lastStatus[id].Status != status.CurrentStatus: | ||
var builder strings.Builder | ||
builder.WriteString(fmt.Sprintf("%s status: '%s'", | ||
utils.FmtObjMetadata(rs.Identifier), lastStatus[id].Status)) | ||
if rs.Error != nil { | ||
builder.WriteString(fmt.Sprintf(": %s", rs.Error)) | ||
Comment on lines
+129
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to ignore it but the two cases above seem identical. case (lastStatus[id].Status == status.FailedStatus) || (errors.Is(ctx.Err(), context.DeadlineExceeded) && lastStatus[id].Status != status.CurrentStatus):
... I may be missing something if they aren't identical. Please tell me if they aren't. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did like this so it's easier to read, failure vs timeout. |
||
} | ||
errs = append(errs, builder.String()) | ||
} | ||
} | ||
|
||
if len(errs) > 0 { | ||
msg := "failed early due to stalled resources" | ||
if errors.Is(ctx.Err(), context.DeadlineExceeded) { | ||
msg = "timeout waiting for" | ||
} | ||
return fmt.Errorf("%s: [%s]", msg, strings.Join(errors, ", ")) | ||
return fmt.Errorf("%s: [%s]", msg, strings.Join(errs, ", ")) | ||
} | ||
|
||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wdyt think about
Wrapping the
errors
can make it easier to inspect for calling funtions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is more about humans than code, keep in mind that the resulting error ends up in Slack, PagerDuty, etc. Is error wrapping with 100+ errors easier to read and parse than an array?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.Error()
will return a string still. The difference is that forJoin
. It saysThe error formats as the concatenation of the strings obtained by calling the Error method of each element of errs, with a newline between each string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok but this will change the format and if people rely on the current array, their parser will fail. I would consider change it in Flux minor release instead of a patch like now.