Skip to content

Commit

Permalink
Merge pull request #506 from TarsCloud/fix/initproreport
Browse files Browse the repository at this point in the history
perf: Optimize Property Reporting Initialization
  • Loading branch information
lbbniu committed Jan 11, 2024
2 parents 516efe0 + c945e61 commit f5ccfb8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
20 changes: 20 additions & 0 deletions tars/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package tars

import (
"fmt"
"strings"
"time"

"github.com/TarsCloud/TarsGo/tars/util/endpoint"
Expand Down Expand Up @@ -101,6 +103,24 @@ func GetClientConfig() *clientConfig {
return defaultApp.ClientConfig()
}

func (c *clientConfig) ValidateStat() error {
if c.Stat == "" || (c.LocatorEmpty() && !strings.Contains(c.Stat, "@")) {
return fmt.Errorf("stat config emptry")
}
return nil
}

func (c *clientConfig) ValidateProperty() error {
if c.Property == "" || (c.LocatorEmpty() && !strings.Contains(c.Property, "@")) {
return fmt.Errorf("property config emptry")
}
return nil
}

func (c *clientConfig) LocatorEmpty() bool {
return c.Locator == ""
}

// ServerConfig returns server config
func (a *application) ServerConfig() *serverConfig {
a.init()
Expand Down
14 changes: 9 additions & 5 deletions tars/propertyf.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tars

import (
"fmt"
"reflect"
"sort"
"strconv"
Expand Down Expand Up @@ -326,14 +325,19 @@ var (
proOnce utilSync.Once
)

func newPropertyReportHelper(comm *Communicator, node string) *PropertyReportHelper {
p := new(PropertyReportHelper)
p.Init(comm, node)
return p
}

func initProReport() error {
cfg := GetClientConfig()
if cfg.Property == "" || (cfg.Locator == "" && !strings.Contains(cfg.Property, "@")) {
return fmt.Errorf("property emptry")
if err := cfg.ValidateProperty(); err != nil {
return err
}
comm := GetCommunicator()
ProHelper = new(PropertyReportHelper)
ProHelper.Init(comm, GetClientConfig().Property)
ProHelper = newPropertyReportHelper(comm, cfg.Property)
go ProHelper.Run()
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions tars/statf.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ var (

func initReport(app *application) error {
cfg := app.ClientConfig()
if cfg.Stat == "" || (cfg.Locator == "" && !strings.Contains(cfg.Stat, "@")) {
if err := cfg.ValidateStat(); err != nil {
statInited <- struct{}{}
return fmt.Errorf("stat init error")
return err
}
comm := app.Communicator()
StatReport = newStatFHelper(app)
Expand Down

0 comments on commit f5ccfb8

Please sign in to comment.