Merge branch 'master' into kd-live

This commit is contained in:
2023-06-29 11:00:49 +09:00
4 changed files with 40 additions and 8 deletions

View File

@ -117,6 +117,8 @@ type houstonClient struct {
timestamp string timestamp string
wg sync.WaitGroup wg sync.WaitGroup
config clientConfig config clientConfig
version string
standalone bool
} }
func unmarshal[T any](val *T, src map[string]string) { func unmarshal[T any](val *T, src map[string]string) {
@ -162,8 +164,25 @@ func gatherDeployedPrograms(storageRoot, name string) []*protos.VersionAndArgs {
} }
func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryRequest { func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryRequest {
hn, _ := os.Hostname() procs := make([]*protos.ProcessDescription, 0, len(hc.childProcs)+1)
procs := make([]*protos.ProcessDescription, 0, len(hc.childProcs)) if hc.standalone {
procs = append(procs, &protos.ProcessDescription{
Name: os.Args[0],
Args: os.Args[1:],
Version: hc.version,
State: protos.ProcessState_Running,
Pid: int32(os.Getpid()),
})
} else {
procs = append(procs, &protos.ProcessDescription{
Name: "houston",
Args: []string{},
Version: hc.version,
State: protos.ProcessState_Running,
Pid: int32(os.Getpid()),
})
}
for _, child := range hc.childProcs { for _, child := range hc.childProcs {
procs = append(procs, &protos.ProcessDescription{ procs = append(procs, &protos.ProcessDescription{
Name: child.name, Name: child.name,
@ -181,7 +200,7 @@ func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryReque
Versions: prog, Versions: prog,
}) })
} }
hn, _ := os.Hostname()
return &protos.OperationQueryRequest{ return &protos.OperationQueryRequest{
Hostname: hn, Hostname: hn,
Procs: procs, Procs: procs,
@ -189,7 +208,7 @@ func (hc *houstonClient) makeOperationQueryRequest() *protos.OperationQueryReque
} }
} }
func NewClient() (HoustonClient, error) { func NewClient(standalone bool) (HoustonClient, error) {
clientConfig, err := loadClientConfig() clientConfig, err := loadClientConfig()
if err != nil { if err != nil {
return nil, err return nil, err
@ -238,12 +257,19 @@ func NewClient() (HoustonClient, error) {
} }
} }
ver, _ := os.ReadFile("@version")
if len(ver) == 0 {
ver = []byte("0.0.0")
}
hc := &houstonClient{ hc := &houstonClient{
config: clientConfig, config: clientConfig,
clientChan: make(chan *grpc.ClientConn), clientChan: make(chan *grpc.ClientConn),
extraMetrics: unsafe.Pointer(&map[string]float32{}), extraMetrics: unsafe.Pointer(&map[string]float32{}),
deploys: deploys, deploys: deploys,
timestamp: exefi.ModTime().String(), timestamp: exefi.ModTime().String(),
version: string(ver),
standalone: standalone,
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@ -419,6 +445,8 @@ func (hc *houstonClient) Start() {
var client *grpc.ClientConn var client *grpc.ClientConn
reconnCount := 0 reconnCount := 0
time.Sleep(time.Second)
for { for {
select { select {
case <-hc.ctx.Done(): case <-hc.ctx.Done():

View File

@ -264,6 +264,12 @@ func (hc *houstonClient) prepareUpdateSelf(req *shared.DeployRequest) (srcdir st
return "", "", err return "", "", err
} }
// houston version 파일
err = os.WriteFile(path.Join(fname, "@version"), []byte(req.Version), 0444)
if err != nil {
return "", "", err
}
selfname, _ := os.Executable() selfname, _ := os.Executable()
srcreplacer := path.Join(path.Dir(fname), "replacer") + path.Ext(selfname) srcreplacer := path.Join(path.Dir(fname), "replacer") + path.Ext(selfname)
replacer = "./" + filepath.ToSlash("replacer"+path.Ext(selfname)) replacer = "./" + filepath.ToSlash("replacer"+path.Ext(selfname))

View File

@ -18,7 +18,7 @@ func main() {
} }
if *runAsClient { if *runAsClient {
hc, err := client.NewClient() hc, err := client.NewClient(true)
if err != nil { if err != nil {
logger.Fatal(err) logger.Fatal(err)
return return

View File

@ -6,7 +6,6 @@ import (
"net" "net"
"os" "os"
"sync/atomic" "sync/atomic"
"time"
"repositories.action2quare.com/ayo/gocommon/logger" "repositories.action2quare.com/ayo/gocommon/logger"
"repositories.action2quare.com/ayo/houston/client" "repositories.action2quare.com/ayo/houston/client"
@ -180,13 +179,12 @@ func (hs *houstonServer) Start() error {
closeCount := int32(0) closeCount := int32(0)
var hc client.HoustonClient var hc client.HoustonClient
if loadServerConfig().RunAsClient { if loadServerConfig().RunAsClient {
hc, err = client.NewClient() hc, err = client.NewClient(false)
if err != nil { if err != nil {
return err return err
} }
go func() { go func() {
time.Sleep(time.Second)
hc.Start() hc.Start()
logger.Println("houstonClient is finished") logger.Println("houstonClient is finished")
if atomic.AddInt32(&closeCount, 1) == 1 { if atomic.AddInt32(&closeCount, 1) == 1 {