|
|
@ -61,28 +61,17 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var (
|
|
|
|
var prometheusListenAddr string
|
|
|
|
rpcListenAddr string
|
|
|
|
|
|
|
|
prometheusListenAddr string
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if autoSetPorts {
|
|
|
|
if autoSetPorts {
|
|
|
|
rpcListenAddr = net.JoinHostPort(listenIP, "0")
|
|
|
|
|
|
|
|
prometheusListenAddr = net.JoinHostPort(listenIP, "0")
|
|
|
|
prometheusListenAddr = net.JoinHostPort(listenIP, "0")
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
rpcPort, err := datautil.GetElemByIndex(rpcPorts, index)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
prometheusPort, err := datautil.GetElemByIndex(prometheusConfig.Ports, index)
|
|
|
|
prometheusPort, err := datautil.GetElemByIndex(prometheusConfig.Ports, index)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rpcListenAddr = net.JoinHostPort(listenIP, strconv.Itoa(rpcPort))
|
|
|
|
|
|
|
|
prometheusListenAddr = net.JoinHostPort(listenIP, strconv.Itoa(prometheusPort))
|
|
|
|
prometheusListenAddr = net.JoinHostPort(listenIP, strconv.Itoa(prometheusPort))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.CInfo(ctx, "RPC server is initializing", "rpcRegisterName", rpcRegisterName, "rpcAddr", rpcListenAddr, "prometheusAddr", prometheusListenAddr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
watchConfigNames = append(watchConfigNames, conf.LogConfigFileName)
|
|
|
|
watchConfigNames = append(watchConfigNames, conf.LogConfigFileName)
|
|
|
|
|
|
|
|
|
|
|
|
client, err := kdisc.NewDiscoveryRegister(disc, watchServiceNames)
|
|
|
|
client, err := kdisc.NewDiscoveryRegister(disc, watchServiceNames)
|
|
|
@ -149,6 +138,17 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|
|
|
rpcServer.RegisterService(desc, impl)
|
|
|
|
rpcServer.RegisterService(desc, impl)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var rpcListenAddr string
|
|
|
|
|
|
|
|
if autoSetPorts {
|
|
|
|
|
|
|
|
rpcListenAddr = net.JoinHostPort(listenIP, "0")
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
rpcPort, err := datautil.GetElemByIndex(rpcPorts, index)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
cancel(fmt.Errorf("rpcPorts index out of range %s %w", rpcRegisterName, err))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rpcListenAddr = net.JoinHostPort(listenIP, strconv.Itoa(rpcPort))
|
|
|
|
|
|
|
|
}
|
|
|
|
rpcListener, err := net.Listen("tcp", rpcListenAddr)
|
|
|
|
rpcListener, err := net.Listen("tcp", rpcListenAddr)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
cancel(fmt.Errorf("listen rpc %s %s %w", rpcRegisterName, rpcListenAddr, err))
|
|
|
|
cancel(fmt.Errorf("listen rpc %s %s %w", rpcRegisterName, rpcListenAddr, err))
|
|
|
@ -186,6 +186,7 @@ func Start[T any](ctx context.Context, disc *conf.Discovery, prometheusConfig *c
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
<-ctx.Done()
|
|
|
|
<-ctx.Done()
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "cmd wait done", "err", context.Cause(ctx))
|
|
|
|
if rpcGracefulStop != nil {
|
|
|
|
if rpcGracefulStop != nil {
|
|
|
|
timeout := time.NewTimer(time.Second * 15)
|
|
|
|
timeout := time.NewTimer(time.Second * 15)
|
|
|
|
defer timeout.Stop()
|
|
|
|
defer timeout.Stop()
|
|
|
|