From 3bf4812017e4b948e8603534c1ad0d961c7f5d44 Mon Sep 17 00:00:00 2001 From: Barak Amar Date: Wed, 25 Nov 2020 20:28:51 +0200 Subject: [PATCH 1/2] return installation as part of health check information --- api/handler.go | 2 +- cmd/lakefs/cmd/run.go | 2 ++ httputil/endpoints.go | 17 ++++++++++++----- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/api/handler.go b/api/handler.go index ea33b38b243..7d52efa1cae 100644 --- a/api/handler.go +++ b/api/handler.go @@ -145,7 +145,7 @@ func (s *Handler) BasicAuth() func(accessKey, secretKey string) (user *models.Us func (s *Handler) setupHandler(api http.Handler, ui http.Handler) { mux := http.NewServeMux() // health check - mux.Handle("/_health", httputil.ServeHealth()) + mux.Handle("/_health", http.HandlerFunc(httputil.HealthHandler)) // metrics mux.Handle("/metrics", promhttp.Handler()) // pprof endpoint diff --git a/cmd/lakefs/cmd/run.go b/cmd/lakefs/cmd/run.go index 917d6fad550..ca6aa3c498d 100644 --- a/cmd/lakefs/cmd/run.go +++ b/cmd/lakefs/cmd/run.go @@ -88,6 +88,8 @@ var runCmd = &cobra.Command{ bufferedCollector := stats.NewBufferedCollector(metadata.InstallationID, cfg) // send metadata bufferedCollector.CollectMetadata(metadata) + // update health info with installation ID + httputil.SetHealthHandlerInfo(metadata.InstallationID) dedupCleaner := dedup.NewCleaner(blockStore, cataloger.DedupReportChannel()) diff --git a/httputil/endpoints.go b/httputil/endpoints.go index a523bb0cbf3..471f5b1b505 100644 --- a/httputil/endpoints.go +++ b/httputil/endpoints.go @@ -1,16 +1,23 @@ package httputil import ( + "io" "net/http" "net/http/pprof" "strings" ) -func ServeHealth() http.Handler { - return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { - writer.WriteHeader(http.StatusOK) - _, _ = writer.Write([]byte("alive!")) - }) +var healthInfo string + +func SetHealthHandlerInfo(info string) { + healthInfo = info +} + +func HealthHandler(w http.ResponseWriter, r *http.Request) { + _, _ = io.WriteString(w, "alive!") + if healthInfo != "" { + _, _ = io.WriteString(w, " "+healthInfo) + } } func ServePPROF(pprofPrefix string) http.Handler { From f4216c27623639dd1707c012dc3d64f6056157e1 Mon Sep 17 00:00:00 2001 From: Barak Amar Date: Wed, 25 Nov 2020 20:52:33 +0200 Subject: [PATCH 2/2] revert ServeHealth --- api/handler.go | 2 +- httputil/endpoints.go | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/api/handler.go b/api/handler.go index 7d52efa1cae..ea33b38b243 100644 --- a/api/handler.go +++ b/api/handler.go @@ -145,7 +145,7 @@ func (s *Handler) BasicAuth() func(accessKey, secretKey string) (user *models.Us func (s *Handler) setupHandler(api http.Handler, ui http.Handler) { mux := http.NewServeMux() // health check - mux.Handle("/_health", http.HandlerFunc(httputil.HealthHandler)) + mux.Handle("/_health", httputil.ServeHealth()) // metrics mux.Handle("/metrics", promhttp.Handler()) // pprof endpoint diff --git a/httputil/endpoints.go b/httputil/endpoints.go index 471f5b1b505..f7983d64e56 100644 --- a/httputil/endpoints.go +++ b/httputil/endpoints.go @@ -13,11 +13,13 @@ func SetHealthHandlerInfo(info string) { healthInfo = info } -func HealthHandler(w http.ResponseWriter, r *http.Request) { - _, _ = io.WriteString(w, "alive!") - if healthInfo != "" { - _, _ = io.WriteString(w, " "+healthInfo) - } +func ServeHealth() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + _, _ = io.WriteString(w, "alive!") + if healthInfo != "" { + _, _ = io.WriteString(w, " "+healthInfo) + } + }) } func ServePPROF(pprofPrefix string) http.Handler {