Skip to content

Commit

Permalink
fix(registry/nacos): Fixed the bug that NACOS service discovery could…
Browse files Browse the repository at this point in the history
… not obtain all service names, and added the ability to filter interface-level service IDs (#2715)
  • Loading branch information
Allen442 committed Jul 26, 2024
1 parent 6c5fd6d commit fe5afaa
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions registry/nacos/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nacos

import (
"fmt"
"regexp"
"sync"
)

Expand Down Expand Up @@ -122,20 +123,32 @@ func (n *nacosServiceDiscovery) GetDefaultPageSize() int {

// GetServices will return the all services
func (n *nacosServiceDiscovery) GetServices() *gxset.HashSet {
services, err := n.namingClient.Client().GetAllServicesInfo(vo.GetAllServiceInfoParam{
GroupName: n.group,
})

res := gxset.NewSet()
if err != nil {
logger.Errorf("Could not query the services: %v", err)
return res
}

for _, e := range services.Doms {
res.Add(e)
//Filter out interface-level service DataIds
const pattern = `^providers:[\w\.]+(?::[\w\.]*:|::[\w\.]*)?$`
re := regexp.MustCompile(pattern)
for pageNo := uint32(1); ; pageNo++ {
services, err := n.namingClient.Client().GetAllServicesInfo(vo.GetAllServiceInfoParam{
PageSize: uint32(n.GetDefaultPageSize()),
PageNo: pageNo,
GroupName: n.group,
})

if err != nil {
logger.Errorf("Could not query the services: %v", err)
return res
}
for _, e := range services.Doms {
if !re.MatchString(e) {
res.Add(e)
}
}

if int(services.Count) < n.GetDefaultPageSize() {
return res
}
}
return res
}

// GetInstances will return the instances of serviceName and the group
Expand Down

0 comments on commit fe5afaa

Please sign in to comment.