Skip to content

Commit

Permalink
perf: Optimize Property Reporting Initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lbbniu committed Jan 11, 2024
1 parent b34089b commit c945e61
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 @@ -170,9 +170,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 = new(StatFHelper)
Expand Down

0 comments on commit c945e61

Please sign in to comment.