Service Map node key as entry.Name instead of entry.IP (#818)

This commit is contained in:
Gustavo Massaneiro
2022-02-16 04:01:59 -03:00
committed by GitHub
parent 5dfa94d76e
commit bb3ae1ef70
3 changed files with 44 additions and 18 deletions

View File

@@ -102,13 +102,13 @@ func (s *ServiceMapControllerSuite) TestGet() {
// response nodes // response nodes
aNode := servicemap.ServiceMapNode{ aNode := servicemap.ServiceMapNode{
Id: 1, Id: 1,
Name: TCPEntryA.IP, Name: TCPEntryA.Name,
Entry: TCPEntryA, Entry: TCPEntryA,
Count: 1, Count: 1,
} }
bNode := servicemap.ServiceMapNode{ bNode := servicemap.ServiceMapNode{
Id: 2, Id: 2,
Name: TCPEntryB.IP, Name: TCPEntryB.Name,
Entry: TCPEntryB, Entry: TCPEntryB,
Count: 1, Count: 1,
} }

View File

@@ -172,20 +172,33 @@ func (s *serviceMap) NewTCPEntry(src *tapApi.TCP, dst *tapApi.TCP, p *tapApi.Pro
return return
} }
srcEntry := &entryData{ var srcEntry *entryData
key: key(src.IP), var dstEntry *entryData
entry: src,
} if len(src.Name) == 0 {
if len(srcEntry.entry.Name) == 0 { srcEntry = &entryData{
key: key(src.IP),
entry: src,
}
srcEntry.entry.Name = UnresolvedNodeName srcEntry.entry.Name = UnresolvedNodeName
} else {
srcEntry = &entryData{
key: key(src.Name),
entry: src,
}
} }
dstEntry := &entryData{ if len(dst.Name) == 0 {
key: key(dst.IP), dstEntry = &entryData{
entry: dst, key: key(dst.IP),
} entry: dst,
if len(dstEntry.entry.Name) == 0 { }
dstEntry.entry.Name = UnresolvedNodeName dstEntry.entry.Name = UnresolvedNodeName
} else {
dstEntry = &entryData{
key: key(dst.Name),
entry: dst,
}
} }
s.addEdge(srcEntry, dstEntry, p) s.addEdge(srcEntry, dstEntry, p)

View File

@@ -268,9 +268,14 @@ func (s *ServiceMapEnabledSuite) TestServiceMap() {
assert.LessOrEqual(node.Id, expectedNodeCount) assert.LessOrEqual(node.Id, expectedNodeCount)
// entry // entry
// node.Name is the key of the node, key = entry.IP // node.Name is the key of the node, key = entry.Name by default
// entry.Name is the name of the service and could be unresolved // entry.Name is the name of the service and could be unresolved
assert.Equal(node.Name, node.Entry.IP) // when entry.Name is unresolved, key = entry.IP
if node.Entry.Name == UnresolvedNodeName {
assert.Equal(node.Name, node.Entry.IP)
} else {
assert.Equal(node.Name, node.Entry.Name)
}
assert.Equal(Port, node.Entry.Port) assert.Equal(Port, node.Entry.Port)
assert.Equal(entryName, node.Entry.Name) assert.Equal(entryName, node.Entry.Name)
@@ -320,16 +325,24 @@ func (s *ServiceMapEnabledSuite) TestServiceMap() {
cdEdge := -1 cdEdge := -1
acEdge := -1 acEdge := -1
var validateEdge = func(edge ServiceMapEdge, sourceEntryName string, destEntryName string, protocolName string, protocolCount int) { var validateEdge = func(edge ServiceMapEdge, sourceEntryName string, destEntryName string, protocolName string, protocolCount int) {
// source // source node
assert.Contains(nodeIds, edge.Source.Id) assert.Contains(nodeIds, edge.Source.Id)
assert.LessOrEqual(edge.Source.Id, expectedNodeCount) assert.LessOrEqual(edge.Source.Id, expectedNodeCount)
assert.Equal(edge.Source.Name, edge.Source.Entry.IP) if edge.Source.Entry.Name == UnresolvedNodeName {
assert.Equal(edge.Source.Name, edge.Source.Entry.IP)
} else {
assert.Equal(edge.Source.Name, edge.Source.Entry.Name)
}
assert.Equal(sourceEntryName, edge.Source.Entry.Name) assert.Equal(sourceEntryName, edge.Source.Entry.Name)
// destination // destination node
assert.Contains(nodeIds, edge.Destination.Id) assert.Contains(nodeIds, edge.Destination.Id)
assert.LessOrEqual(edge.Destination.Id, expectedNodeCount) assert.LessOrEqual(edge.Destination.Id, expectedNodeCount)
assert.Equal(edge.Destination.Name, edge.Destination.Entry.IP) if edge.Destination.Entry.Name == UnresolvedNodeName {
assert.Equal(edge.Destination.Name, edge.Destination.Entry.IP)
} else {
assert.Equal(edge.Destination.Name, edge.Destination.Entry.Name)
}
assert.Equal(destEntryName, edge.Destination.Entry.Name) assert.Equal(destEntryName, edge.Destination.Entry.Name)
// protocol // protocol