command: Enhance health command to check if there are any active alarms (#12150)

release-3.5
Ankur Gargi 2020-10-22 18:55:15 -04:00 committed by GitHub
parent 97354af44b
commit 8866d55b9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 1 deletions

View File

@ -20,6 +20,7 @@ import (
"sync"
"time"
"go.etcd.io/etcd/api/v3/etcdserverpb"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
v3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/pkg/v3/flags"
@ -124,7 +125,6 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) {
// endpoint is health.
ctx, cancel := commandCtx(cmd)
_, err = cli.Get(ctx, "health")
cancel()
eh := epHealth{Ep: ep, Health: false, Took: time.Since(st).String()}
// permission denied is OK since proposal goes through consensus to get it
if err == nil || err == rpctypes.ErrPermissionDenied {
@ -132,6 +132,28 @@ func epHealthCommandFunc(cmd *cobra.Command, args []string) {
} else {
eh.Error = err.Error()
}
if eh.Health == true {
resp, err := cli.AlarmList(ctx)
if err == nil && len(resp.Alarms) > 0 {
eh.Health = false
eh.Error = "Active Alarm(s): "
for _, v := range resp.Alarms {
switch v.Alarm {
case etcdserverpb.AlarmType_NOSPACE:
eh.Error = eh.Error + "NOSPACE "
case etcdserverpb.AlarmType_CORRUPT:
eh.Error = eh.Error + "CORRUPT "
default:
eh.Error = eh.Error + "UNKNOWN "
}
}
} else if err != nil {
eh.Health = false
eh.Error = "Unable to fetch the alarm list"
}
}
cancel()
hch <- eh
}(cfg)
}