Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: tag route static config #2304

Merged
merged 13 commits into from
May 30, 2023
Prev Previous commit
Next Next commit
fix test error
  • Loading branch information
wudong5 committed Apr 24, 2023
commit dc718d4e2f54eb49013732008999c9b70b422c49
8 changes: 4 additions & 4 deletions cluster/router/tag/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ func (p *PriorityRouter) Notify(invokers []protocol.Invoker) {
if len(invokers) == 0 {
return
}
service := invokers[0].GetURL().GetParam(constant.ApplicationKey, "")
if service == "" {
logger.Error("url service is empty")
application := invokers[0].GetURL().GetParam(constant.ApplicationKey, "")
if application == "" {
logger.Error("url application is empty")
return
}
dynamicConfiguration := conf.GetEnvInstance().GetDynamicConfiguration()
if dynamicConfiguration == nil {
logger.Warnf("config center does not start, please check if the configuration center has been properly configured in dubbogo.yml")
return
}
key := strings.Join([]string{service, constant.TagRouterRuleSuffix}, "")
key := strings.Join([]string{application, constant.TagRouterRuleSuffix}, "")
dynamicConfiguration.AddListener(key, p)
value, err := dynamicConfiguration.GetRule(key)
if err != nil {
Expand Down
38 changes: 20 additions & 18 deletions cluster/router/tag/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func TestRouter(t *testing.T) {
t.Run("dynamicEmptyTag_requestEmptyTag", func(t *testing.T) {
p, err := NewTagPriorityRouter()
assert.Nil(t, err)
p.routerConfigs.Store(consumerUrl.Service()+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.Service() + constant.TagRouterRuleSuffix,
p.routerConfigs.Store(consumerUrl.GetParam(constant.ApplicationKey, "")+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix,
Force: false,
Enabled: true,
Valid: true,
Expand All @@ -149,8 +149,8 @@ func TestRouter(t *testing.T) {
t.Run("dynamicEmptyTag_requestHasTag", func(t *testing.T) {
p, err := NewTagPriorityRouter()
assert.Nil(t, err)
p.routerConfigs.Store(consumerUrl.Service()+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.Service() + constant.TagRouterRuleSuffix,
p.routerConfigs.Store(consumerUrl.GetParam(constant.ApplicationKey, "")+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix,
Force: false,
Enabled: true,
Valid: true,
Expand All @@ -170,8 +170,8 @@ func TestRouter(t *testing.T) {
t.Run("dynamicTag_requestEmptyTag", func(t *testing.T) {
p, err := NewTagPriorityRouter()
assert.Nil(t, err)
p.routerConfigs.Store(consumerUrl.Service()+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.Service() + constant.TagRouterRuleSuffix,
p.routerConfigs.Store(consumerUrl.GetParam(constant.ApplicationKey, "")+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix,
Force: false,
Enabled: true,
Valid: true,
Expand All @@ -194,8 +194,8 @@ func TestRouter(t *testing.T) {
t.Run("dynamicTag_emptyAddress_requestHasTag", func(t *testing.T) {
p, err := NewTagPriorityRouter()
assert.Nil(t, err)
p.routerConfigs.Store(consumerUrl.Service()+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.Service() + constant.TagRouterRuleSuffix,
p.routerConfigs.Store(consumerUrl.GetParam(constant.ApplicationKey, "")+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix,
Force: false,
Enabled: true,
Valid: true,
Expand All @@ -218,8 +218,8 @@ func TestRouter(t *testing.T) {
t.Run("dynamicTag_address_requestHasTag", func(t *testing.T) {
p, err := NewTagPriorityRouter()
assert.Nil(t, err)
p.routerConfigs.Store(consumerUrl.Service()+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.Service() + constant.TagRouterRuleSuffix,
p.routerConfigs.Store(consumerUrl.GetParam(constant.ApplicationKey, "")+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix,
Force: false,
Enabled: true,
Valid: true,
Expand All @@ -243,8 +243,8 @@ func TestRouter(t *testing.T) {
t.Run("dynamicTag_twoAddress_requestHasTag", func(t *testing.T) {
p, err := NewTagPriorityRouter()
assert.Nil(t, err)
p.routerConfigs.Store(consumerUrl.Service()+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.Service() + constant.TagRouterRuleSuffix,
p.routerConfigs.Store(consumerUrl.GetParam(constant.ApplicationKey, "")+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix,
Force: false,
Enabled: true,
Valid: true,
Expand All @@ -268,8 +268,8 @@ func TestRouter(t *testing.T) {
t.Run("dynamicTag_addressNotMatch_requestHasTag", func(t *testing.T) {
p, err := NewTagPriorityRouter()
assert.Nil(t, err)
p.routerConfigs.Store(consumerUrl.Service()+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.Service() + constant.TagRouterRuleSuffix,
p.routerConfigs.Store(consumerUrl.GetParam(constant.ApplicationKey, "")+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix,
Force: false,
Enabled: true,
Valid: true,
Expand All @@ -293,8 +293,8 @@ func TestRouter(t *testing.T) {
t.Run("dynamicTag_notValid", func(t *testing.T) {
p, err := NewTagPriorityRouter()
assert.Nil(t, err)
p.routerConfigs.Store(consumerUrl.Service()+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.Service() + constant.TagRouterRuleSuffix,
p.routerConfigs.Store(consumerUrl.GetParam(constant.ApplicationKey, "")+constant.TagRouterRuleSuffix, config.RouterConfig{
Key: consumerUrl.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix,
Force: false,
Enabled: true,
Valid: false,
Expand Down Expand Up @@ -338,6 +338,7 @@ func TestNotify(t *testing.T) {
ivk := protocol.NewBaseInvoker(url1)
ivk1 := protocol.NewBaseInvoker(url2)
ivk2 := protocol.NewBaseInvoker(url3)
ivk.GetURL().SetParam(constant.ApplicationKey, "org.apache.dubbo.UserProvider.Test")
invokerList := make([]protocol.Invoker, 0, 3)
invokerList = append(invokerList, ivk)
invokerList = append(invokerList, ivk1)
Expand All @@ -359,7 +360,7 @@ tags:
dc, _ := mockFactory.GetDynamicConfiguration(ccUrl)
common_cfg.GetEnvInstance().SetDynamicConfiguration(dc)
p.Notify(invokerList)
value, ok := p.routerConfigs.Load(url3.Service() + constant.TagRouterRuleSuffix)
value, ok := p.routerConfigs.Load(url1.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix)
assert.True(t, ok)
routerCfg := value.(config.RouterConfig)
assert.True(t, routerCfg.Key == "org.apache.dubbo.UserProvider.Test")
Expand All @@ -374,6 +375,7 @@ tags:
ivk := protocol.NewBaseInvoker(url1)
ivk1 := protocol.NewBaseInvoker(url2)
ivk2 := protocol.NewBaseInvoker(url3)
ivk.GetURL().SetParam(constant.ApplicationKey, "org.apache.dubbo.UserProvider.Test")
invokerList := make([]protocol.Invoker, 0, 3)
invokerList = append(invokerList, ivk)
invokerList = append(invokerList, ivk1)
Expand All @@ -386,7 +388,7 @@ tags:
dc, _ := mockFactory.GetDynamicConfiguration(ccUrl)
common_cfg.GetEnvInstance().SetDynamicConfiguration(dc)
p.Notify(invokerList)
value, ok := p.routerConfigs.Load(url3.Service() + constant.TagRouterRuleSuffix)
value, ok := p.routerConfigs.Load(url1.GetParam(constant.ApplicationKey, "") + constant.TagRouterRuleSuffix)
assert.True(t, ok == false)
assert.True(t, value == nil)
})
Expand Down