-
Notifications
You must be signed in to change notification settings - Fork 936
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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"` | ||
|
||
ProvisionerDaemons []codersdk.ProvisionerDaemon `json:"provisioner_daemons"` | ||
Items []ProvisionerDaemonsReportItem `json:"items"` | ||
} | ||
|
||
// @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.ProvisionerDaemons = make([]codersdk.ProvisionerDaemon, 0) | ||
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 | ||
} | ||
|
||
r.ProvisionerDaemons = append(r.ProvisionerDaemons, db2sdk.ProvisionerDaemon(daemon)) | ||
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, "Provisioner daemon %q reports invalid version %q", opts.CurrentVersion, daemon.Version)) | ||
r.Warnings = append(r.Warnings, health.Messagef(health.CodeUnknown, "Some provisioner daemons report invalid version information.")) | ||
johnstcn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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, "Provisioner daemon %q has outdated version %q", daemon.Name, daemon.Version)) | ||
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, "Provisioner daemon %q reports invalid API version: %s", daemon.Name, err.Error())) | ||
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, "Provisioner daemon %q reports deprecated major API version %d. Consider upgrading!", daemon.Name, provisionersdk.CurrentMajor)) | ||
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.ProvisionerDaemons) == 0 { | ||
if len(r.Items) == 0 { | ||
r.Severity = health.SeverityError | ||
r.Error = ptr.Ref("No active provisioner daemons found!") | ||
return | ||
|
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.
In theory, this is API breaking, right?
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.
Yeah in theory, but the modifications were only merged this morning :-)