Browse Source

etcdserver: check alarms in health handler

Signed-off-by: Gyu-Ho Lee <gyuhox@gmail.com>
Gyu-Ho Lee 8 years ago
parent
commit
61a736a068
2 changed files with 8 additions and 0 deletions
  1. 4 0
      etcdserver/api/etcdhttp/base.go
  2. 4 0
      etcdserver/server.go

+ 4 - 0
etcdserver/api/etcdhttp/base.go

@@ -67,6 +67,10 @@ func healthHandler(server *etcdserver.EtcdServer) http.HandlerFunc {
 			http.Error(w, `{"health": "false"}`, http.StatusServiceUnavailable)
 			return
 		}
+		if len(server.Alarms()) > 0 {
+			w.Write([]byte(`{"health": "false"}`))
+			return
+		}
 		ctx, cancel := context.WithTimeout(context.Background(), time.Second)
 		defer cancel()
 		if _, err := server.Do(ctx, etcdserverpb.Request{Method: "QGET"}); err != nil {

+ 4 - 0
etcdserver/server.go

@@ -1667,3 +1667,7 @@ func (s *EtcdServer) goAttach(f func()) {
 		f()
 	}()
 }
+
+func (s *EtcdServer) Alarms() []*pb.AlarmMember {
+	return s.alarmStore.Get(pb.AlarmType_NONE)
+}