MCPcopy Index your code
hub / github.com/coder/coder / debugDeploymentHealth

Method debugDeploymentHealth

coderd/debug.go:65–122  ·  view source on GitHub ↗

@Summary Debug Info Deployment Health @ID debug-info-deployment-health @Security CoderSessionToken @Produce json @Tags Debug @Success 200 {object} healthsdk.HealthcheckReport @Router /api/v2/debug/health [get] @Param force query boolean false "Force a healthcheck to run"

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

63// @Router /api/v2/debug/health [get]
64// @Param force query boolean false "Force a healthcheck to run"
65func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
66 apiKey := httpmw.APITokenFromRequest(r)
67 ctx, cancel := context.WithTimeout(r.Context(), api.Options.HealthcheckTimeout)
68 defer cancel()
69
70 // Load sections previously marked as dismissed.
71 // We hydrate this here as we cache the healthcheck and hydrating in the
72 // healthcheck function itself can lead to stale results.
73 dismissed := loadDismissedHealthchecks(ctx, api.Database, api.Logger)
74
75 // Check if the forced query parameter is set.
76 forced := r.URL.Query().Get("force") == "true"
77
78 // Get cached report if it exists and the requester did not force a refresh.
79 if !forced {
80 if report := api.healthCheckCache.Load(); report != nil {
81 if time.Since(report.Time) < api.Options.HealthcheckRefresh {
82 formatHealthcheck(ctx, rw, r, *report, dismissed...)
83 return
84 }
85 }
86 }
87
88 resChan := api.healthCheckGroup.DoChan("", func() (*healthsdk.HealthcheckReport, error) {
89 // Create a new context not tied to the request.
90 ctx, cancel := context.WithTimeout(context.Background(), api.Options.HealthcheckTimeout)
91 defer cancel()
92
93 // Create and store progress tracker for timeout diagnostics.
94 report := api.HealthcheckFunc(ctx, apiKey, &api.healthCheckProgress)
95 if report != nil { // Only store non-nil reports.
96 api.healthCheckCache.Store(report)
97 }
98 api.healthCheckProgress.Reset()
99 return report, nil
100 })
101
102 select {
103 case <-ctx.Done():
104 summary := api.healthCheckProgress.Summary()
105 httpapi.Write(ctx, rw, http.StatusServiceUnavailable, codersdk.Response{
106 Message: "Healthcheck timed out.",
107 Detail: summary,
108 })
109 return
110 case res := <-resChan:
111 report := res.Val
112 if report == nil {
113 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
114 Message: "There was an unknown error completing the healthcheck.",
115 Detail: "nil report from healthcheck result channel",
116 })
117 return
118 }
119 formatHealthcheck(ctx, rw, r, *report, dismissed...)
120 return
121 }
122}

Callers

nothing calls this directly

Calls 11

APITokenFromRequestFunction · 0.92
WriteFunction · 0.92
formatHealthcheckFunction · 0.85
SummaryMethod · 0.80
ContextMethod · 0.65
GetMethod · 0.65
ResetMethod · 0.65
LoadMethod · 0.45
StoreMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected