mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-02 17:50:39 +00:00
New type joinResult is created to hold the nodes and ID mapping. The implementation move from host.go to render.go.
98 lines
2.3 KiB
Go
98 lines
2.3 KiB
Go
package render
|
|
|
|
import (
|
|
"github.com/weaveworks/scope/report"
|
|
)
|
|
|
|
// HostRenderer is a Renderer which produces a renderable host
|
|
// graph from the host topology.
|
|
//
|
|
// not memoised
|
|
var HostRenderer = MakeReduce(
|
|
endpoints2Hosts{},
|
|
MakeMap(
|
|
MapX2Host,
|
|
ColorConnectedProcessRenderer,
|
|
),
|
|
MakeMap(
|
|
MapX2Host,
|
|
ContainerRenderer,
|
|
),
|
|
MakeMap(
|
|
MapX2Host,
|
|
ContainerImageRenderer,
|
|
),
|
|
MakeMap(
|
|
MapX2Host,
|
|
PodRenderer,
|
|
),
|
|
SelectHost,
|
|
)
|
|
|
|
// MapX2Host maps any Nodes to host Nodes.
|
|
//
|
|
// If this function is given a node without a hostname
|
|
// (including other pseudo nodes), it will drop the node.
|
|
//
|
|
// Otherwise, this function will produce nodes with the correct ID
|
|
// format for a host, but without any Major or Minor labels. It does
|
|
// not have enough info to do that, and the resulting graph must be
|
|
// merged with a host graph to get that info.
|
|
func MapX2Host(n report.Node, _ report.Networks) report.Nodes {
|
|
// Don't propagate pseudo nodes - we do this in MapEndpoint2Host
|
|
if n.Topology == Pseudo {
|
|
return report.Nodes{}
|
|
}
|
|
|
|
hostIDs, ok := n.Parents.Lookup(report.Host)
|
|
if !ok {
|
|
return report.Nodes{}
|
|
}
|
|
|
|
result := report.Nodes{}
|
|
children := report.MakeNodeSet(n)
|
|
for _, id := range hostIDs {
|
|
node := NewDerivedNode(id, n).WithTopology(report.Host)
|
|
node.Counters = node.Counters.Add(n.Topology, 1)
|
|
node.Children = children
|
|
result[id] = node
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
// endpoints2Hosts takes nodes from the endpoint topology and produces
|
|
// host nodes or pseudo nodes.
|
|
type endpoints2Hosts struct {
|
|
}
|
|
|
|
func (e endpoints2Hosts) Render(rpt report.Report, dct Decorator) report.Nodes {
|
|
ns := SelectEndpoint.Render(rpt, dct)
|
|
local := LocalNetworks(rpt)
|
|
ret := newJoinResults()
|
|
|
|
for _, n := range ns {
|
|
// Nodes without a hostid are treated as pseudo nodes
|
|
hostNodeID, timestamp, ok := n.Latest.LookupEntry(report.HostNodeID)
|
|
if !ok {
|
|
id, ok := pseudoNodeID(n, local)
|
|
if !ok {
|
|
continue
|
|
}
|
|
ret.addToResults(n, id, newPseudoNode)
|
|
} else {
|
|
id := report.MakeHostNodeID(report.ExtractHostID(n))
|
|
ret.addToResults(n, id, func(id string) report.Node {
|
|
return report.MakeNode(id).WithTopology(report.Host).
|
|
WithLatest(report.HostNodeID, timestamp, hostNodeID)
|
|
})
|
|
}
|
|
}
|
|
ret.fixupAdjacencies(ns)
|
|
return ret.nodes
|
|
}
|
|
|
|
func (e endpoints2Hosts) Stats(rpt report.Report, _ Decorator) Stats {
|
|
return Stats{} // nothing to report
|
|
}
|