mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix(coderd/debug): fix caching issue with dismissed sections (#11051)
This commit is contained in:
+33
-4
@@ -59,6 +59,11 @@ 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"
|
||||
|
||||
@@ -66,7 +71,7 @@ func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
|
||||
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 {
|
||||
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":
|
||||
@@ -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))
|
||||
}
|
||||
return dismissedHealthchecks
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user