etcdserver/api/etcdhttp: remove "errors" field in /health
@@ -71,33 +71,31 @@ func NewHealthHandler(hfunc func() Health) http.HandlerFunc {
// TODO: remove manual parsing in etcdctl cluster-health
type Health struct {
Health string `json:"health"`
- Errors []string `json:"errors,omitempty"`
}
+// 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())
- }
- return h
+ h.Health = "false"
}
+ if h.Health == "true" {
if uint64(srv.Leader()) == raft.None {
- h.Errors = append(h.Errors, etcdserver.ErrNoLeader.Error())
- return h
+ h.Health = "false"
+ }
}
+ 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.Errors = append(h.Errors, err.Error())
+ h.Health = "false"
}
- if err == nil {
- h.Health = "true"
}
return h
}
