Refactor: extract pseudoNodeID function

This commit is contained in:
Bryan Boreham
2017-10-17 18:13:54 +00:00
parent d230846b95
commit 1b3e40ccb5
2 changed files with 18 additions and 9 deletions

View File

@@ -45,6 +45,21 @@ func NewDerivedExternalNode(n report.Node, addr string, local report.Networks) (
return NewDerivedPseudoNode(id, n), true
}
func pseudoNodeID(n report.Node, local report.Networks) (string, bool) {
_, addr, _, ok := report.ParseEndpointNodeID(n.ID)
if !ok {
return "", false
}
if id, ok := externalNodeID(n, addr, local); ok {
return id, ok
}
// due to https://github.com/weaveworks/scope/issues/1323 we are dropping
// all non-external pseudo nodes for now.
return "", false
}
// figure out if a node should be considered external and returns an ID which can be used to create a pseudo node
func externalNodeID(n report.Node, addr string, local report.Networks) (string, bool) {
// First, check if it's a known service and emit a a specific node if it

View File

@@ -91,18 +91,12 @@ var ProcessNameRenderer = ConditionalRenderer(renderProcesses,
// MapEndpoint2Pseudo makes internet of host pesudo nodes from a endpoint node.
func MapEndpoint2Pseudo(n report.Node, local report.Networks) report.Nodes {
_, addr, _, ok := report.ParseEndpointNodeID(n.ID)
id, ok := pseudoNodeID(n, local)
if !ok {
return report.Nodes{}
}
if externalNode, ok := NewDerivedExternalNode(n, addr, local); ok {
return report.Nodes{externalNode.ID: externalNode}
}
// due to https://github.com/weaveworks/scope/issues/1323 we are dropping
// all non-external pseudo nodes for now.
return report.Nodes{}
externalNode := NewDerivedPseudoNode(id, n)
return report.Nodes{externalNode.ID: externalNode}
}
// MapEndpoint2Process maps endpoint Nodes to process