Skip to content

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

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Dec 5, 2023

Previously we were making healthcheck sections as dismissed in the healthcheck function, the reuslt of which gets cached. This commit moves the logic outside of the function. It results in an extra database lookup on every call to healthcheck.

@johnstcn johnstcn requested review from mafredri and mtojek December 5, 2023 21:27
@johnstcn johnstcn self-assigned this Dec 5, 2023
@@ -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))
Copy link
Member Author

@johnstcn johnstcn Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review: drive-by: this was causing slog to panic

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: why?

Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking

@@ -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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: why?

hc.WorkspaceProxy.Dismissed = true
}
}

format := r.URL.Query().Get("format")
switch format {
case "text":
Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

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.

hc.WorkspaceProxy.Dismissed = true
}
}

format := r.URL.Query().Get("format")
switch format {
case "text":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not part of this PR: "simple" is not an available option?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the available formats were just json and text.

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) {
Copy link
Member

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.

Copy link
Member Author

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.

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 {
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

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.

@johnstcn
Copy link
Member Author

johnstcn commented Dec 6, 2023

out of curiosity: why?

I don't remember the exact complaint, but it was something about a context key value.
I didn't dig into it much further before changing to use slog.Err.

@johnstcn johnstcn merged commit 38ed816 into main Dec 6, 2023
@johnstcn johnstcn deleted the cj/dismiss-healthcheck-stale branch December 6, 2023 08:38
@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants