mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: remove redundant len
check in health check
From the Go specification [1]: "1. For a nil slice, the number of iterations is 0." `len` returns 0 if the slice or map is nil [2]. Therefore, checking `len(v) > 0` around a loop is unnecessary. [1]: https://go.dev/ref/spec#For_range [2]: https://pkg.go.dev/builtin#len Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
parent
d0d0c33338
commit
867faa1924
@ -143,27 +143,25 @@ func getSerializableFlag(r *http.Request) bool {
|
||||
|
||||
func checkAlarms(lg *zap.Logger, srv ServerHealth, excludedAlarms AlarmSet) Health {
|
||||
h := Health{Health: "true"}
|
||||
as := srv.Alarms()
|
||||
if len(as) > 0 {
|
||||
for _, v := range as {
|
||||
alarmName := v.Alarm.String()
|
||||
if _, found := excludedAlarms[alarmName]; found {
|
||||
lg.Debug("/health excluded alarm", zap.String("alarm", v.String()))
|
||||
continue
|
||||
}
|
||||
|
||||
h.Health = "false"
|
||||
switch v.Alarm {
|
||||
case pb.AlarmType_NOSPACE:
|
||||
h.Reason = "ALARM NOSPACE"
|
||||
case pb.AlarmType_CORRUPT:
|
||||
h.Reason = "ALARM CORRUPT"
|
||||
default:
|
||||
h.Reason = "ALARM UNKNOWN"
|
||||
}
|
||||
lg.Warn("serving /health false due to an alarm", zap.String("alarm", v.String()))
|
||||
return h
|
||||
for _, v := range srv.Alarms() {
|
||||
alarmName := v.Alarm.String()
|
||||
if _, found := excludedAlarms[alarmName]; found {
|
||||
lg.Debug("/health excluded alarm", zap.String("alarm", v.String()))
|
||||
continue
|
||||
}
|
||||
|
||||
h.Health = "false"
|
||||
switch v.Alarm {
|
||||
case pb.AlarmType_NOSPACE:
|
||||
h.Reason = "ALARM NOSPACE"
|
||||
case pb.AlarmType_CORRUPT:
|
||||
h.Reason = "ALARM CORRUPT"
|
||||
default:
|
||||
h.Reason = "ALARM UNKNOWN"
|
||||
}
|
||||
lg.Warn("serving /health false due to an alarm", zap.String("alarm", v.String()))
|
||||
return h
|
||||
}
|
||||
|
||||
return h
|
||||
|
Loading…
x
Reference in New Issue
Block a user