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

Check for known services before external IPs #2172

Merged
merged 1 commit into from
Jan 31, 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
7 changes: 3 additions & 4 deletions render/container.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package render

import (
"net"
"regexp"
"strings"

Expand Down Expand Up @@ -111,9 +110,9 @@ func ShortLivedConnectionJoin(r Renderer, toIPs func(report.Node) []string) Rend
if !ok {
return report.Nodes{}
}
if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
node := externalNode(m)
return report.Nodes{node.ID: node}

if externalNode, ok := NewDerivedExternalNode(m, addr, local); ok {
return report.Nodes{externalNode.ID: externalNode}
}

// We also allow for joining on ip:port pairs. This is useful
Expand Down
48 changes: 48 additions & 0 deletions render/id.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package render

import (
"net"
"sort"
"strings"

"github.com/weaveworks/scope/probe/endpoint"
"github.com/weaveworks/scope/report"
)

// Constants are used in the tests.
const (
TheInternetID = "theinternet"
IncomingInternetID = "in-" + TheInternetID
OutgoingInternetID = "out-" + TheInternetID
)

// MakePseudoNodeID joins the parts of an id into the id of a pseudonode
func MakePseudoNodeID(parts ...string) string {
return strings.Join(append([]string{"pseudo"}, parts...), ":")
Expand All @@ -26,3 +36,41 @@ func NewDerivedPseudoNode(id string, node report.Node) report.Node {
output := NewDerivedNode(id, node).WithTopology(Pseudo)
return output
}

// NewDerivedExternalNode figures out if a node should be considered external and creates the corresponding pseudo node
func NewDerivedExternalNode(n report.Node, addr string, local report.Networks) (report.Node, 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
for _, hostname := range DNSNames(n) {
if isKnownService(hostname) {
return NewDerivedPseudoNode(ServiceNodeIDPrefix+hostname, n), true
}
}

// If the dstNodeAddr is not in a network local to this report, we emit an
// internet pseudoNode
if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
// emit one internet node for incoming, one for outgoing
if len(n.Adjacency) > 0 {
return NewDerivedPseudoNode(IncomingInternetID, n), true
}
return NewDerivedPseudoNode(OutgoingInternetID, n), true
}

// The node is not external
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
// deterministic
sort.StringSlice(snoopedNames).Sort()
sort.StringSlice(reverseNames).Sort()
// prioritize snooped names
return append(snoopedNames, reverseNames...)
}
61 changes: 10 additions & 51 deletions render/process.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package render

import (
"net"
"sort"

"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/probe/endpoint"
"github.com/weaveworks/scope/probe/process"
Expand All @@ -12,13 +9,10 @@ import (

// Constants are used in the tests.
const (
TheInternetID = "theinternet"
IncomingInternetID = "in-" + TheInternetID
OutgoingInternetID = "out-" + TheInternetID
InboundMajor = "The Internet"
OutboundMajor = "The Internet"
InboundMinor = "Inbound connections"
OutboundMinor = "Outbound connections"
InboundMajor = "The Internet"
OutboundMajor = "The Internet"
InboundMinor = "Inbound connections"
OutboundMinor = "Outbound connections"

// Topology for pseudo-nodes and IPs so we can differentiate them at the end
Pseudo = "pseudo"
Expand Down Expand Up @@ -88,24 +82,18 @@ 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 {
var node report.Node

addr, ok := n.Latest.Lookup(endpoint.Addr)
if !ok {
return 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 = externalNode(n)
} else {
// due to https://github.com/weaveworks/scope/issues/1323 we are dropping
// all non-internet pseudo nodes for now.
// node = NewDerivedPseudoNode(MakePseudoNodeID(addr), n)
return report.Nodes{}
if externalNode, ok := NewDerivedExternalNode(n, addr, local); ok {
return report.Nodes{externalNode.ID: externalNode}
}
return report.Nodes{node.ID: node}

// due to https://github.com/weaveworks/scope/issues/1323 we are dropping
// all non-external pseudo nodes for now.
return report.Nodes{}
}

// MapEndpoint2Process maps endpoint Nodes to process
Expand Down Expand Up @@ -157,32 +145,3 @@ func MapProcess2Name(n report.Node, _ report.Networks) report.Nodes {
node.Counters = node.Counters.Add(n.Topology, 1)
return report.Nodes{name: 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
for _, hostname := range DNSNames(n) {
if isKnownService(hostname) {
return NewDerivedPseudoNode(ServiceNodeIDPrefix+hostname, n)
}
}

// emit one internet node for incoming, one for outgoing
if len(n.Adjacency) > 0 {
return NewDerivedPseudoNode(IncomingInternetID, n)
}
return NewDerivedPseudoNode(OutgoingInternetID, n)
}

// 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
// deterministic
sort.StringSlice(snoopedNames).Sort()
sort.StringSlice(reverseNames).Sort()
// prioritize snooped names
return append(snoopedNames, reverseNames...)
}