Use helper to add result nodes in endpoints2Hosts.Render

This means we are no longer generating a Counter for the number of
endpoint sub-nodes, but it seems that data was not used.
This commit is contained in:
Bryan Boreham
2017-11-05 00:14:34 +00:00
parent e16aaf6c43
commit 77a8cac65a

View File

@@ -73,8 +73,6 @@ func (e endpoints2Hosts) Render(rpt report.Report, dct Decorator) report.Nodes {
var ret = make(report.Nodes)
var mapped = map[string]string{} // input node ID -> output node ID
for _, n := range ns {
var result report.Node
var exists bool
// Nodes without a hostid are treated as pseudo nodes
hostNodeID, timestamp, ok := n.Latest.LookupEntry(report.HostNodeID)
if !ok {
@@ -82,23 +80,16 @@ func (e endpoints2Hosts) Render(rpt report.Report, dct Decorator) report.Nodes {
if !ok {
continue
}
result, exists = ret[id]
if !exists {
result = report.MakeNode(id).WithTopology(Pseudo)
}
addToResults(n, id, ret, mapped, func() report.Node {
return report.MakeNode(id).WithTopology(Pseudo)
})
} else {
id := report.MakeHostNodeID(report.ExtractHostID(n))
result, exists = ret[id]
if !exists {
result = report.MakeNode(id).WithTopology(report.Host)
result.Latest = result.Latest.Set(report.HostNodeID, timestamp, hostNodeID)
}
result.Children = result.Children.Merge(n.Children)
addToResults(n, id, ret, mapped, func() report.Node {
return report.MakeNode(id).WithTopology(report.Host).
WithLatest(report.HostNodeID, timestamp, hostNodeID)
})
}
result.Children = result.Children.Add(n)
result.Counters = result.Counters.Add(n.Topology, 1)
ret[result.ID] = result
mapped[n.ID] = result.ID
}
fixupAdjancencies(ns, ret, mapped)
return ret