From 32bb5b0e05778880c0a82b16d69a965cd7944cd9 Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Tue, 9 Jun 2020 18:01:21 +0800 Subject: [PATCH 1/6] differ the Down and Unhealty status for PD node --- pkg/cluster/meta/topology.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/cluster/meta/topology.go b/pkg/cluster/meta/topology.go index ffb5149666..ec7f17d917 100644 --- a/pkg/cluster/meta/topology.go +++ b/pkg/cluster/meta/topology.go @@ -279,7 +279,6 @@ type PDSpec struct { // Status queries current status of the instance func (s PDSpec) Status(pdList ...string) string { curAddr := fmt.Sprintf("%s:%d", s.Host, s.ClientPort) - curPdAPI := api.NewPDClient([]string{curAddr}, statusQueryTimeout, nil) allPdAPI := api.NewPDClient(pdList, statusQueryTimeout, nil) suffix := "" @@ -293,13 +292,15 @@ func (s PDSpec) Status(pdList ...string) string { suffix = "|UI" } - healths, err := curPdAPI.GetHealth() + // "Down" means all PD nodes don't work, + // while "Unhealthy" means current PD node doesn't work + healths, err := allPdAPI.GetHealth() if err != nil { return "Down" + suffix } // find leader node - leader, err := curPdAPI.GetLeader() + leader, err := allPdAPI.GetLeader() if err != nil { return "ERR" + suffix } From 2b8cd5eae9679f7f8753f9b6a646c6b6a86c2492 Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Fri, 12 Jun 2020 19:15:21 +0800 Subject: [PATCH 2/6] Revert "differ the Down and Unhealty status for PD node" This reverts commit 32bb5b0e05778880c0a82b16d69a965cd7944cd9. --- pkg/cluster/meta/topology.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/cluster/meta/topology.go b/pkg/cluster/meta/topology.go index ec7f17d917..ffb5149666 100644 --- a/pkg/cluster/meta/topology.go +++ b/pkg/cluster/meta/topology.go @@ -279,6 +279,7 @@ type PDSpec struct { // Status queries current status of the instance func (s PDSpec) Status(pdList ...string) string { curAddr := fmt.Sprintf("%s:%d", s.Host, s.ClientPort) + curPdAPI := api.NewPDClient([]string{curAddr}, statusQueryTimeout, nil) allPdAPI := api.NewPDClient(pdList, statusQueryTimeout, nil) suffix := "" @@ -292,15 +293,13 @@ func (s PDSpec) Status(pdList ...string) string { suffix = "|UI" } - // "Down" means all PD nodes don't work, - // while "Unhealthy" means current PD node doesn't work - healths, err := allPdAPI.GetHealth() + healths, err := curPdAPI.GetHealth() if err != nil { return "Down" + suffix } // find leader node - leader, err := allPdAPI.GetLeader() + leader, err := curPdAPI.GetLeader() if err != nil { return "ERR" + suffix } From f6a50684d0c97473158284ba2d544aed8231449d Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Fri, 12 Jun 2020 19:43:37 +0800 Subject: [PATCH 3/6] make PD node status consistency with other components --- pkg/cluster/api/pdapi.go | 21 +++++++-------------- pkg/cluster/meta/topology.go | 19 +++++-------------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/pkg/cluster/api/pdapi.go b/pkg/cluster/api/pdapi.go index 8117644276..9b8e2aea52 100644 --- a/pkg/cluster/api/pdapi.go +++ b/pkg/cluster/api/pdapi.go @@ -64,7 +64,7 @@ func (pc *PDClient) GetURL(addr string) string { // nolint (some is unused now) var ( - pdHealthURI = "pd/health" + pdPingURI = "pd/ping" pdMembersURI = "pd/api/v1/members" pdStoresURI = "pd/api/v1/stores" pdStoreURI = "pd/api/v1/store" @@ -102,11 +102,6 @@ func tryURLs(endpoints []string, f func(endpoint string) ([]byte, error)) ([]byt return bytes, err } -// PDHealthInfo is the member health info from PD's API -type PDHealthInfo struct { - Healths []pdserverapi.Health -} - func (pc *PDClient) getEndpoints(cmd string) (endpoints []string) { for _, addr := range pc.addrs { endpoint := fmt.Sprintf("%s/%s", pc.GetURL(addr), cmd) @@ -116,11 +111,9 @@ func (pc *PDClient) getEndpoints(cmd string) (endpoints []string) { return } -// GetHealth queries the health info from PD server -func (pc *PDClient) GetHealth() (*PDHealthInfo, error) { - endpoints := pc.getEndpoints(pdHealthURI) - - healths := []pdserverapi.Health{} +// CheckHeath checks the health of PD node +func (pc *PDClient) CheckHealth() error { + endpoints := pc.getEndpoints(pdPingURI) _, err := tryURLs(endpoints, func(endpoint string) ([]byte, error) { body, err := pc.httpClient.Get(endpoint) @@ -128,14 +121,14 @@ func (pc *PDClient) GetHealth() (*PDHealthInfo, error) { return body, err } - return body, json.Unmarshal(body, &healths) + return body, nil }) if err != nil { - return nil, errors.AddStack(err) + return errors.AddStack(err) } - return &PDHealthInfo{healths}, nil + return nil } // GetStores queries the stores info from PD server diff --git a/pkg/cluster/meta/topology.go b/pkg/cluster/meta/topology.go index ffb5149666..b093171c85 100644 --- a/pkg/cluster/meta/topology.go +++ b/pkg/cluster/meta/topology.go @@ -293,7 +293,8 @@ func (s PDSpec) Status(pdList ...string) string { suffix = "|UI" } - healths, err := curPdAPI.GetHealth() + // check health + err := curPdAPI.CheckHealth() if err != nil { return "Down" + suffix } @@ -303,20 +304,10 @@ func (s PDSpec) Status(pdList ...string) string { if err != nil { return "ERR" + suffix } - - for _, member := range healths.Healths { - if s.Name != member.Name { - continue - } - if s.Name == leader.Name { - suffix = "|L" + suffix - } - if member.Health { - return "Healthy" + suffix - } - return "Unhealthy" + suffix + if s.Name == leader.Name { + suffix = "|L" + suffix } - return "N/A" + suffix + return "Up" + suffix } // Role returns the component role of the instance From a276ba1c76140526b7789b03ec21b02d679b7bd5 Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Fri, 12 Jun 2020 20:00:54 +0800 Subject: [PATCH 4/6] update display output --- components/cluster/command/display.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/components/cluster/command/display.go b/components/cluster/command/display.go index bf55a42b7b..8fc1367cd8 100644 --- a/components/cluster/command/display.go +++ b/components/cluster/command/display.go @@ -272,14 +272,12 @@ func formatInstanceStatus(status string) string { } switch { - case startsWith("healthy|l"): // healthy|l, healthy|l|ui + case startsWith("up|l"): // up|l, up|l|ui return color.HiGreenString(status) - case startsWith("healthy"): // healthy, healthy|ui - return color.GreenString(status) - case startsWith("unhealthy", "down", "err"): // unhealthy/down/err, unhealthy/down/err|ui - return color.RedString(status) case startsWith("up"): return color.GreenString(status) + case startsWith("down", "err"): // down, down|ui + return color.RedString(status) case startsWith("tombstone", "disconnected"), strings.Contains(status, "offline"): return color.YellowString(status) default: From 3486880602988fb3099efef920d88a21c902ac12 Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Fri, 12 Jun 2020 20:08:09 +0800 Subject: [PATCH 5/6] fix CI --- pkg/cluster/api/pdapi.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/api/pdapi.go b/pkg/cluster/api/pdapi.go index 9b8e2aea52..c452619e03 100644 --- a/pkg/cluster/api/pdapi.go +++ b/pkg/cluster/api/pdapi.go @@ -111,7 +111,7 @@ func (pc *PDClient) getEndpoints(cmd string) (endpoints []string) { return } -// CheckHeath checks the health of PD node +// CheckHealth checks the health of PD node func (pc *PDClient) CheckHealth() error { endpoints := pc.getEndpoints(pdPingURI) From cb6a42f66a6d3c0497728722ac439889fa6ffc1b Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Fri, 12 Jun 2020 20:20:17 +0800 Subject: [PATCH 6/6] refine --- components/dms/command/display.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/components/dms/command/display.go b/components/dms/command/display.go index f84d798db8..812a3c2572 100644 --- a/components/dms/command/display.go +++ b/components/dms/command/display.go @@ -246,15 +246,26 @@ func displayClusterTopology(clusterName string, opt *operator.Options) error { } func formatInstanceStatus(status string) string { - switch strings.ToLower(status) { - case "up", "healthy", "free": - return color.GreenString(status) - case "healthy|l", "bound": // master leader + lowercaseStatus := strings.ToLower(status) + + startsWith := func(prefixs ...string) bool { + for _, prefix := range prefixs { + if strings.HasPrefix(lowercaseStatus, prefix) { + return true + } + } + return false + } + + switch { + case startsWith("up|l"): // up|l, up|l|ui return color.HiGreenString(status) - case "offline", "tombstone", "disconnected": - return color.YellowString(status) - case "down", "unhealthy", "err": + case startsWith("up"): + return color.GreenString(status) + case startsWith("down", "err"): // down, down|ui return color.RedString(status) + case startsWith("tombstone", "disconnected"), strings.Contains(status, "offline"): + return color.YellowString(status) default: return status }