Move DNS name mapping from endpoint to report

This commit is contained in:
Bryan Boreham
2018-02-06 13:08:57 +00:00
parent 6674ff61e5
commit b5cdcb9a42
7 changed files with 135 additions and 42 deletions

View File

@@ -73,7 +73,7 @@ func newConnectionCounters() *connectionCounters {
return &connectionCounters{counted: map[string]struct{}{}, counts: map[connection]int{}}
}
func (c *connectionCounters) add(outgoing bool, localNode, remoteNode, localEndpoint, remoteEndpoint report.Node) {
func (c *connectionCounters) add(dns report.DNSRecords, outgoing bool, localNode, remoteNode, localEndpoint, remoteEndpoint report.Node) {
// We identify connections by their source endpoint, pre-NAT, to
// ensure we only count them once.
srcEndpoint, dstEndpoint := remoteEndpoint, localEndpoint
@@ -94,10 +94,10 @@ func (c *connectionCounters) add(outgoing bool, localNode, remoteNode, localEndp
return
}
// For internet nodes we break out individual addresses
if conn.remoteAddr, ok = internetAddr(remoteNode, remoteEndpoint); !ok {
if conn.remoteAddr, ok = internetAddr(dns, remoteNode, remoteEndpoint); !ok {
return
}
if conn.localAddr, ok = internetAddr(localNode, localEndpoint); !ok {
if conn.localAddr, ok = internetAddr(dns, localNode, localEndpoint); !ok {
return
}
@@ -105,7 +105,7 @@ func (c *connectionCounters) add(outgoing bool, localNode, remoteNode, localEndp
c.counts[conn]++
}
func internetAddr(node report.Node, ep report.Node) (string, bool) {
func internetAddr(dns report.DNSRecords, node report.Node, ep report.Node) (string, bool) {
if !render.IsInternetNode(node) {
return "", true
}
@@ -113,7 +113,7 @@ func internetAddr(node report.Node, ep report.Node) (string, bool) {
if !ok {
return "", false
}
if name, found := render.DNSFirstMatch(ep, func(string) bool { return true }); found {
if name, found := dns.FirstMatch(ep.ID, func(string) bool { return true }); found {
// we show the "most important" name only, since we don't have
// space for more
addr = fmt.Sprintf("%s (%s)", name, addr)
@@ -171,7 +171,7 @@ func incomingConnectionsSummary(topologyID string, r report.Report, n report.Nod
for _, remoteEndpoint := range endpointChildrenOf(node) {
for _, localEndpointID := range remoteEndpoint.Adjacency.Intersection(localEndpointIDs) {
localEndpointID = canonicalEndpointID(localEndpointIDCopies, localEndpointID)
counts.add(false, n, node, r.Endpoint.Nodes[localEndpointID], remoteEndpoint)
counts.add(r.DNS, false, n, node, r.Endpoint.Nodes[localEndpointID], remoteEndpoint)
}
}
}
@@ -203,7 +203,7 @@ func outgoingConnectionsSummary(topologyID string, r report.Report, n report.Nod
for _, localEndpoint := range localEndpoints {
for _, remoteEndpointID := range localEndpoint.Adjacency.Intersection(remoteEndpointIDs) {
remoteEndpointID = canonicalEndpointID(remoteEndpointIDCopies, remoteEndpointID)
counts.add(true, n, node, localEndpoint, r.Endpoint.Nodes[remoteEndpointID])
counts.add(r.DNS, true, n, node, localEndpoint, r.Endpoint.Nodes[remoteEndpointID])
}
}
}

View File

@@ -36,7 +36,7 @@ func (e mapEndpoints) Render(rpt report.Report) Nodes {
// Nodes without a hostid are mapped to pseudo nodes, if
// possible.
if _, ok := n.Latest.Lookup(report.HostNodeID); !ok {
if id, ok := pseudoNodeID(n, local); ok {
if id, ok := pseudoNodeID(rpt, n, local); ok {
ret.addChild(n, id, Pseudo)
continue
}

View File

@@ -3,7 +3,6 @@ package render
import (
"strings"
"github.com/weaveworks/scope/probe/endpoint"
"github.com/weaveworks/scope/report"
)
@@ -62,13 +61,13 @@ func NewDerivedPseudoNode(id string, node report.Node) report.Node {
return output
}
func pseudoNodeID(n report.Node, local report.Networks) (string, bool) {
func pseudoNodeID(rpt report.Report, 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 {
if id, ok := externalNodeID(rpt, n, addr, local); ok {
return id, ok
}
@@ -78,11 +77,11 @@ func pseudoNodeID(n report.Node, local report.Networks) (string, bool) {
}
// 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) {
func externalNodeID(rpt report.Report, 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
// is. This needs to be done before checking IPs since known services can
// live in the same network, see https://github.com/weaveworks/scope/issues/2163
if hostname, found := DNSFirstMatch(n, isKnownService); found {
if hostname, found := rpt.DNS.FirstMatch(n.ID, isKnownService); found {
return ServiceNodeIDPrefix + hostname, true
}
@@ -101,25 +100,3 @@ func externalNodeID(n report.Node, addr string, local report.Networks) (string,
// The node is not external
return "", false
}
// DNSFirstMatch returns the first DNS name where match() returns
// true, from a prioritized list of snooped and reverse-resolved DNS
// names associated with node n.
func DNSFirstMatch(n report.Node, match func(name string) bool) (string, bool) {
// we rely on Sets being sorted, to make selection for display more
// deterministic
// prioritize snooped names
snoopedNames, _ := n.Sets.Lookup(endpoint.SnoopedDNSNames)
for _, hostname := range snoopedNames {
if match(hostname) {
return hostname, true
}
}
reverseNames, _ := n.Sets.Lookup(endpoint.ReverseDNSNames)
for _, hostname := range reverseNames {
if match(hostname) {
return hostname, true
}
}
return "", false
}