2023-01-25 21:27:36 +00:00
|
|
|
package coderd
|
|
|
|
|
2023-04-03 06:28:42 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/coder/coder/coderd/healthcheck"
|
|
|
|
"github.com/coder/coder/coderd/httpapi"
|
2023-05-30 19:22:32 +00:00
|
|
|
"github.com/coder/coder/coderd/httpmw"
|
2023-04-03 06:28:42 +00:00
|
|
|
"github.com/coder/coder/codersdk"
|
|
|
|
)
|
2023-01-25 21:27:36 +00:00
|
|
|
|
|
|
|
// @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)
|
|
|
|
}
|
2023-04-03 06:28:42 +00:00
|
|
|
|
|
|
|
// @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) {
|
2023-05-30 19:22:32 +00:00
|
|
|
apiKey := httpmw.APITokenFromRequest(r)
|
2023-04-03 06:28:42 +00:00
|
|
|
ctx, cancel := context.WithTimeout(r.Context(), api.HealthcheckTimeout)
|
|
|
|
defer cancel()
|
|
|
|
|
2023-05-30 19:22:32 +00:00
|
|
|
// Get cached report if it exists.
|
|
|
|
if report := api.healthCheckCache.Load(); report != nil {
|
|
|
|
if time.Since(report.Time) < api.HealthcheckRefresh {
|
2023-05-30 21:59:39 +00:00
|
|
|
httpapi.WriteIndent(ctx, rw, http.StatusOK, report)
|
2023-05-30 19:22:32 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-03 06:28:42 +00:00
|
|
|
resChan := api.healthCheckGroup.DoChan("", func() (*healthcheck.Report, error) {
|
2023-05-30 19:22:32 +00:00
|
|
|
// Create a new context not tied to the request.
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), api.HealthcheckTimeout)
|
|
|
|
defer cancel()
|
|
|
|
|
2023-06-02 00:21:24 +00:00
|
|
|
report := api.HealthcheckFunc(ctx, apiKey)
|
|
|
|
api.healthCheckCache.Store(report)
|
|
|
|
return report, nil
|
2023-04-03 06:28:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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:
|
2023-05-30 21:59:39 +00:00
|
|
|
httpapi.WriteIndent(ctx, rw, http.StatusOK, res.Val)
|
2023-04-03 06:28:42 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2023-05-30 19:22:32 +00:00
|
|
|
|
|
|
|
// For some reason the swagger docs need to be attached to a function.
|
|
|
|
//
|
|
|
|
// @Summary Debug Info Websocket Test
|
|
|
|
// @ID debug-info-websocket-test
|
|
|
|
// @Security CoderSessionToken
|
|
|
|
// @Produce json
|
|
|
|
// @Tags Debug
|
|
|
|
// @Success 201 {object} codersdk.Response
|
|
|
|
// @Router /debug/ws [get]
|
|
|
|
// @x-apidocgen {"skip": true}
|
|
|
|
func _debugws(http.ResponseWriter, *http.Request) {} //nolint:unused
|