Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

/health reports unhealthy when alarm is raised #8272

Merged
merged 2 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions e2e/ctl_v3_alarm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ func alarmTest(cx ctlCtx) {
cx.t.Fatal(err)
}

// '/health' handler should return 'false'
if err := cURLGet(cx.epc, cURLReq{endpoint: "/health", expected: `{"health": "false"}`}); err != nil {
cx.t.Fatalf("failed get with curl (%v)", err)
}

// check that Put is rejected when alarm is on
if err := ctlV3Put(cx, "3rd_test", smallbuf, ""); err != nil {
if !strings.Contains(err.Error(), "etcdserver: mvcc: database space exceeded") {
Expand Down
4 changes: 4 additions & 0 deletions etcdserver/api/etcdhttp/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1667,3 +1667,7 @@ func (s *EtcdServer) goAttach(f func()) {
f()
}()
}

func (s *EtcdServer) Alarms() []*pb.AlarmMember {
return s.alarmStore.Get(pb.AlarmType_NONE)
}