Skip to content

Commit

Permalink
feat:support user custom sdk labels (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Jan 8, 2024
1 parent 95fc087 commit c316572
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 38 deletions.
27 changes: 20 additions & 7 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"sync/atomic"
"time"

"github.com/google/uuid"
"github.com/hashicorp/go-multierror"
"github.com/modern-go/reflect2"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -261,20 +260,21 @@ func InitContextByConfig(cfg config.Configuration) (SDKContext, error) {
if err := cfg.Verify(); err != nil {
return nil, model.NewSDKError(model.ErrCodeAPIInvalidConfig, err, "fail to verify input config")
}
getSelfIP(cfg)
token := model.SDKToken{
initSelfIP(cfg)
token := &model.SDKToken{
IP: cfg.GetGlobal().GetAPI().GetBindIP(),
PID: int32(os.Getpid()),
UID: strings.ToUpper(uuid.New().String()),
Client: version.ClientType,
Version: version.Version,
PodName: getPodName(),
HostName: getHostName(),
}
token.InitUID()
initSelfLabels(cfg, token)
log.GetBaseLogger().Infof("\n-------Start to init SDKContext of version %s, IP: %s, PID: %d, UID: %s, CONTAINER: "+"%s, HOSTNAME:%s-------",
version.Version, token.IP, token.PID, token.UID, token.PodName, token.HostName)

globalCtx.SetValue(model.ContextKeyToken, token)
globalCtx.SetValue(model.ContextKeyToken, *token)
plugManager := plugin.NewPluginManager()
globalCtx.SetValue(model.ContextKeyPlugins, plugManager)
connManager, err := network.NewConnectionManager(cfg, globalCtx)
Expand Down Expand Up @@ -321,8 +321,8 @@ func InitContextByConfig(cfg config.Configuration) (SDKContext, error) {
return ctx, nil
}

// getSelfIP 获取SDK自身的IP
func getSelfIP(cfg config.Configuration) {
// initSelfIP 获取SDK自身的IP
func initSelfIP(cfg config.Configuration) {
bindIP := cfg.GetGlobal().GetAPI().GetBindIP()
bindIntf := cfg.GetGlobal().GetAPI().GetBindIntf()
if len(bindIP) != 0 || len(bindIntf) != 0 {
Expand All @@ -346,6 +346,19 @@ func getSelfIP(cfg config.Configuration) {
}
}

func initSelfLabels(cfg config.Configuration, sdkToken *model.SDKToken) {
clientCfg := cfg.GetGlobal().GetClient().(*config.ClientConfigImpl)
if clientCfg.GetId() == "" {
clientCfg.SetId(sdkToken.UID)
}
clientCfg.AddLabels(map[string]string{
"CLIENT_IP": cfg.GetGlobal().GetAPI().GetBindIP(),
"CLIENT_ID": clientCfg.GetId(),
"CLIENT_VERSION": sdkToken.Version,
"CLIENT_LANGUAGE": sdkToken.Client,
})
}

// onContextInitialized 在全局上下文初始化完成后,触发事件回调,可针对不同插件做一些阻塞等待某个事件完成的操作
func onContextInitialized(ctx SDKContext) error {
eventHandlers := ctx.GetPlugins().GetEventSubscribers(common.OnContextStarted)
Expand Down
5 changes: 0 additions & 5 deletions examples/configuration/crud/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -320,7 +319,6 @@ github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99
github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c=
github.com/googleapis/gax-go/v2 v2.5.1/go.mod h1:h6B0KMMFNtI2ddbGJn3T3ZbwkeT6yqEF02fYlzkUCyo=
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
Expand All @@ -338,7 +336,6 @@ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
Expand Down Expand Up @@ -401,9 +398,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
Expand Down
2 changes: 1 addition & 1 deletion examples/configuration/normal/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polarismesh/specification v1.3.2-alpha.2 // indirect
github.com/polarismesh/specification v1.4.1 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
Expand Down
9 changes: 2 additions & 7 deletions examples/configuration/normal/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down Expand Up @@ -321,7 +320,6 @@ github.com/googleapis/gax-go/v2 v2.3.0/go.mod h1:b8LNqSzNabLiUpXKkY7HAR5jr6bIT99
github.com/googleapis/gax-go/v2 v2.4.0/go.mod h1:XOTVJ59hdnfJLIP/dh8n5CGryZR2LxK9wbMD5+iXC6c=
github.com/googleapis/gax-go/v2 v2.5.1/go.mod h1:h6B0KMMFNtI2ddbGJn3T3ZbwkeT6yqEF02fYlzkUCyo=
github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
Expand All @@ -340,7 +338,6 @@ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
Expand Down Expand Up @@ -375,8 +372,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/polarismesh/specification v1.3.2-alpha.2 h1:cMghyvCnRVM5ca2kYCGHOgIIxVnokiMvw0720q8a8RA=
github.com/polarismesh/specification v1.3.2-alpha.2/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/polarismesh/specification v1.4.1 h1:lTZqeyUhhWuKyr6NDKBwmUrNfcUDvKLxWT/uOq71T5A=
github.com/polarismesh/specification v1.4.1/go.mod h1:rDvMMtl5qebPmqiBLNa5Ps0XtwkP31ZLirbH4kXA0YU=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
Expand Down Expand Up @@ -404,9 +401,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
github.com/smartystreets/goconvey v1.7.2 h1:9RBaZCeXEQ3UselpuwUQHltGVXvdwm6cv1hgR6gDIPg=
github.com/smartystreets/goconvey v1.7.2/go.mod h1:Vw0tHAZW6lzCRk3xgdin6fKYcG+G3Pg9vgXWeJpQFMM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
Expand Down
3 changes: 3 additions & 0 deletions examples/configuration/normal/polaris.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ global:
serverConnector:
addresses:
- 127.0.0.1:8091
client:
labels:
env: pre
config:
configConnector:
addresses:
Expand Down
12 changes: 11 additions & 1 deletion pkg/config/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ type GlobalConfig interface {
GetStatReporter() StatReporterConfig
// GetLocation global.location前缀开头的所有配置项
GetLocation() LocationConfig
// GetClient global.client前缀开头的所有配置项
GetClient() ClientConfig
}

// ConsumerConfig consumer config object.
Expand Down Expand Up @@ -213,10 +215,18 @@ type LocationConfig interface {
BaseConfig
// GetProvider 获取地理位置的提供者插件名称
GetProviders() []*LocationProviderConfigImpl

// GetProvider 根据类型名称获取对应插件的配置内容信息
GetProvider(typ string) *LocationProviderConfigImpl
}

type ClientConfig interface {
BaseConfig
// GetId 获取客户端ID
GetId() string
// GetLabels 获取客户端标签
GetLabels() map[string]string
}

// ServerConnectorConfig 与名字服务服务端的连接配置.
type ServerConnectorConfig interface {
BaseConfig
Expand Down
50 changes: 50 additions & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ func (g *GlobalConfigImpl) Init() {
g.StatReporter.Init()
g.Location = &LocationConfigImpl{}
g.Location.Init()
g.Client = &ClientConfigImpl{}
g.Client.Init()
}

// Init 初始化ConsumerConfigImpl.
Expand Down Expand Up @@ -616,3 +618,51 @@ func (s *ServerClusterConfigImpl) Verify() error {
}
return errs
}

type ClientConfigImpl struct {
ID string `yaml:"id" json:"id"`
Labels map[string]string `yaml:"labels" json:"labels"`
}

// Init 初始化
func (c *ClientConfigImpl) Init() {
}

func (c *ClientConfigImpl) SetId(id string) {
c.ID = id
}

func (c *ClientConfigImpl) GetId() string {
return c.ID
}

func (c *ClientConfigImpl) SetLabels(m map[string]string) {
c.Labels = m
}

func (c *ClientConfigImpl) AddLabels(m map[string]string) {
if len(c.Labels) == 0 {
c.Labels = map[string]string{}
}
for k, v := range m {
c.Labels[k] = v
}
}

func (c *ClientConfigImpl) GetLabels() map[string]string {
copyM := map[string]string{}
for k, v := range c.Labels {
copyM[k] = v
}
return copyM
}

func (c *ClientConfigImpl) SetDefault() {
if len(c.Labels) == 0 {
c.Labels = map[string]string{}
}
}

func (c *ClientConfigImpl) Verify() error {
return nil
}
6 changes: 6 additions & 0 deletions pkg/config/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type GlobalConfigImpl struct {
ServerConnector *ServerConnectorConfigImpl `yaml:"serverConnector" json:"serverConnector"`
StatReporter *StatReporterConfigImpl `yaml:"statReporter" json:"statReporter"`
Location *LocationConfigImpl `yaml:"location" json:"location"`
Client *ClientConfigImpl `yaml:"client" json:"client"`
}

// GetSystem 获取系统配置.
Expand Down Expand Up @@ -91,6 +92,11 @@ func (g *GlobalConfigImpl) GetLocation() LocationConfig {
return g.Location
}

// GetClient global.client前缀开头的所有配置项.
func (g *GlobalConfigImpl) GetClient() ClientConfig {
return g.Client
}

// ConsumerConfigImpl 消费者配置.
type ConsumerConfigImpl struct {
LocalCache *LocalCacheConfigImpl `yaml:"localCache" json:"localCache"`
Expand Down
20 changes: 10 additions & 10 deletions pkg/flow/configuration/config_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ type ConfigFileFlow struct {
configFilePool map[string]*ConfigFileRepo
notifiedVersion map[string]uint64

connector configconnector.ConfigConnector
chain configfilter.Chain
configuration config.Configuration
connector configconnector.ConfigConnector
chain configfilter.Chain
conf config.Configuration

persistHandler *CachePersistHandler

Expand All @@ -54,12 +54,12 @@ type ConfigFileFlow struct {

// NewConfigFileFlow 创建配置中心服务
func NewConfigFileFlow(connector configconnector.ConfigConnector, chain configfilter.Chain,
configuration config.Configuration) (*ConfigFileFlow, error) {
conf config.Configuration) (*ConfigFileFlow, error) {
persistHandler, err := NewCachePersistHandler(
configuration.GetConfigFile().GetLocalCache().GetPersistDir(),
configuration.GetConfigFile().GetLocalCache().GetPersistMaxWriteRetry(),
configuration.GetConfigFile().GetLocalCache().GetPersistMaxReadRetry(),
configuration.GetConfigFile().GetLocalCache().GetPersistRetryInterval(),
conf.GetConfigFile().GetLocalCache().GetPersistDir(),
conf.GetConfigFile().GetLocalCache().GetPersistMaxWriteRetry(),
conf.GetConfigFile().GetLocalCache().GetPersistMaxReadRetry(),
conf.GetConfigFile().GetLocalCache().GetPersistRetryInterval(),
)
if err != nil {
return nil, err
Expand All @@ -68,7 +68,7 @@ func NewConfigFileFlow(connector configconnector.ConfigConnector, chain configfi
configFileService := &ConfigFileFlow{
connector: connector,
chain: chain,
configuration: configuration,
conf: conf,
repos: make([]*ConfigFileRepo, 0, 8),
configFileCache: map[string]model.ConfigFile{},
configFilePool: map[string]*ConfigFileRepo{},
Expand Down Expand Up @@ -112,7 +112,7 @@ func (c *ConfigFileFlow) GetConfigFile(req *model.GetConfigFileRequest) (model.C
return configFile, nil
}

fileRepo, err := newConfigFileRepo(configFileMetadata, c.connector, c.chain, c.configuration, c.persistHandler)
fileRepo, err := newConfigFileRepo(configFileMetadata, c.connector, c.chain, c.conf, c.persistHandler)
if err != nil {
return nil, err
}
Expand Down
19 changes: 13 additions & 6 deletions pkg/flow/configuration/file_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ var (

// ConfigFileRepo 服务端配置文件代理类,从服务端拉取配置并同步数据
type ConfigFileRepo struct {
connector configconnector.ConfigConnector
chain configfilter.Chain
configuration config.Configuration
connector configconnector.ConfigConnector
chain configfilter.Chain
conf config.Configuration

configFileMetadata model.ConfigFileMetadata
// 长轮询通知的版本号
Expand All @@ -71,12 +71,12 @@ type ConfigFileRepoChangeListener func(configFileMetadata model.ConfigFileMetada
func newConfigFileRepo(metadata model.ConfigFileMetadata,
connector configconnector.ConfigConnector,
chain configfilter.Chain,
configuration config.Configuration,
conf config.Configuration,
persistHandler *CachePersistHandler) (*ConfigFileRepo, error) {
repo := &ConfigFileRepo{
connector: connector,
chain: chain,
configuration: configuration,
conf: conf,
configFileMetadata: metadata,
notifiedVersion: initVersion,
retryPolicy: retryPolicy{
Expand All @@ -85,7 +85,7 @@ func newConfigFileRepo(metadata model.ConfigFileMetadata,
},
remoteConfigFileRef: &atomic.Value{},
persistHandler: persistHandler,
fallbackToLocalCache: configuration.GetConfigFile().GetLocalCache().IsFallbackToLocalCache(),
fallbackToLocalCache: conf.GetConfigFile().GetLocalCache().IsFallbackToLocalCache(),
}
repo.remoteConfigFileRef.Store(&configconnector.ConfigFile{
Namespace: metadata.GetNamespace(),
Expand Down Expand Up @@ -143,6 +143,13 @@ func (r *ConfigFileRepo) pull() error {
FileGroup: r.configFileMetadata.GetFileGroup(),
FileName: r.configFileMetadata.GetFileName(),
Version: r.notifiedVersion,
Tags: make([]*configconnector.ConfigFileTag, 0, len(r.conf.GetGlobal().GetClient().GetLabels())),
}
for k, v := range r.conf.GetGlobal().GetClient().GetLabels() {
pullConfigFileReq.Tags = append(pullConfigFileReq.Tags, &configconnector.ConfigFileTag{
Key: k,
Value: v,
})
}

log.GetBaseLogger().Infof("[Config] start pull config file. config file = %+v, version = %d",
Expand Down
Loading

0 comments on commit c316572

Please sign in to comment.