-
Notifications
You must be signed in to change notification settings - Fork 889
feat(coderd): add parameter to force health check in /debug/health #10677
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 |
---|---|---|
|
@@ -41,16 +41,22 @@ func (api *API) debugTailnet(rw http.ResponseWriter, r *http.Request) { | |
// @Tags Debug | ||
// @Success 200 {object} healthcheck.Report | ||
// @Router /debug/health [get] | ||
// @Param force query boolean false "Force a healthcheck to run" | ||
func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) { | ||
apiKey := httpmw.APITokenFromRequest(r) | ||
ctx, cancel := context.WithTimeout(r.Context(), api.Options.HealthcheckTimeout) | ||
defer cancel() | ||
|
||
// Get cached report if it exists. | ||
if report := api.healthCheckCache.Load(); report != nil { | ||
if time.Since(report.Time) < api.Options.HealthcheckRefresh { | ||
formatHealthcheck(ctx, rw, r, report) | ||
return | ||
// 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 { | ||
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. Do we need an extra safety check to ensure that only 1 request is in-flight? 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 belive the healthcheck singleflight group should take care of that. |
||
if time.Since(report.Time) < api.Options.HealthcheckRefresh { | ||
formatHealthcheck(ctx, rw, r, report) | ||
return | ||
} | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
I get the invalidation concept, but if it does not take too much time, maybe we can also run the health check without caching?
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.
I think this is a pretty big 'if' :-)