1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2024-05-19 18:01:03 +02:00

Merge pull request #3385 from Woellchen/feature/cluster-status-return-healthy

Add healthy indicator for raft status
This commit is contained in:
Chris Lu 2022-07-30 11:55:30 -07:00 committed by GitHub
commit 0bb3ba17ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -2,19 +2,21 @@ package command
import ( import (
"fmt" "fmt"
"golang.org/x/exp/slices"
"net/http" "net/http"
"os" "os"
"path" "path"
"strings" "strings"
"time" "time"
"golang.org/x/exp/slices"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/seaweedfs/raft/protobuf" "github.com/seaweedfs/raft/protobuf"
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
"github.com/spf13/viper" "github.com/spf13/viper"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
stats_collect "github.com/seaweedfs/seaweedfs/weed/stats"
"github.com/seaweedfs/seaweedfs/weed/util/grace" "github.com/seaweedfs/seaweedfs/weed/util/grace"
"github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/glog"
@ -179,6 +181,7 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
} }
ms.SetRaftServer(raftServer) ms.SetRaftServer(raftServer)
r.HandleFunc("/cluster/status", raftServer.StatusHandler).Methods("GET") r.HandleFunc("/cluster/status", raftServer.StatusHandler).Methods("GET")
r.HandleFunc("/cluster/healthz", raftServer.HealthzHandler).Methods("GET", "HEAD")
if *m.raftHashicorp { if *m.raftHashicorp {
r.HandleFunc("/raft/stats", raftServer.StatsRaftHandler).Methods("GET") r.HandleFunc("/raft/stats", raftServer.StatsRaftHandler).Methods("GET")
} }

View file

@ -26,6 +26,15 @@ func (s *RaftServer) StatusHandler(w http.ResponseWriter, r *http.Request) {
writeJsonQuiet(w, r, http.StatusOK, ret) writeJsonQuiet(w, r, http.StatusOK, ret)
} }
func (s *RaftServer) HealthzHandler(w http.ResponseWriter, r *http.Request) {
_, err := s.topo.Leader()
if err != nil {
w.WriteHeader(http.StatusServiceUnavailable)
} else {
w.WriteHeader(http.StatusOK)
}
}
func (s *RaftServer) StatsRaftHandler(w http.ResponseWriter, r *http.Request) { func (s *RaftServer) StatsRaftHandler(w http.ResponseWriter, r *http.Request) {
if s.RaftHashicorp == nil { if s.RaftHashicorp == nil {
writeJsonQuiet(w, r, http.StatusNotFound, nil) writeJsonQuiet(w, r, http.StatusNotFound, nil)