Skip to content

Commit

Permalink
Merge pull request #399 from cocowh/fix/reg_group_suffix
Browse files Browse the repository at this point in the history
fix:all groups are appended with RPC_REG_GROUP_SUFFIX
  • Loading branch information
rayzhang0603 authored Jun 11, 2024
2 parents 13c3dc9 + cbff1ba commit db5aa0a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
3 changes: 3 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,9 @@ func (a *Agent) unavailableAllServices() {
func (a *Agent) doExportService(url *motan.URL) {
a.svcLock.Lock()
defer a.svcLock.Unlock()
if _, ok := a.serviceExporters.Load(url.GetIdentityWithRegistry()); ok {
return
}

globalContext := a.Context
exporter := &mserver.DefaultExporter{}
Expand Down
12 changes: 1 addition & 11 deletions core/globalContext.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,21 +553,11 @@ func (c *Context) parseRegGroupSuffix(urlMap map[string]*URL) {
if regGroupSuffix == "" {
return
}
filterMap := make(map[string]struct{}, len(urlMap))
for _, url := range urlMap {
filterMap[url.GetIdentityWithRegistry()] = struct{}{}
}
for k, url := range urlMap {
if strings.HasSuffix(url.Group, regGroupSuffix) {
continue
}
newUrl := url.Copy()
newUrl.Group += regGroupSuffix
if _, ok := filterMap[newUrl.GetIdentityWithRegistry()]; ok {
continue
}
filterMap[newUrl.GetIdentityWithRegistry()] = struct{}{}
urlMap[k] = newUrl
url.Group += regGroupSuffix
}
}

Expand Down
9 changes: 5 additions & 4 deletions core/globalContext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,19 @@ func TestContext_parseRegGroupSuffix(t *testing.T) {
},
AssertFunc: func(t *testing.T, urlMap map[string]*URL) {
groupMap := countGroup(urlMap)
assert.Equal(t, 1, groupMap["group1"])
assert.Equal(t, 1, groupMap["group1"+regGroupSuffix])
assert.Equal(t, 0, groupMap["group1"])
assert.Equal(t, 2, groupMap["group1"+regGroupSuffix])
assert.Equal(t, 1, groupMap["group2"+regGroupSuffix])
assert.Equal(t, 1, groupMap["group3"])
assert.Equal(t, 1, groupMap["group3"+regGroupSuffix])
assert.Equal(t, 0, groupMap["group3"])
assert.Equal(t, 2, groupMap["group3"+regGroupSuffix])
assert.Equal(t, 2, groupMap["group4"+regGroupSuffix])
assert.Equal(t, 2, groupMap["group5"+regGroupSuffix])
},
},
}
os.Setenv(RegGroupSuffix, regGroupSuffix)
ctx := &Context{}
// replace all groups with regGroupSuffix
for _, s := range cases {
ctx.parseRegGroupSuffix(s.UrlMap)
s.AssertFunc(t, s.UrlMap)
Expand Down

0 comments on commit db5aa0a

Please sign in to comment.