@@ -19,6 +19,7 @@ package components
1919import (
2020 "context"
2121 "fmt"
22+ "net"
2223 "net/http"
2324 "path"
2425 "sync"
@@ -30,7 +31,7 @@ import (
3031 fileutils "github.com/GreptimeTeam/gtctl/pkg/utils/file"
3132)
3233
33- type frontend struct {
34+ type Frontend struct {
3435 config * config.Frontend
3536 metaSrvAddr string
3637
@@ -42,8 +43,8 @@ type frontend struct {
4243}
4344
4445func NewFrontend (config * config.Frontend , metaSrvAddr string , workingDirs WorkingDirs ,
45- wg * sync.WaitGroup , logger logger.Logger ) ClusterComponent {
46- return & frontend {
46+ wg * sync.WaitGroup , logger logger.Logger ) Frontend {
47+ return Frontend {
4748 config : config ,
4849 metaSrvAddr : metaSrvAddr ,
4950 workingDirs : workingDirs ,
@@ -52,11 +53,11 @@ func NewFrontend(config *config.Frontend, metaSrvAddr string, workingDirs Workin
5253 }
5354}
5455
55- func (f * frontend ) Name () string {
56+ func (f * Frontend ) Name () string {
5657 return string (greptimedbclusterv1alpha1 .FrontendComponentKind )
5758}
5859
59- func (f * frontend ) Start (ctx context.Context , stop context.CancelFunc , binary string ) error {
60+ func (f * Frontend ) Start (ctx context.Context , stop context.CancelFunc , binary string ) error {
6061 for i := 0 ; i < f .config .Replicas ; i ++ {
6162 dirName := fmt .Sprintf ("%s.%d" , f .Name (), i )
6263
@@ -87,7 +88,7 @@ func (f *frontend) Start(ctx context.Context, stop context.CancelFunc, binary st
8788 return nil
8889}
8990
90- func (f * frontend ) BuildArgs (params ... interface {}) []string {
91+ func (f * Frontend ) BuildArgs (params ... interface {}) []string {
9192 logLevel := f .config .LogLevel
9293 if logLevel == "" {
9394 logLevel = DefaultLogLevel
@@ -115,7 +116,7 @@ func (f *frontend) BuildArgs(params ...interface{}) []string {
115116 return args
116117}
117118
118- func (f * frontend ) IsRunning (_ context.Context ) bool {
119+ func (f * Frontend ) IsRunning (_ context.Context ) bool {
119120 for i := 0 ; i < f .config .Replicas ; i ++ {
120121 addr := FormatAddrArg (f .config .HTTPAddr , i )
121122 healthy := fmt .Sprintf ("http://%s/health" , addr )
@@ -138,3 +139,34 @@ func (f *frontend) IsRunning(_ context.Context) bool {
138139 }
139140 return true
140141}
142+
143+ func (f * Frontend ) PrintDashboardLog () {
144+ format := "http://%s:%s/dashboard/"
145+
146+ // Split addr to host:ip
147+ http_addr := f .config .HTTPAddr
148+ host , port , err := net .SplitHostPort (http_addr )
149+ if len (http_addr ) > 0 && err != nil {
150+ f .logger .Warnf ("%s use incorrect http_addr: %s err: %s" , f .Name (), http_addr , err )
151+ return
152+ }
153+
154+ var log string
155+ if len (http_addr ) == 0 || host == "0.0.0.0" {
156+ ip , err := HostnameIP ()
157+
158+ if err != nil {
159+ f .logger .Warnf ("%s hostname local resolution failed: %s" , f .Name (), err )
160+ return
161+ }
162+ if len (port ) == 0 {
163+ port = "4000"
164+ }
165+
166+ log = fmt .Sprintf (format , ip , port )
167+ } else {
168+ log = fmt .Sprintf (format , host , port )
169+ }
170+
171+ f .logger .V (0 ).Infof ("If enable dashboard, view it by accessing: %s" , logger .Bold (log ))
172+ }
0 commit comments