Skip to content

Commit

Permalink
Review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfonso Acosta committed Sep 20, 2016
1 parent 01c713f commit 94dc9cb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
3 changes: 0 additions & 3 deletions probe/endpoint/dns_snooper_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ func newPcapHandle() (*pcap.Handle, error) {
return nil, err
}
defer inactive.CleanUp()
if err = inactive.SetPromisc(true); err != nil {
return nil, err
}
// pcap timeout blackmagic copied from Weave Net to reduce CPU consumption
// see https://github.com/weaveworks/weave/commit/025315363d5ea8b8265f1b3ea800f24df2be51a4
if err = inactive.SetTimeout(time.Duration(math.MaxInt64)); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions probe/endpoint/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
Conntracked = "conntracked"
Procspied = "procspied"
ReverseDNSNames = "reverse_dns_names"
SnoopedDNSNames = "snooped_dns_names"
)

// Reporter generates Reports containing the Endpoint topology.
Expand Down Expand Up @@ -195,11 +196,10 @@ func (r *Reporter) makeEndpointNode(namespaceID string, addr string, port uint16
node := report.MakeNodeWith(
report.MakeEndpointNodeID(r.hostID, namespaceID, addr, portStr),
map[string]string{Addr: addr, Port: portStr})
names := r.dnsSnooper.CachedNamesForIP(addr)
if resolvedNames, err := r.reverseResolver.get(addr); err == nil {
names = append(names, resolvedNames...)
if names := r.dnsSnooper.CachedNamesForIP(addr); len(names) > 0 {
node = node.WithSet(SnoopedDNSNames, report.MakeStringSet(names...))
}
if len(names) > 0 {
if names, err := r.reverseResolver.get(addr); err == nil && len(names) > 0 {
node = node.WithSet(ReverseDNSNames, report.MakeStringSet(names...))
}
if extra != nil {
Expand Down
2 changes: 1 addition & 1 deletion render/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func ShortLivedConnectionJoin(r Renderer, toIPs func(report.Node) []string) Rend
return report.Nodes{}
}
if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
node := toInternetNode(m)
node := externalNode(m)
return report.Nodes{node.ID: node}
}

Expand Down
10 changes: 6 additions & 4 deletions render/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func MapEndpoint2Pseudo(n report.Node, local report.Networks) report.Nodes {
if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
// If the dstNodeAddr is not in a network local to this report, we emit an
// external pseudoNode
node = toInternetNode(n)
node = externalNode(n)
} else {
// due to https://github.com/weaveworks/scope/issues/1323 we are dropping
// all non-internet pseudo nodes for now.
Expand Down Expand Up @@ -157,11 +157,13 @@ func MapProcess2Name(n report.Node, _ report.Networks) report.Nodes {
return report.Nodes{name: node}
}

func toInternetNode(m report.Node) report.Node {
func externalNode(m report.Node) report.Node {
// First, check if it's a known service and emit a
// a specific node if it is
hostnames, _ := m.Sets.Lookup(endpoint.ReverseDNSNames)
for _, hostname := range hostnames {
snoopedHostnames, _ := m.Sets.Lookup(endpoint.SnoopedDNSNames)
reverseHostnames, _ := m.Sets.Lookup(endpoint.ReverseDNSNames)
// Intentionally prioritize snooped hostnames
for _, hostname := range append(snoopedHostnames, reverseHostnames...) {
if isKnownService(hostname) {
return NewDerivedPseudoNode(ServiceNodeIDPrefix+hostname, m)
}
Expand Down
10 changes: 5 additions & 5 deletions render/theinternet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
)

var (
// ServiceNodeIDPrefix is how the ID all service pseudo nodes begin
// ServiceNodeIDPrefix is how the ID of all service pseudo nodes begin
ServiceNodeIDPrefix = "service-"

knownServicesMatchers = []*regexp.Regexp{
knownServiceMatchers = []*regexp.Regexp{
// See http://docs.aws.amazon.com/general/latest/gr/rande.html for fainer grained
// details
regexp.MustCompile(`^.+\.amazonaws\.com$`),
regexp.MustCompile(`^.+\.googleapis\.com$`),
}

knownServicesExcluder = []*regexp.Regexp{
knownServiceExcluders = []*regexp.Regexp{
// We exclude ec2 machines because they are too generic
// and having separate nodes for them makes visualizations worse
regexp.MustCompile(`^ec2.*\.amazonaws\.com$`),
Expand All @@ -28,7 +28,7 @@ var (

func isKnownService(hostname string) bool {
foundMatch := false
for _, matcher := range knownServicesMatchers {
for _, matcher := range knownServiceMatchers {
if matcher.MatchString(hostname) {
foundMatch = true
break
Expand All @@ -38,7 +38,7 @@ func isKnownService(hostname string) bool {
return false
}

for _, excluder := range knownServicesExcluder {
for _, excluder := range knownServiceExcluders {
if excluder.MatchString(hostname) {
return false
}
Expand Down

0 comments on commit 94dc9cb

Please sign in to comment.