From 5a79212b322fc5686806787b7fc04c0fcaa7ff1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 19 Mar 2021 15:04:01 +0100 Subject: [PATCH] add healthcheck. --- Dockerfile | 5 +++++ internal/api/router.go | 5 +++++ internal/http/logger.go | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/Dockerfile b/Dockerfile index 77c85932..96000a7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -110,6 +110,11 @@ ENV NEKO_SERVER_BIND=:8080 # copy executabe from previous stage COPY --from=build /src/bin/neko /usr/bin/neko +# +# add healthcheck +HEALTHCHECK --interval=10s --timeout=5s --retries=8 \ + CMD wget -O - http://localhost:${NEKO_SERVER_BIND#*:}/api/health || exit 1 + # # run neko CMD ["/usr/bin/supervisord", "-c", "/etc/neko/supervisord.conf"] diff --git a/internal/api/router.go b/internal/api/router.go index 84a7b377..477e94da 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -58,6 +58,11 @@ func (api *ApiManagerCtx) Route(r chi.Router) { r.Route(path, router) } }) + + r.Get("/health", func(w http.ResponseWriter, r *http.Request) { + //nolint + w.Write([]byte("true")) + }) } func (api *ApiManagerCtx) Authenticate(next http.Handler) http.Handler { diff --git a/internal/http/logger.go b/internal/http/logger.go index dabffea1..419be2a7 100644 --- a/internal/http/logger.go +++ b/internal/http/logger.go @@ -13,6 +13,12 @@ func Logger(next http.Handler) http.Handler { fn := func(w http.ResponseWriter, r *http.Request) { req := map[string]interface{}{} + // exclude healthcheck from logs + if r.RequestURI == "/api/health" { + next.ServeHTTP(w, r) + return + } + if reqID := middleware.GetReqID(r.Context()); reqID != "" { req["id"] = reqID }