From 571873917294a041094b8c5fac277423d4c761f7 Mon Sep 17 00:00:00 2001 From: LFC <990479+MichaelScofield@users.noreply.github.com> Date: Tue, 26 Dec 2023 11:21:05 +0800 Subject: [PATCH 1/2] print start err (#185) --- cmd/gtctl/main.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/gtctl/main.go b/cmd/gtctl/main.go index 06b1f41d..84d4bc1d 100644 --- a/cmd/gtctl/main.go +++ b/cmd/gtctl/main.go @@ -85,5 +85,7 @@ func main() { } os.Exit(0) } + + fmt.Println(err) } } From 42eaabae77db1329b1f2495ed7d6b6dfd5c85218 Mon Sep 17 00:00:00 2001 From: LFC <990479+MichaelScofield@users.noreply.github.com> Date: Wed, 27 Dec 2023 11:35:44 +0800 Subject: [PATCH 2/2] fix: correctly config multiple address for frontend (#186) --- pkg/components/frontend.go | 44 ++++++++++++++++++++++++++++++++++---- pkg/config/baremetal.go | 2 ++ 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/pkg/components/frontend.go b/pkg/components/frontend.go index 0c16a8e8..e6eab400 100644 --- a/pkg/components/frontend.go +++ b/pkg/components/frontend.go @@ -17,7 +17,10 @@ package components import ( "context" "fmt" + "net" + "net/http" "path" + "strconv" "sync" greptimedbclusterv1alpha1 "github.com/GreptimeTeam/greptimedb-operator/apis/v1alpha1" @@ -74,7 +77,7 @@ func (f *frontend) Start(ctx context.Context, stop context.CancelFunc, binary st Name: dirName, logDir: frontendLogDir, pidDir: frontendPidDir, - args: f.BuildArgs(), + args: f.BuildArgs(i), } if err := runBinary(ctx, stop, option, f.wg, f.logger); err != nil { return err @@ -84,16 +87,23 @@ func (f *frontend) Start(ctx context.Context, stop context.CancelFunc, binary st return nil } -func (f *frontend) BuildArgs(_ ...interface{}) []string { +func (f *frontend) BuildArgs(params ...interface{}) []string { logLevel := f.config.LogLevel if logLevel == "" { logLevel = DefaultLogLevel } + nodeId := params[0].(int) + args := []string{ fmt.Sprintf("--log-level=%s", logLevel), f.Name(), "start", fmt.Sprintf("--metasrv-addr=%s", f.metaSrvAddr), + fmt.Sprintf("--http-addr=%s", generateAddrArg(f.config.HTTPAddr, nodeId)), + fmt.Sprintf("--rpc-addr=%s", generateAddrArg(f.config.GRPCAddr, nodeId)), + fmt.Sprintf("--mysql-addr=%s", generateAddrArg(f.config.MysqlAddr, nodeId)), + fmt.Sprintf("--postgres-addr=%s", generateAddrArg(f.config.PostgresAddr, nodeId)), + fmt.Sprintf("--opentsdb-addr=%s", generateAddrArg(f.config.OpentsdbAddr, nodeId)), } if len(f.config.Config) > 0 { @@ -104,6 +114,32 @@ func (f *frontend) BuildArgs(_ ...interface{}) []string { } func (f *frontend) IsRunning(_ context.Context) bool { - // Have not implemented the healthy checker now. - return false + for i := 0; i < f.config.Replicas; i++ { + addr := generateAddrArg(f.config.HTTPAddr, i) + healthy := fmt.Sprintf("http://%s/health", addr) + + resp, err := http.Get(healthy) + if err != nil { + f.logger.V(5).Infof("Failed to get %s healthy: %s", f.Name(), err) + return false + } + + if resp.StatusCode != http.StatusOK { + f.logger.V(5).Infof("%s is not healthy: %s", f.Name(), resp) + return false + } + + if err = resp.Body.Close(); err != nil { + f.logger.V(5).Infof("%s is not healthy: %s, err: %s", f.Name(), resp, err) + return false + } + } + return true +} + +func generateAddrArg(addr string, nodeId int) string { + // The "addr" is validated when set. + host, port, _ := net.SplitHostPort(addr) + portInt, _ := strconv.Atoi(port) + return net.JoinHostPort(host, strconv.Itoa(portInt+nodeId)) } diff --git a/pkg/config/baremetal.go b/pkg/config/baremetal.go index 50c154db..64ed9199 100644 --- a/pkg/config/baremetal.go +++ b/pkg/config/baremetal.go @@ -73,6 +73,8 @@ type Frontend struct { HTTPAddr string `yaml:"httpAddr" validate:"omitempty,hostname_port"` PostgresAddr string `yaml:"postgresAddr" validate:"omitempty,hostname_port"` MetaAddr string `yaml:"metaAddr" validate:"omitempty,hostname_port"` + MysqlAddr string `yaml:"mysqlAddr" validate:"omitempty,hostname_port"` + OpentsdbAddr string `yaml:"opentsdbAddr" validate:"omitempty,hostname_port"` Replicas int `yaml:"replicas" validate:"gt=0"` Config string `yaml:"config" validate:"omitempty,filepath"`