Provide yes man endpoint for inflexible load balancers
Certain load balancers, such as Amazon's Elastic Load Balancer, have a very limited notion of health. While a properly configured and operational registry should always return a 401 when hitting "/v2/", such load balancers cannot be configured to treat this response code as healthy. This changeset makes "/" always return a 200 response, unless the health checks have failed. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
77c6d9deb9
commit
74080b7225
1 changed files with 19 additions and 1 deletions
|
@ -72,8 +72,9 @@ func main() {
|
|||
app := handlers.NewApp(ctx, *config)
|
||||
app.RegisterHealthChecks()
|
||||
handler := configureReporting(app)
|
||||
handler = panicHandler(handler)
|
||||
handler = alive("/", handler)
|
||||
handler = health.Handler(handler)
|
||||
handler = panicHandler(handler)
|
||||
handler = gorhandlers.CombinedLoggingHandler(os.Stdout, handler)
|
||||
|
||||
if config.HTTP.Debug.Addr != "" {
|
||||
|
@ -313,3 +314,20 @@ func panicHandler(handler http.Handler) http.Handler {
|
|||
handler.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
// alive simply wraps the handler with a route that always returns an http 200
|
||||
// response when the path is matched. If the path is not matched, the request
|
||||
// is passed to the provided handler. There is no guarantee of anything but
|
||||
// that the server is up. Wrap with other handlers (such as health.Handler)
|
||||
// for greater affect.
|
||||
func alive(path string, handler http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path == path {
|
||||
w.Header().Set("Cache-Control", "no-cache")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
return
|
||||
}
|
||||
|
||||
handler.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue