From 98e481f9928d3a26612194f4f7f8094af386806d Mon Sep 17 00:00:00 2001 From: wentaojin <1051866518@qq.com> Date: Fri, 6 Sep 2024 23:06:38 +0800 Subject: [PATCH] opti display tip --- component/cluster/command/display.go | 2 +- utils/cluster/instance.go | 2 +- utils/cluster/manager/display.go | 14 +++++++------- utils/cluster/topology.go | 24 ++++++++++++------------ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/component/cluster/command/display.go b/component/cluster/command/display.go index 366a5c9..e8cb0f0 100644 --- a/component/cluster/command/display.go +++ b/component/cluster/command/display.go @@ -204,7 +204,7 @@ func (a *AppDisplay) Display(dOpt *manager.DisplayOption, gOpt *operator.Options if v.ComponentName != cluster.ComponentDBMSMaster { continue } - if strings.HasPrefix(v.Status, "Up") || strings.HasPrefix(v.Status, "Healthy") { + if strings.HasPrefix(v.Status, "NotReady") || strings.HasPrefix(v.Status, "Healthy") { instAddr := stringutil.JoinHostPort(v.ManageHost, v.Port) masterActive = append(masterActive, instAddr) } diff --git a/utils/cluster/instance.go b/utils/cluster/instance.go index 46284c9..7b76980 100644 --- a/utils/cluster/instance.go +++ b/utils/cluster/instance.go @@ -320,7 +320,7 @@ type BaseInstance struct { OSVersion string OSArch string - StatusFn func(ctx context.Context, tlsCfg *tls.Config, pdHosts ...string) (string, error) + StatusFn func(ctx context.Context, tlsCfg *tls.Config, masterAddrs ...string) (string, error) Config map[string]any Component Component diff --git a/utils/cluster/manager/display.go b/utils/cluster/manager/display.go index b6e5391..3ce0d9c 100644 --- a/utils/cluster/manager/display.go +++ b/utils/cluster/manager/display.go @@ -112,7 +112,7 @@ func (c *Controller) GetClusterTopology(dopt *DisplayOption, opt *operator.Optio } if len(masterList) == 0 { - return nil, nil, fmt.Errorf("the dbms-matser addr can't be zero, the dbms-cluster topology: [%v]", topo.String()) + return nil, nil, fmt.Errorf("the dbms-cluster master instance can't be zero, the dbms-cluster topology: [%v]", topo.String()) } client, err := etcdutil.CreateClient(context.TODO(), masterList, nil) @@ -141,7 +141,7 @@ func (c *Controller) GetClusterTopology(dopt *DisplayOption, opt *operator.Optio status, err := ins.Status(ctx, nil, masterList...) if err != nil { - c.Logger.Errorf("get instance %s status failed: %v", ins.InstanceName(), err) + c.Logger.Errorf("the dbms-cluster get master instance %s status failed: %v", ins.InstanceName(), err) masterStatus[ins.InstanceName()] = status return } @@ -182,7 +182,7 @@ func (c *Controller) GetClusterTopology(dopt *DisplayOption, opt *operator.Optio default: status, err = ins.Status(ctx, nil, masterActive...) if err != nil { - c.Logger.Errorf("get instance %s status failed: %v", ins.InstanceName(), err) + c.Logger.Errorf("the dbms-cluster get worker instance %s status failed: %v", ins.InstanceName(), err) } } @@ -332,13 +332,13 @@ func FormatInstanceStatus(status string) string { } switch { - case startsWith("up|l", "healthy|l"): // up|l, up|l|ui, healthy|l + case startsWith("healthy|l"): return color.GreenString(status) - case startsWith("up", "healthy", "free", "bound"): + case startsWith("healthy", "free", "bound"): return color.GreenString(status) - case startsWith("down", "err", "inactive", "failed"): // down, down|ui + case startsWith("down", "err", "inactive", "failed"): return color.RedString(status) - case startsWith("tombstone", "disconnected", "n/a", "stopped"), strings.Contains(strings.ToLower(status), "offline"): + case startsWith("notready", "disconnected", "n/a", "stopped"), strings.Contains(strings.ToLower(status), "offline"): return color.YellowString(status) default: return status diff --git a/utils/cluster/topology.go b/utils/cluster/topology.go index c20eed9..c8a493b 100644 --- a/utils/cluster/topology.go +++ b/utils/cluster/topology.go @@ -105,31 +105,31 @@ func (s *MasterOptions) InstanceName() string { // Status queries current status of the instance func (s *MasterOptions) Status(ctx context.Context, tlsCfg *tls.Config, addrs ...string) (string, error) { if len(addrs) == 0 { - return "N/A", fmt.Errorf("the cluster master instance cannot be zero, please contact author or reselect") + return "N/A", fmt.Errorf("the dbms-cluster master instance cannot be zero, please contact author or reselect") } cli, err := etcdutil.CreateClient(ctx, addrs, tlsCfg) if err != nil { - return "N/A", err + return "N/A", fmt.Errorf("the dbms-cluster create service client failed: [%v]", err) } - keyResp, err := etcdutil.GetKey(cli, stringutil.StringBuilder(constant.DefaultInstanceServiceRegisterPrefixKey, fmt.Sprintf("%s:%d", s.Host, s.PeerPort))) + keyResp, err := etcdutil.GetKey(cli, stringutil.StringBuilder(constant.DefaultInstanceServiceRegisterPrefixKey, fmt.Sprintf("%s:%d", s.Host, s.Port))) if err != nil { - return "N/A", err + return "N/A", fmt.Errorf("the dbms-cluster get master instance service key failed: [%v]", err) } if len(keyResp.Kvs) == 0 { - return "DOWN", nil + return "DOWN", fmt.Errorf("the dbms-cluster master instance [%s] service registe failed, please check and wait service normal", fmt.Sprintf("%s:%d", s.Host, s.Port)) } else if len(keyResp.Kvs) > 1 { - return "N/A", fmt.Errorf("the cluster instance member [%s] are over than one, please contact author or reselect", fmt.Sprintf("%s:%d", s.Host, s.Port)) + return "N/A", fmt.Errorf("the dbms-cluster instance member [%s] are over than one, please contact author or reselect", fmt.Sprintf("%s:%d", s.Host, s.Port)) } leaderResp, err := etcdutil.GetKey(cli, constant.DefaultMasterLeaderAddressKey) if err != nil { - return "N/A", err + return "N/A", fmt.Errorf("the dbms-cluster get master leader addr key failed: [%v]", err) } if len(leaderResp.Kvs) == 0 { - return "N/A", nil + return "NotReady", fmt.Errorf("the dbms-cluster master leader election has not completed, the service is disabled, please wait server ready") } else if len(leaderResp.Kvs) > 1 { - return "N/A", fmt.Errorf("the cluster leader are over than one, please contact author or reselect, detail: %v", leaderResp.Kvs) + return "N/A", fmt.Errorf("the dbms-cluster leader are over than one, please contact author or reselect, detail: %v", leaderResp.Kvs) } if strings.EqualFold(stringutil.BytesToString(leaderResp.Kvs[0].Value), fmt.Sprintf("%s:%d", s.Host, s.Port)) { @@ -165,7 +165,7 @@ func (w *WorkerOptions) InstanceName() string { // Status queries current status of the instance func (w *WorkerOptions) Status(ctx context.Context, tlsCfg *tls.Config, addrs ...string) (string, error) { if len(addrs) == 0 { - return "N/A", fmt.Errorf("the cluster master instance cannot be zero, please contact author or reselect") + return "N/A", fmt.Errorf("the dbms-cluster master instance cannot be zero, please contact author or reselect") } cli, err := etcdutil.CreateClient(ctx, addrs, tlsCfg) if err != nil { @@ -179,7 +179,7 @@ func (w *WorkerOptions) Status(ctx context.Context, tlsCfg *tls.Config, addrs .. if len(keyResp.Kvs) == 0 { return "DOWN", nil } else if len(keyResp.Kvs) > 1 { - return "N/A", fmt.Errorf("the cluster worker member [%s] are over than one, please contact author or reselect", fmt.Sprintf("%s:%d", w.Host, w.Port)) + return "N/A", fmt.Errorf("the dbms-cluster worker member [%s] are over than one, please contact author or reselect", fmt.Sprintf("%s:%d", w.Host, w.Port)) } var ws *etcdutil.Instance @@ -263,7 +263,7 @@ func (t *Topology) FillHostArchOrOS(hostArch map[string]string, fullType FullHos return nil } -// CountDir counts for dir paths used by any instance in the cluster with the same +// CountDir counts for dir paths used by any instance in the dbms-cluster with the same // prefix, useful to find potential path conflicts func (t *Topology) CountDir(targetHost, dirPrefix string) int { dirTypes := []string{