Skip to content

Commit

Permalink
Dedup services.
Browse files Browse the repository at this point in the history
  • Loading branch information
apollo13 authored and Chris S. Kim committed Jul 28, 2023
1 parent 3ed5e11 commit abbea8f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions agent/consul/state/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -4584,6 +4584,7 @@ func (s *Store) combinedServiceNodesTxn(tx ReadTxn, ws memdb.WatchSet, names []s
maxIdx uint64
resp structs.CheckServiceNodes
)
dedupMap := make(map[string]structs.CheckServiceNode)
for _, u := range names {
// Collect typical then connect instances
idx, csn, err := checkServiceNodesTxn(tx, ws, u.Name, false, &u.EnterpriseMeta, peerName)
Expand All @@ -4593,7 +4594,9 @@ func (s *Store) combinedServiceNodesTxn(tx ReadTxn, ws memdb.WatchSet, names []s
if idx > maxIdx {
maxIdx = idx
}
resp = append(resp, csn...)
for _, item := range csn {
dedupMap[item.Node.Node+"/"+item.Service.ID] = item
}

idx, csn, err = checkServiceNodesTxn(tx, ws, u.Name, true, &u.EnterpriseMeta, peerName)
if err != nil {
Expand All @@ -4602,7 +4605,12 @@ func (s *Store) combinedServiceNodesTxn(tx ReadTxn, ws memdb.WatchSet, names []s
if idx > maxIdx {
maxIdx = idx
}
resp = append(resp, csn...)
for _, item := range csn {
dedupMap[item.Node.Node+"/"+item.Service.ID] = item
}
}
for _, item := range dedupMap {
resp = append(resp, item)
}
return maxIdx, resp, nil
}
Expand Down
4 changes: 2 additions & 2 deletions agent/ui_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2165,8 +2165,8 @@ func TestUIServiceTopology(t *testing.T) {
Name: "cproxy",
Datacenter: "dc1",
Tags: []string{"http", "https"},
Nodes: []string{"cnative", "cnative", "cnative"},
InstanceCount: 3,
Nodes: []string{"cnative", "cnative"},
InstanceCount: 2,
ChecksPassing: 3,
ChecksWarning: 0,
ChecksCritical: 0,
Expand Down

0 comments on commit abbea8f

Please sign in to comment.