Browse Source

etcdctl: prepare for health endpoint change

We made a mistake on the health endpoint by returning a string "true".
We have to make the etcdctl works for the next version of etcd which
will correct the mistake on the server side.

It is too late to change the server side right now since we already
released a version of etcdctl that only understands "true".
Xiang Li 10 years ago
parent
commit
04539c6240
1 changed files with 12 additions and 2 deletions
  1. 12 2
      etcdctl/command/cluster_health.go

+ 12 - 2
etcdctl/command/cluster_health.go

@@ -3,6 +3,7 @@ package command
 import (
 import (
 	"encoding/json"
 	"encoding/json"
 	"fmt"
 	"fmt"
+	"io/ioutil"
 	"net/http"
 	"net/http"
 	"os"
 	"os"
 	"os/signal"
 	"os/signal"
@@ -70,9 +71,18 @@ func handleClusterHealth(c *cli.Context) {
 				}
 				}
 
 
 				result := struct{ Health string }{}
 				result := struct{ Health string }{}
-				d := json.NewDecoder(resp.Body)
-				err = d.Decode(&result)
+				nresult := struct{ Health bool }{}
+				bytes, err := ioutil.ReadAll(resp.Body)
+				if err != nil {
+					fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err)
+					continue
+				}
 				resp.Body.Close()
 				resp.Body.Close()
+
+				err = json.Unmarshal(bytes, &result)
+				if err != nil {
+					err = json.Unmarshal(bytes, &nresult)
+				}
 				if err != nil {
 				if err != nil {
 					fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err)
 					fmt.Printf("failed to check the health of member %s on %s: %v\n", m.ID, url, err)
 					continue
 					continue