mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-17 19:09:11 +03:00
internal: rework liveness probe and proxy (#19312)
Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
@@ -63,7 +63,11 @@ func (ws *WebServer) configureProxy() {
|
||||
rp.ErrorHandler = ws.proxyErrorHandler
|
||||
rp.ModifyResponse = ws.proxyModifyResponse
|
||||
ws.mainRouter.PathPrefix(config.Get().Web.Path).Path("/-/health/live/").HandlerFunc(sentry.SentryNoSample(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.WriteHeader(200)
|
||||
if ws.upstreamHealthcheck() {
|
||||
rw.WriteHeader(200)
|
||||
} else {
|
||||
rw.WriteHeader(502)
|
||||
}
|
||||
}))
|
||||
ws.mainRouter.PathPrefix(config.Get().Web.Path).HandlerFunc(sentry.SentryNoSample(func(rw http.ResponseWriter, r *http.Request) {
|
||||
if !ws.g.IsRunning() {
|
||||
|
||||
+16
-12
@@ -97,23 +97,27 @@ func NewWebServer() *WebServer {
|
||||
if sp := config.Get().Web.Path; sp != "/" {
|
||||
ws.mainRouter.Path("/").Handler(http.RedirectHandler(sp, http.StatusFound))
|
||||
}
|
||||
hcUrl := fmt.Sprintf("%s%s-/health/live/", ws.upstreamURL.String(), config.Get().Web.Path)
|
||||
ws.g = gounicorn.New(func() bool {
|
||||
req, err := http.NewRequest(http.MethodGet, hcUrl, nil)
|
||||
if err != nil {
|
||||
ws.log.WithError(err).Warning("failed to create request for healthcheck")
|
||||
return false
|
||||
}
|
||||
req.Header.Set("User-Agent", "goauthentik.io/router/healthcheck")
|
||||
res, err := ws.upstreamHttpClient().Do(req)
|
||||
if err == nil && res.StatusCode >= 200 && res.StatusCode < 300 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
return ws.upstreamHealthcheck()
|
||||
})
|
||||
return ws
|
||||
}
|
||||
|
||||
func (ws *WebServer) upstreamHealthcheck() bool {
|
||||
hcUrl := fmt.Sprintf("%s%s-/health/live/", ws.upstreamURL.String(), config.Get().Web.Path)
|
||||
req, err := http.NewRequest(http.MethodGet, hcUrl, nil)
|
||||
if err != nil {
|
||||
ws.log.WithError(err).Warning("failed to create request for healthcheck")
|
||||
return false
|
||||
}
|
||||
req.Header.Set("User-Agent", "goauthentik.io/router/healthcheck")
|
||||
res, err := ws.upstreamHttpClient().Do(req)
|
||||
if err == nil && res.StatusCode >= 200 && res.StatusCode < 300 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (ws *WebServer) prepareKeys() {
|
||||
tmp := os.TempDir()
|
||||
key := base64.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(64))
|
||||
|
||||
Reference in New Issue
Block a user