mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-16 03:49:52 +00:00
refactor: replace addEndpointChild with addChild
...and make addChildAndChildren an obvious extension of that even though it adds a dead code path (we never call addChildAndChildren with an endpoint).
This commit is contained in:
@@ -82,7 +82,7 @@ func (c connectionJoin) Render(rpt report.Report) Nodes {
|
||||
// Nodes without a hostid may be pseudo nodes - if so, pass through to result
|
||||
if _, ok := m.Latest.Lookup(report.HostNodeID); !ok {
|
||||
if id, ok := externalNodeID(m, addr, local); ok {
|
||||
ret.addEndpointChild(m, id, newPseudoNode)
|
||||
ret.addChild(m, id, newPseudoNode)
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ func (c connectionJoin) Render(rpt report.Report) Nodes {
|
||||
id, found = ipNodes[report.MakeScopedEndpointNodeID(scope, addr, port)]
|
||||
}
|
||||
if found && id != "" { // not one we blanked out earlier
|
||||
ret.addEndpointChild(m, id, func(id string) report.Node {
|
||||
ret.addChild(m, id, func(id string) report.Node {
|
||||
return inputNodes.Nodes[id]
|
||||
})
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ func (e endpoints2Hosts) Render(rpt report.Report) Nodes {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
ret.addEndpointChild(n, id, newPseudoNode)
|
||||
ret.addChild(n, id, newPseudoNode)
|
||||
} else {
|
||||
id := report.MakeHostNodeID(report.ExtractHostID(n))
|
||||
ret.addEndpointChild(n, id, func(id string) report.Node {
|
||||
ret.addChild(n, id, func(id string) report.Node {
|
||||
return report.MakeNode(id).WithTopology(report.Host).
|
||||
WithLatest(report.HostNodeID, timestamp, hostNodeID)
|
||||
})
|
||||
|
||||
@@ -94,7 +94,7 @@ func (e endpoints2Processes) Render(rpt report.Report) Nodes {
|
||||
// Nodes without a hostid are treated as pseudo nodes
|
||||
if hostNodeID, ok := n.Latest.Lookup(report.HostNodeID); !ok {
|
||||
if id, ok := pseudoNodeID(n, local); ok {
|
||||
ret.addEndpointChild(n, id, newPseudoNode)
|
||||
ret.addChild(n, id, newPseudoNode)
|
||||
}
|
||||
} else {
|
||||
pid, timestamp, ok := n.Latest.LookupEntry(process.PID)
|
||||
@@ -111,7 +111,7 @@ func (e endpoints2Processes) Render(rpt report.Report) Nodes {
|
||||
|
||||
hostID, _, _ := report.ParseNodeID(hostNodeID)
|
||||
id := report.MakeProcessNodeID(hostID, pid)
|
||||
ret.addEndpointChild(n, id, func(id string) report.Node {
|
||||
ret.addChild(n, id, func(id string) report.Node {
|
||||
if processNode, found := processes.Nodes[id]; found {
|
||||
return processNode
|
||||
}
|
||||
|
||||
@@ -158,34 +158,22 @@ func newJoinResults() joinResults {
|
||||
return joinResults{nodes: make(report.Nodes), mapped: map[string]string{}}
|
||||
}
|
||||
|
||||
// Add Endpoint Node m under id, creating a new result node if not already there
|
||||
// and updating the mapping from old ID to new ID
|
||||
// Note we do not update any counters for child topologies here because we never look at endpoint counts
|
||||
func (ret *joinResults) addEndpointChild(m report.Node, id string, create func(string) report.Node) {
|
||||
result, exists := ret.nodes[id]
|
||||
if !exists {
|
||||
result = create(id)
|
||||
}
|
||||
result.Children = result.Children.Add(m)
|
||||
ret.nodes[id] = result
|
||||
ret.mapped[m.ID] = id
|
||||
}
|
||||
|
||||
// Add Node m as a child of the node at id, creating a new result node if not already there
|
||||
// incrementing a count of the topology, and updating the mapping from old ID to new ID
|
||||
// Add m as a child of the node at id, creating a new result node if
|
||||
// not already there, and updating the mapping from old ID to new ID.
|
||||
func (ret *joinResults) addChild(m report.Node, id string, create func(string) report.Node) {
|
||||
result, exists := ret.nodes[id]
|
||||
if !exists {
|
||||
result = create(id)
|
||||
}
|
||||
result.Children = result.Children.Add(m)
|
||||
result.Counters = result.Counters.Add(m.Topology, 1)
|
||||
if m.Topology != report.Endpoint { // optimisation: we never look at endpoint counts
|
||||
result.Counters = result.Counters.Add(m.Topology, 1)
|
||||
}
|
||||
ret.nodes[id] = result
|
||||
ret.mapped[m.ID] = id
|
||||
}
|
||||
|
||||
// Add m and its children as children under id, creating a new result node if not already there,
|
||||
// incrementing a count of the topology, and updating the mapping from old ID to new ID
|
||||
// Like addChild, but also add m's children.
|
||||
func (ret *joinResults) addChildAndChildren(m report.Node, id string, create func(string) report.Node) {
|
||||
result, exists := ret.nodes[id]
|
||||
if !exists {
|
||||
@@ -193,7 +181,9 @@ func (ret *joinResults) addChildAndChildren(m report.Node, id string, create fun
|
||||
}
|
||||
result.Children = result.Children.Add(m)
|
||||
result.Children = result.Children.Merge(m.Children)
|
||||
result.Counters = result.Counters.Add(m.Topology, 1)
|
||||
if m.Topology != report.Endpoint { // optimisation: we never look at endpoint counts
|
||||
result.Counters = result.Counters.Add(m.Topology, 1)
|
||||
}
|
||||
ret.nodes[id] = result
|
||||
ret.mapped[m.ID] = id
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user