From 4e9ea1e628a4d2105a758d12673efdeebe43ebaa Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Wed, 17 Jan 2024 20:46:37 +0500 Subject: [PATCH] chore: filer healthz handler check filer store (#5208) --- weed/server/filer_server.go | 1 + weed/server/filer_server_handlers.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/weed/server/filer_server.go b/weed/server/filer_server.go index d8b2ad8dc..a04fd1910 100644 --- a/weed/server/filer_server.go +++ b/weed/server/filer_server.go @@ -171,6 +171,7 @@ func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption) } if defaultMux != readonlyMux { handleStaticResources(readonlyMux) + readonlyMux.HandleFunc("/healthz", fs.filerHealthzHandler) readonlyMux.HandleFunc("/", fs.readonlyFilerHandler) } diff --git a/weed/server/filer_server_handlers.go b/weed/server/filer_server_handlers.go index c1b883f38..b5e070fb2 100644 --- a/weed/server/filer_server_handlers.go +++ b/weed/server/filer_server_handlers.go @@ -1,6 +1,7 @@ package weed_server import ( + "context" "errors" "net/http" "os" @@ -9,7 +10,9 @@ import ( "sync/atomic" "time" + "github.com/seaweedfs/seaweedfs/weed/filer" "github.com/seaweedfs/seaweedfs/weed/glog" + "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" "github.com/seaweedfs/seaweedfs/weed/security" "github.com/seaweedfs/seaweedfs/weed/util" @@ -220,5 +223,10 @@ func (fs *FilerServer) maybeCheckJwtAuthorization(r *http.Request, isWrite bool) func (fs *FilerServer) filerHealthzHandler(w http.ResponseWriter, r *http.Request) { w.Header().Set("Server", "SeaweedFS Filer "+util.VERSION) - w.WriteHeader(http.StatusOK) + if _, err := fs.filer.Store.FindEntry(context.Background(), filer.TopicsDir); err != nil && err != filer_pb.ErrNotFound { + glog.Warningf("filerHealthzHandler FindEntry: %+v", err) + w.WriteHeader(http.StatusServiceUnavailable) + } else { + w.WriteHeader(http.StatusOK) + } }