diff --git a/etcdserver/api/etcdhttp/metrics.go b/etcdserver/api/etcdhttp/metrics.go index a68d9cefd..f374adcaa 100644 --- a/etcdserver/api/etcdhttp/metrics.go +++ b/etcdserver/api/etcdhttp/metrics.go @@ -70,34 +70,32 @@ func NewHealthHandler(hfunc func() Health) http.HandlerFunc { // Health defines etcd server health status. // TODO: remove manual parsing in etcdctl cluster-health type Health struct { - Health string `json:"health"` - Errors []string `json:"errors,omitempty"` + Health string `json:"health"` } +// TODO: server NOSPACE, etcdserver.ErrNoLeader in health API + func checkHealth(srv etcdserver.ServerV2) Health { - h := Health{Health: "false"} + h := Health{Health: "true"} as := srv.Alarms() if len(as) > 0 { - for _, v := range as { - h.Errors = append(h.Errors, v.Alarm.String()) + h.Health = "false" + } + + if h.Health == "true" { + if uint64(srv.Leader()) == raft.None { + h.Health = "false" } - return h } - if uint64(srv.Leader()) == raft.None { - h.Errors = append(h.Errors, etcdserver.ErrNoLeader.Error()) - return h - } - - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - _, err := srv.Do(ctx, etcdserverpb.Request{Method: "QGET"}) - cancel() - if err != nil { - h.Errors = append(h.Errors, err.Error()) - } - if err == nil { - h.Health = "true" + if h.Health == "true" { + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + _, err := srv.Do(ctx, etcdserverpb.Request{Method: "QGET"}) + cancel() + if err != nil { + h.Health = "false" + } } return h }