-
Notifications
You must be signed in to change notification settings - Fork 936
fix(coderd/debug): fix caching issue with dismissed sections #11051
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,14 +59,19 @@ func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) { | |
ctx, cancel := context.WithTimeout(r.Context(), api.Options.HealthcheckTimeout) | ||
defer cancel() | ||
|
||
// Load sections previously marked as dismissed. | ||
// We hydrate this here as we cache the healthcheck and hydrating in the | ||
// healthcheck function itself can lead to stale results. | ||
dismissed := loadDismissedHealthchecks(ctx, api.Database, api.Logger) | ||
|
||
// Check if the forced query parameter is set. | ||
forced := r.URL.Query().Get("force") == "true" | ||
|
||
// Get cached report if it exists and the requester did not force a refresh. | ||
if !forced { | ||
if report := api.healthCheckCache.Load(); report != nil { | ||
if time.Since(report.Time) < api.Options.HealthcheckRefresh { | ||
formatHealthcheck(ctx, rw, r, report) | ||
formatHealthcheck(ctx, rw, r, *report, dismissed...) | ||
return | ||
} | ||
} | ||
|
@@ -89,12 +94,36 @@ func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) { | |
}) | ||
return | ||
case res := <-resChan: | ||
formatHealthcheck(ctx, rw, r, res.Val) | ||
report := res.Val | ||
if report == nil { | ||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ | ||
Message: "There was an unknown error completing the healthcheck.", | ||
Detail: "nil report from healthcheck result channel", | ||
}) | ||
return | ||
} | ||
formatHealthcheck(ctx, rw, r, *report, dismissed...) | ||
return | ||
} | ||
} | ||
|
||
func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc *healthcheck.Report) { | ||
func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthcheck.Report, dismissed ...codersdk.HealthSection) { | ||
// Mark any sections previously marked as dismissed. | ||
for _, d := range dismissed { | ||
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'm afraid that somebody may forget to extend this switch in the future. Maybe we should move the logic to codersdk, closer to Healthcheck report? 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. Will address in a follow-up. |
||
switch d { | ||
case codersdk.HealthSectionAccessURL: | ||
hc.AccessURL.Dismissed = true | ||
case codersdk.HealthSectionDERP: | ||
hc.DERP.Dismissed = true | ||
case codersdk.HealthSectionDatabase: | ||
hc.Database.Dismissed = true | ||
case codersdk.HealthSectionWebsocket: | ||
hc.Websocket.Dismissed = true | ||
case codersdk.HealthSectionWorkspaceProxy: | ||
hc.WorkspaceProxy.Dismissed = true | ||
} | ||
} | ||
|
||
format := r.URL.Query().Get("format") | ||
switch format { | ||
case "text": | ||
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. not part of this PR: we could update it to use severity + dismissed as well. 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. Will address in a follow-up. 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. not part of this PR: "simple" is not an available option? 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 thought the available formats were just |
||
|
@@ -269,7 +298,7 @@ func loadDismissedHealthchecks(ctx context.Context, db database.Store, logger sl | |
} | ||
} | ||
if err != nil && !xerrors.Is(err, sql.ErrNoRows) { | ||
logger.Error(ctx, "unable to fetch health settings: %w", err) | ||
logger.Error(ctx, "unable to fetch health settings", slog.Error(err)) | ||
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. review: drive-by: this was causing slog to panic 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. out of curiosity: why? |
||
} | ||
return dismissedHealthchecks | ||
} |
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.
nit: if you have switch to go over a finite number of sections, this does not have to be varags.
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.
Will address in a follow-up.