Add health check endpoint

Fix https://github.com/matrix-org/dendrite/issues/1668
This commit is contained in:
Eric Eastwood 2020-12-18 02:06:52 -06:00
parent e1ace7e44a
commit a8e947e93d

View file

@ -26,6 +26,7 @@ import (
"github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/httputil"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
"github.com/prometheus/client_golang/prometheus/promhttp"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
@ -311,6 +312,17 @@ func (b *BaseDendrite) SetupAndServeHTTP(
}
}
externalRouter.Handle("/health",
httputil.MakeExternalAPI("health", func(req *http.Request) util.JSONResponse {
return util.JSONResponse{
Code: http.StatusOK,
JSON: struct {
Versions bool `json:"success"`
}{true},
}
}),
).Methods(http.MethodGet)
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
if b.Cfg.Global.Metrics.Enabled {
internalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), b.Cfg.Global.Metrics.BasicAuth))