mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver/api/etcdhttp: remove "errors" field in /health
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
This commit is contained in:
parent
b5bb91a7c2
commit
1b4502114f
@ -70,34 +70,32 @@ func NewHealthHandler(hfunc func() Health) http.HandlerFunc {
|
|||||||
// Health defines etcd server health status.
|
// Health defines etcd server health status.
|
||||||
// TODO: remove manual parsing in etcdctl cluster-health
|
// TODO: remove manual parsing in etcdctl cluster-health
|
||||||
type Health struct {
|
type Health struct {
|
||||||
Health string `json:"health"`
|
Health string `json:"health"`
|
||||||
Errors []string `json:"errors,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: server NOSPACE, etcdserver.ErrNoLeader in health API
|
||||||
|
|
||||||
func checkHealth(srv etcdserver.ServerV2) Health {
|
func checkHealth(srv etcdserver.ServerV2) Health {
|
||||||
h := Health{Health: "false"}
|
h := Health{Health: "true"}
|
||||||
|
|
||||||
as := srv.Alarms()
|
as := srv.Alarms()
|
||||||
if len(as) > 0 {
|
if len(as) > 0 {
|
||||||
for _, v := range as {
|
h.Health = "false"
|
||||||
h.Errors = append(h.Errors, v.Alarm.String())
|
}
|
||||||
|
|
||||||
|
if h.Health == "true" {
|
||||||
|
if uint64(srv.Leader()) == raft.None {
|
||||||
|
h.Health = "false"
|
||||||
}
|
}
|
||||||
return h
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if uint64(srv.Leader()) == raft.None {
|
if h.Health == "true" {
|
||||||
h.Errors = append(h.Errors, etcdserver.ErrNoLeader.Error())
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||||
return h
|
_, err := srv.Do(ctx, etcdserverpb.Request{Method: "QGET"})
|
||||||
}
|
cancel()
|
||||||
|
if err != nil {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
h.Health = "false"
|
||||||
_, 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"
|
|
||||||
}
|
}
|
||||||
return h
|
return h
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user