mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
optimise & simplify node propagation in joinResult
Instead of copying unmatched nodes at the end, and matched nodes when we encounter them, copy *all* nodes at the beginning.
This commit is contained in:
@@ -71,7 +71,7 @@ func (c connectionJoin) Render(rpt report.Report) Nodes {
|
||||
}
|
||||
}
|
||||
}
|
||||
ret := newJoinResults()
|
||||
ret := newJoinResults(inputNodes.Nodes)
|
||||
|
||||
// Now look at all the endpoints and see which map to IP nodes
|
||||
for _, m := range endpoints.Nodes {
|
||||
@@ -99,7 +99,6 @@ func (c connectionJoin) Render(rpt report.Report) Nodes {
|
||||
})
|
||||
}
|
||||
}
|
||||
ret.copyUnmatched(inputNodes)
|
||||
return ret.result(endpoints)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ var HostRenderer = MakeReduce(
|
||||
// not have enough info to do that, and the resulting graph must be
|
||||
// merged with a host graph to get that info.
|
||||
func nodes2Hosts(nodes Nodes) Nodes {
|
||||
ret := newJoinResults()
|
||||
ret := newJoinResults(nil)
|
||||
|
||||
for _, n := range nodes.Nodes {
|
||||
if n.Topology == Pseudo {
|
||||
@@ -51,7 +51,7 @@ func (e endpoints2Hosts) Render(rpt report.Report) Nodes {
|
||||
local := LocalNetworks(rpt)
|
||||
hosts := SelectHost.Render(rpt)
|
||||
endpoints := SelectEndpoint.Render(rpt)
|
||||
ret := newJoinResults()
|
||||
ret := newJoinResults(hosts.Nodes)
|
||||
|
||||
for _, n := range endpoints.Nodes {
|
||||
// Nodes without a hostid are treated as pseudo nodes
|
||||
@@ -72,6 +72,5 @@ func (e endpoints2Hosts) Render(rpt report.Report) Nodes {
|
||||
})
|
||||
}
|
||||
}
|
||||
ret.copyUnmatched(hosts)
|
||||
return ret.result(endpoints)
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ func (e endpoints2Processes) Render(rpt report.Report) Nodes {
|
||||
local := LocalNetworks(rpt)
|
||||
processes := SelectProcess.Render(rpt)
|
||||
endpoints := SelectEndpoint.Render(rpt)
|
||||
ret := newJoinResults()
|
||||
ret := newJoinResults(processes.Nodes)
|
||||
|
||||
for _, n := range endpoints.Nodes {
|
||||
// Nodes without a hostid are treated as pseudo nodes
|
||||
@@ -115,7 +115,6 @@ func (e endpoints2Processes) Render(rpt report.Report) Nodes {
|
||||
})
|
||||
}
|
||||
}
|
||||
ret.copyUnmatched(processes)
|
||||
return ret.result(endpoints)
|
||||
}
|
||||
|
||||
@@ -148,7 +147,7 @@ func hasMoreThanOneConnection(n report.Node, endpoints report.Nodes) bool {
|
||||
|
||||
// processes2Names maps process Nodes to Nodes for each process name.
|
||||
func processes2Names(processes Nodes) Nodes {
|
||||
ret := newJoinResults()
|
||||
ret := newJoinResults(nil)
|
||||
|
||||
for _, n := range processes.Nodes {
|
||||
if n.Topology == Pseudo {
|
||||
|
||||
@@ -166,8 +166,12 @@ type joinResults struct {
|
||||
mapped map[string]string // input node ID -> output node ID
|
||||
}
|
||||
|
||||
func newJoinResults() joinResults {
|
||||
return joinResults{nodes: make(report.Nodes), mapped: map[string]string{}}
|
||||
func newJoinResults(inputNodes report.Nodes) joinResults {
|
||||
nodes := make(report.Nodes, len(inputNodes))
|
||||
for id, n := range inputNodes {
|
||||
nodes[id] = n
|
||||
}
|
||||
return joinResults{nodes: nodes, mapped: map[string]string{}}
|
||||
}
|
||||
|
||||
// Add m as a child of the node at id, creating a new result node if
|
||||
@@ -207,14 +211,6 @@ func (ret *joinResults) passThrough(n report.Node) {
|
||||
ret.mapped[n.ID] = n.ID
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user