Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid object creation when scanning DNS names #2921

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions render/detailed/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func internetAddr(node report.Node, ep report.Node) (string, bool) {
if !ok {
return "", false
}
if names := render.DNSNames(ep); len(names) > 0 {
if name, found := render.DNSFirstMatch(ep, 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)", names[0], addr)
addr = fmt.Sprintf("%s (%s)", name, addr)
}
return addr, true
}
Expand Down
34 changes: 20 additions & 14 deletions render/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package render

import (
"net"
"sort"
"strings"

"github.com/weaveworks/scope/probe/endpoint"
Expand Down Expand Up @@ -42,10 +41,8 @@ func NewDerivedExternalNode(n report.Node, addr string, local report.Networks) (
// 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
for _, hostname := range DNSNames(n) {
if isKnownService(hostname) {
return NewDerivedPseudoNode(ServiceNodeIDPrefix+hostname, n), true
}
if hostname, found := DNSFirstMatch(n, isKnownService); found {
return NewDerivedPseudoNode(ServiceNodeIDPrefix+hostname, n), true
}

// If the dstNodeAddr is not in a network local to this report, we emit an
Expand All @@ -62,15 +59,24 @@ func NewDerivedExternalNode(n report.Node, addr string, local report.Networks) (
return report.Node{}, false
}

// DNSNames returns a prioritized list of snooped and reverse-resolved
// DNS names associated with node 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
// 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) {

This comment was marked as abuse.

This comment was marked as abuse.

// we rely on Sets being sorted, to make selection for display more
// deterministic
sort.StringSlice(snoopedNames).Sort()
sort.StringSlice(reverseNames).Sort()
// prioritize snooped names
return append(snoopedNames, reverseNames...)
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
}