-
Notifications
You must be signed in to change notification settings - Fork 608
/
debug.go
55 lines (48 loc) · 1.43 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package coderd
import (
"context"
"net/http"
"time"
"github.com/coder/coder/coderd/healthcheck"
"github.com/coder/coder/coderd/httpapi"
"github.com/coder/coder/codersdk"
)
// @Summary Debug Info Wireguard Coordinator
// @ID debug-info-wireguard-coordinator
// @Security CoderSessionToken
// @Produce text/html
// @Tags Debug
// @Success 200
// @Router /debug/coordinator [get]
func (api *API) debugCoordinator(rw http.ResponseWriter, r *http.Request) {
(*api.TailnetCoordinator.Load()).ServeHTTPDebug(rw, r)
}
// @Summary Debug Info Deployment Health
// @ID debug-info-deployment-health
// @Security CoderSessionToken
// @Produce json
// @Tags Debug
// @Success 200 {object} healthcheck.Report
// @Router /debug/health [get]
func (api *API) debugDeploymentHealth(rw http.ResponseWriter, r *http.Request) {
ctx, cancel := context.WithTimeout(r.Context(), api.HealthcheckTimeout)
defer cancel()
resChan := api.healthCheckGroup.DoChan("", func() (*healthcheck.Report, error) {
return api.HealthcheckFunc(ctx)
})
select {
case <-ctx.Done():
httpapi.Write(ctx, rw, http.StatusNotFound, codersdk.Response{
Message: "Healthcheck is in progress and did not complete in time. Try again in a few seconds.",
})
return
case res := <-resChan:
if time.Since(res.Val.Time) > api.HealthcheckRefresh {
api.healthCheckGroup.Forget("")
api.debugDeploymentHealth(rw, r)
return
}
httpapi.Write(ctx, rw, http.StatusOK, res.Val)
return
}
}