mirror of
https://github.com/weaveworks/scope.git
synced 2026-04-19 17:07:30 +00:00
refactor: fix up adjacencies as part of joinResult.result()
This commit is contained in:
@@ -100,8 +100,7 @@ func (c connectionJoin) Render(rpt report.Report) Nodes {
|
||||
}
|
||||
}
|
||||
ret.copyUnmatched(inputNodes)
|
||||
ret.fixupAdjacencies(endpoints)
|
||||
return ret.result()
|
||||
return ret.result(endpoints)
|
||||
}
|
||||
|
||||
// FilterEmpty is a Renderer which filters out nodes which have no children
|
||||
|
||||
@@ -40,8 +40,7 @@ func nodes2Hosts(nodes Nodes) Nodes {
|
||||
})
|
||||
}
|
||||
}
|
||||
ret.fixupAdjacencies(nodes)
|
||||
return ret.result()
|
||||
return ret.result(nodes)
|
||||
}
|
||||
|
||||
// endpoints2Hosts takes nodes from the endpoint topology and produces
|
||||
@@ -68,6 +67,5 @@ func (e endpoints2Hosts) Render(rpt report.Report) Nodes {
|
||||
})
|
||||
}
|
||||
}
|
||||
ret.fixupAdjacencies(endpoints)
|
||||
return ret.result()
|
||||
return ret.result(endpoints)
|
||||
}
|
||||
|
||||
@@ -116,8 +116,7 @@ func (e endpoints2Processes) Render(rpt report.Report) Nodes {
|
||||
}
|
||||
}
|
||||
ret.copyUnmatched(processes)
|
||||
ret.fixupAdjacencies(endpoints)
|
||||
return ret.result()
|
||||
return ret.result(endpoints)
|
||||
}
|
||||
|
||||
// When there is more than one connection originating from a source
|
||||
@@ -161,6 +160,5 @@ func processes2Names(processes Nodes) Nodes {
|
||||
})
|
||||
}
|
||||
}
|
||||
ret.fixupAdjacencies(processes)
|
||||
return ret.result()
|
||||
return ret.result(processes)
|
||||
}
|
||||
|
||||
@@ -202,13 +202,22 @@ func (ret *joinResults) addChildAndChildren(m report.Node, id string, create fun
|
||||
|
||||
// Add a copy of n straight into the results
|
||||
func (ret *joinResults) passThrough(n report.Node) {
|
||||
n.Adjacency = nil // fixupAdjacencies assumes all nodes start with blank lists
|
||||
n.Adjacency = nil // result() assumes all nodes start with blank lists
|
||||
ret.nodes[n.ID] = n
|
||||
ret.mapped[n.ID] = n.ID
|
||||
}
|
||||
|
||||
// Rewrite Adjacency for new nodes in ret for original nodes in input
|
||||
func (ret *joinResults) fixupAdjacencies(input Nodes) {
|
||||
func (ret *joinResults) copyUnmatched(input Nodes) {
|
||||
for _, n := range input.Nodes {
|
||||
if _, found := ret.nodes[n.ID]; !found {
|
||||
ret.nodes[n.ID] = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrite Adjacency of nodes in ret mapped from original nodes in
|
||||
// input, and return the result.
|
||||
func (ret *joinResults) result(input Nodes) Nodes {
|
||||
for _, n := range input.Nodes {
|
||||
outID, ok := ret.mapped[n.ID]
|
||||
if !ok {
|
||||
@@ -224,17 +233,6 @@ func (ret *joinResults) fixupAdjacencies(input Nodes) {
|
||||
}
|
||||
ret.nodes[outID] = out
|
||||
}
|
||||
}
|
||||
|
||||
func (ret *joinResults) copyUnmatched(input Nodes) {
|
||||
for _, n := range input.Nodes {
|
||||
if _, found := ret.nodes[n.ID]; !found {
|
||||
ret.nodes[n.ID] = n
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (ret *joinResults) result() Nodes {
|
||||
return Nodes{Nodes: ret.nodes}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user