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
d292337d14
commit
02d362ccde
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user