- Notifications
You must be signed in to change notification settings - Fork1k
fix(coderd/healthcheck): add daemon-specific warnings to healthcheck output#11490
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,6 +2,7 @@ package healthcheck | ||
import ( | ||
"context" | ||
"sort" | ||
"time" | ||
"golang.org/x/mod/semver" | ||
@@ -26,7 +27,13 @@ type ProvisionerDaemonsReport struct { | ||
Dismissed bool `json:"dismissed"` | ||
Error *string `json:"error"` | ||
Items []ProvisionerDaemonsReportItem `json:"items"` | ||
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. In theory, this is API breaking, right? 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. Yeah in theory, but the modifications were only merged this morning :-) | ||
} | ||
// @typescript-generate ProvisionerDaemonsReportItem | ||
type ProvisionerDaemonsReportItem struct { | ||
codersdk.ProvisionerDaemon `json:"provisioner_daemon"` | ||
Warnings []health.Message `json:"warnings"` | ||
} | ||
type ProvisionerDaemonsReportDeps struct { | ||
@@ -47,7 +54,7 @@ type ProvisionerDaemonsStore interface { | ||
} | ||
func (r *ProvisionerDaemonsReport) Run(ctx context.Context, opts *ProvisionerDaemonsReportDeps) { | ||
r.Items = make([]ProvisionerDaemonsReportItem, 0) | ||
r.Severity = health.SeverityOK | ||
r.Warnings = make([]health.Message, 0) | ||
r.Dismissed = opts.Dismissed | ||
@@ -86,6 +93,12 @@ func (r *ProvisionerDaemonsReport) Run(ctx context.Context, opts *ProvisionerDae | ||
r.Error = ptr.Ref("error fetching provisioner daemons: " + err.Error()) | ||
return | ||
} | ||
// Ensure stable order for display and for tests | ||
sort.Slice(daemons, func(i, j int) bool { | ||
return daemons[i].Name < daemons[j].Name | ||
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. doublecheck: we don't need to sort by other fields? There is no way that the report will contain old entries for provisioners with the same name? 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. The database schema requires each provisioner daemon to have a unique name. | ||
}) | ||
for _, daemon := range daemons { | ||
// Daemon never connected, skip. | ||
if !daemon.LastSeenAt.Valid { | ||
@@ -96,19 +109,24 @@ func (r *ProvisionerDaemonsReport) Run(ctx context.Context, opts *ProvisionerDae | ||
continue | ||
} | ||
it := ProvisionerDaemonsReportItem{ | ||
ProvisionerDaemon: db2sdk.ProvisionerDaemon(daemon), | ||
Warnings: make([]health.Message, 0), | ||
} | ||
// For release versions, just check MAJOR.MINOR and ignore patch. | ||
if !semver.IsValid(daemon.Version) { | ||
if r.Severity.Value() < health.SeverityError.Value() { | ||
r.Severity = health.SeverityError | ||
} | ||
r.Warnings = append(r.Warnings, health.Messagef(health.CodeUnknown, "Some provisioner daemons report invalid version information.")) | ||
johnstcn marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
it.Warnings = append(it.Warnings, health.Messagef(health.CodeUnknown, "Invalid version %q", daemon.Version)) | ||
} else if !buildinfo.VersionsMatch(opts.CurrentVersion, daemon.Version) { | ||
if r.Severity.Value() < health.SeverityWarning.Value() { | ||
r.Severity = health.SeverityWarning | ||
} | ||
r.Warnings = append(r.Warnings, health.Messagef(health.CodeProvisionerDaemonVersionMismatch, "Some provisioner daemons report mismatched versions.")) | ||
it.Warnings = append(it.Warnings, health.Messagef(health.CodeProvisionerDaemonVersionMismatch, "Mismatched version %q", daemon.Version)) | ||
} | ||
// Provisioner daemon API version follows different rules; we just want to check the major API version and | ||
@@ -119,16 +137,20 @@ func (r *ProvisionerDaemonsReport) Run(ctx context.Context, opts *ProvisionerDae | ||
if r.Severity.Value() < health.SeverityError.Value() { | ||
r.Severity = health.SeverityError | ||
} | ||
r.Warnings = append(r.Warnings, health.Messagef(health.CodeUnknown, "Some provisioner daemons report invalid API version information.")) | ||
it.Warnings = append(it.Warnings, health.Messagef(health.CodeUnknown, "Invalid API version: %s", err.Error())) // contains version string | ||
} else if maj != opts.CurrentAPIMajorVersion { | ||
if r.Severity.Value() < health.SeverityWarning.Value() { | ||
r.Severity = health.SeverityWarning | ||
} | ||
r.Warnings = append(r.Warnings, health.Messagef(health.CodeProvisionerDaemonAPIMajorVersionDeprecated, "Some provisioner daemons report deprecated major API versions. Consider upgrading!")) | ||
it.Warnings = append(it.Warnings, health.Messagef(health.CodeProvisionerDaemonAPIMajorVersionDeprecated, "Deprecated major API version %d.", provisionersdk.CurrentMajor)) | ||
} | ||
r.Items = append(r.Items, it) | ||
} | ||
if len(r.Items) == 0 { | ||
r.Severity = health.SeverityError | ||
r.Error = ptr.Ref("No active provisioner daemons found!") | ||
return | ||
Uh oh!
There was an error while loading.Please reload this page.