From 4acaa5a2a0f3d714bebd406f1dc40c3ea7d19de9 Mon Sep 17 00:00:00 2001 From: tangcong Date: Sat, 6 Jun 2020 14:24:41 +0800 Subject: [PATCH] etcdserver/api/etcdhttp: add reason field for /health response --- etcdserver/api/etcdhttp/metrics.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/etcdserver/api/etcdhttp/metrics.go b/etcdserver/api/etcdhttp/metrics.go index e6365a8c9..b34a26dfe 100644 --- a/etcdserver/api/etcdhttp/metrics.go +++ b/etcdserver/api/etcdhttp/metrics.go @@ -90,6 +90,7 @@ func init() { // TODO: remove manual parsing in etcdctl cluster-health type Health struct { Health string `json:"health"` + Reason string `json:"reason"` } // TODO: server NOSPACE, etcdserver.ErrNoLeader in health API @@ -109,6 +110,14 @@ func checkHealth(lg *zap.Logger, srv etcdserver.ServerV2) (h Health) { if len(as) > 0 { h.Health = "false" for _, v := range as { + switch v.Alarm { + case etcdserverpb.AlarmType_NOSPACE: + h.Reason = "ALARM NOSPACE" + case etcdserverpb.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 @@ -116,6 +125,7 @@ func checkHealth(lg *zap.Logger, srv etcdserver.ServerV2) (h Health) { if uint64(srv.Leader()) == raft.None { h.Health = "false" + h.Reason = "RAFT NO LEADER" lg.Warn("serving /health false; no leader") return } @@ -125,6 +135,7 @@ func checkHealth(lg *zap.Logger, srv etcdserver.ServerV2) (h Health) { cancel() if err != nil { h.Health = "false" + h.Reason = "QGET ERROR" lg.Warn("serving /health false; QGET fails", zap.Error(err)) }