From 2da6dee6c96cc264d54d542c7cb5c3ee3ae114f2 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Thu, 22 Sep 2016 20:03:37 +0100 Subject: [PATCH] show forward DNS name for internet addresses ...if available. Follow-up to #1863. --- render/detailed/connections.go | 11 ++++------- render/process.go | 29 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/render/detailed/connections.go b/render/detailed/connections.go index 8177105845..f6af81e444 100644 --- a/render/detailed/connections.go +++ b/render/detailed/connections.go @@ -5,7 +5,6 @@ import ( "sort" "strconv" - "github.com/weaveworks/scope/probe/endpoint" "github.com/weaveworks/scope/render" "github.com/weaveworks/scope/report" ) @@ -113,12 +112,10 @@ func internetAddr(node report.Node, ep report.Node) (string, bool) { if !ok { return "", false } - if set, ok := ep.Sets.Lookup(endpoint.ReverseDNSNames); ok && len(set) > 0 { - // TODO We show just one of the names, selected rather - // abitrarily. We don't have space to show all (except in the - // tooltip perhaps), but should think of better strategies for - // choosing the name to display. - addr = fmt.Sprintf("%s (%s)", set[0], addr) + if names := render.DNSNames(ep); len(names) > 0 { + // we show the "most important" name only, since we don't have + // space for more + addr = fmt.Sprintf("%s (%s)", names[0], addr) } return addr, true } diff --git a/render/process.go b/render/process.go index 7c8f14d18a..f351416d96 100644 --- a/render/process.go +++ b/render/process.go @@ -158,24 +158,29 @@ func MapProcess2Name(n report.Node, _ report.Networks) report.Nodes { return report.Nodes{name: node} } -func externalNode(m report.Node) report.Node { +func externalNode(n report.Node) report.Node { // First, check if it's a known service and emit a // a specific node if it is - snoopedHostnames, _ := m.Sets.Lookup(endpoint.SnoopedDNSNames) - reverseHostnames, _ := m.Sets.Lookup(endpoint.ReverseDNSNames) - // Sort the names to make the lookup more deterministic - sort.StringSlice(snoopedHostnames).Sort() - sort.StringSlice(reverseHostnames).Sort() - // Intentionally prioritize snooped hostnames - for _, hostname := range append(snoopedHostnames, reverseHostnames...) { + for _, hostname := range DNSNames(n) { if isKnownService(hostname) { - return NewDerivedPseudoNode(ServiceNodeIDPrefix+hostname, m) + return NewDerivedPseudoNode(ServiceNodeIDPrefix+hostname, n) } } // emit one internet node for incoming, one for outgoing - if len(m.Adjacency) > 0 { - return NewDerivedPseudoNode(IncomingInternetID, m) + if len(n.Adjacency) > 0 { + return NewDerivedPseudoNode(IncomingInternetID, n) } - return NewDerivedPseudoNode(OutgoingInternetID, m) + return NewDerivedPseudoNode(OutgoingInternetID, n) +} + +func DNSNames(n report.Node) []string { + snoopedNames, _ := n.Sets.Lookup(endpoint.SnoopedDNSNames) + reverseNames, _ := n.Sets.Lookup(endpoint.ReverseDNSNames) + // sort the names, to make selection for display more + // deterministic + sort.StringSlice(snoopedNames).Sort() + sort.StringSlice(reverseNames).Sort() + // prioritize snooped names + return append(snoopedNames, reverseNames...) }