api/etcdhttp: change /health type back to string for backwards compatibility

This commit is contained in:
Jordan Liggitt
2018-01-15 01:49:59 -05:00
parent 7a8c192c8f
commit f77e54eb13
7 changed files with 20 additions and 17 deletions

View File

@ -58,7 +58,7 @@ func NewHealthHandler(hfunc func() Health) http.HandlerFunc {
}
h := hfunc()
d, _ := json.Marshal(h)
if !h.Health {
if h.Health != "true" {
http.Error(w, string(d), http.StatusServiceUnavailable)
return
}
@ -70,12 +70,12 @@ func NewHealthHandler(hfunc func() Health) http.HandlerFunc {
// Health defines etcd server health status.
// TODO: remove manual parsing in etcdctl cluster-health
type Health struct {
Health bool `json:"health"`
Health string `json:"health"`
Errors []string `json:"errors,omitempty"`
}
func checkHealth(srv etcdserver.ServerV2) Health {
h := Health{Health: false}
h := Health{Health: "false"}
as := srv.Alarms()
if len(as) > 0 {
@ -96,7 +96,8 @@ func checkHealth(srv etcdserver.ServerV2) Health {
if err != nil {
h.Errors = append(h.Errors, err.Error())
}
h.Health = err == nil
if err == nil {
h.Health = "true"
}
return h
}