diff --git a/components/playground/instance/instance.go b/components/playground/instance/instance.go index 4b4442f59e..72da8aae80 100644 --- a/components/playground/instance/instance.go +++ b/components/playground/instance/instance.go @@ -49,7 +49,9 @@ type Instance interface { LogFile() string // Uptime show uptime. Uptime() string + // StatusAddrs return the address to pull metrics. StatusAddrs() []string + // Wait Should only call this if the instance is started successfully. Wait() error } diff --git a/components/playground/playground.go b/components/playground/playground.go index 6962038148..6256f66c7e 100755 --- a/components/playground/playground.go +++ b/components/playground/playground.go @@ -382,9 +382,26 @@ func (p *Playground) sanitizeComponentConfig(cid string, cfg *instance.Config) { func (p *Playground) startInstance(ctx context.Context, inst instance.Instance) error { fmt.Printf("Start %s instance...\n", inst.Component()) err := inst.Start(context.Background(), v0manifest.Version(p.bootOptions.version)) + p.addWaitInstance(inst) return errors.AddStack(err) } +func (p *Playground) addWaitInstance(inst instance.Instance) { + p.instanceWaiter.Go(func() error { + err := inst.Wait() + if err != nil { + fmt.Print(color.RedString("%s quit: %s\n", inst.Component(), err.Error())) + if lines, _ := utils.TailN(inst.LogFile(), 10); len(lines) > 0 { + for _, line := range lines { + fmt.Println(line) + } + fmt.Print(color.YellowString("...\ncheck detail log from: %s\n", inst.LogFile())) + } + } + return err + }) +} + func (p *Playground) handleScaleOut(w io.Writer, cmd *Command) error { // Ignore Config.Num, alway one command as scale out one instance. p.sanitizeComponentConfig(cmd.ComponentID, &cmd.Config) @@ -398,10 +415,6 @@ func (p *Playground) handleScaleOut(w io.Writer, cmd *Command) error { return errors.AddStack(err) } - p.instanceWaiter.Go(func() error { - return inst.Wait() - }) - logIfErr(p.renderSDFile()) return nil @@ -810,7 +823,7 @@ func (p *Playground) bootCluster(options *bootOptions) error { if lastErr == nil { for _, flash := range p.tiflashs { - if err := flash.Start(ctx, v0manifest.Version(options.version)); err != nil { + if err := p.startInstance(ctx, flash); err != nil { lastErr = err break } @@ -922,23 +935,6 @@ func (p *Playground) bootCluster(options *bootOptions) error { } }() - _ = p.WalkInstances(func(_ string, inst instance.Instance) error { - p.instanceWaiter.Go(func() error { - err := inst.Wait() - if err != nil { - fmt.Print(color.RedString("%s quit: \n", inst.Component())) - if lines, _ := utils.TailN(inst.LogFile(), 10); len(lines) > 0 { - for _, line := range lines { - fmt.Println(line) - } - fmt.Print(color.YellowString("...\ncheck detail log from: %s\n", inst.LogFile())) - } - } - return err - }) - return nil - }) - logIfErr(p.renderSDFile()) if grafana != nil {