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

Function formatHealthcheck

coderd/debug.go:124–163  ·  view source on GitHub ↗
(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthsdk.HealthcheckReport, dismissed ...healthsdk.HealthSection)

Source from the content-addressed store, hash-verified

122}
123
124func formatHealthcheck(ctx context.Context, rw http.ResponseWriter, r *http.Request, hc healthsdk.HealthcheckReport, dismissed ...healthsdk.HealthSection) {
125 // Mark any sections previously marked as dismissed.
126 for _, d := range dismissed {
127 switch d {
128 case healthsdk.HealthSectionAccessURL:
129 hc.AccessURL.Dismissed = true
130 case healthsdk.HealthSectionDERP:
131 hc.DERP.Dismissed = true
132 case healthsdk.HealthSectionDatabase:
133 hc.Database.Dismissed = true
134 case healthsdk.HealthSectionWebsocket:
135 hc.Websocket.Dismissed = true
136 case healthsdk.HealthSectionWorkspaceProxy:
137 hc.WorkspaceProxy.Dismissed = true
138 }
139 }
140
141 format := r.URL.Query().Get("format")
142 switch format {
143 case "text":
144 rw.Header().Set("Content-Type", "text/plain; charset=utf-8")
145 rw.WriteHeader(http.StatusOK)
146
147 _, _ = fmt.Fprintln(rw, "time:", hc.Time.Format(time.RFC3339))
148 _, _ = fmt.Fprintln(rw, "healthy:", hc.Healthy)
149 _, _ = fmt.Fprintln(rw, "derp:", hc.DERP.Healthy)
150 _, _ = fmt.Fprintln(rw, "access_url:", hc.AccessURL.Healthy)
151 _, _ = fmt.Fprintln(rw, "websocket:", hc.Websocket.Healthy)
152 _, _ = fmt.Fprintln(rw, "database:", hc.Database.Healthy)
153
154 case "", "json":
155 httpapi.WriteIndent(ctx, rw, http.StatusOK, hc)
156
157 default:
158 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
159 Message: fmt.Sprintf("Invalid format option %q.", format),
160 Detail: "Allowed values are: \"json\", \"simple\".",
161 })
162 }
163}
164
165// @Summary Get health settings
166// @ID get-health-settings

Callers 1

debugDeploymentHealthMethod · 0.85

Calls 7

WriteIndentFunction · 0.92
WriteFunction · 0.92
GetMethod · 0.65
SetMethod · 0.65
FormatMethod · 0.65
HeaderMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected