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

show more details of a node's internet connections #1875

Merged
merged 2 commits into from
Sep 19, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
39 changes: 27 additions & 12 deletions render/detailed/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func (s connectionsByID) Less(i, j int) bool { return s[i].ID < s[j].ID }

// Intermediate type used as a key to dedupe rows
type connection struct {
remoteNodeID string
addr string // for internet nodes only: the address
port string // destination port
remoteNodeID string
remoteAddr, localAddr string // for internet nodes only
port string // destination port
}

type connectionCounters struct {
Expand Down Expand Up @@ -92,19 +92,31 @@ func (c *connectionCounters) add(outgoing bool, localNode, remoteNode, localEndp
return
}
// For internet nodes we break out individual addresses
if isInternetNode(localNode) {
if _, conn.addr, _, ok = report.ParseEndpointNodeID(localEndpoint.ID); !ok {
return
}
if set, ok := localEndpoint.Sets.Lookup(endpoint.ReverseDNSNames); ok && len(set) > 0 {
conn.addr = fmt.Sprintf("%s (%s)", set[0], conn.addr)
}
if conn.remoteAddr, ok = internetAddr(remoteNode, remoteEndpoint); !ok {
return
}
if conn.localAddr, ok = internetAddr(localNode, localEndpoint); !ok {
return
}

c.counted[connectionID] = struct{}{}
c.counts[conn]++
}

func internetAddr(node report.Node, ep report.Node) (string, bool) {
if !isInternetNode(node) {
return "", true
}
_, addr, _, ok := report.ParseEndpointNodeID(ep.ID)
if !ok {
return "", false
}
if set, ok := ep.Sets.Lookup(endpoint.ReverseDNSNames); ok && len(set) > 0 {
addr = fmt.Sprintf("%s (%s)", set[0], addr)

This comment was marked as abuse.

This comment was marked as abuse.

}
return addr, true
}

func (c *connectionCounters) rows(r report.Report, ns report.Nodes, includeLocal bool) []Connection {
output := []Connection{}
for row, count := range c.counts {
Expand All @@ -113,16 +125,19 @@ func (c *connectionCounters) rows(r report.Report, ns report.Nodes, includeLocal
// MakeNodeID(ns[row.remoteNodeID]). As we don't need the whole summary.
summary, _ := MakeNodeSummary(r, ns[row.remoteNodeID])
connection := Connection{
ID: fmt.Sprintf("%s-%s-%s", row.remoteNodeID, row.addr, row.port),
ID: fmt.Sprintf("%s-%s-%s-%s", row.remoteNodeID, row.remoteAddr, row.localAddr, row.port),
NodeID: summary.ID,
Label: summary.Label,
Linkable: true,
}
if row.remoteAddr != "" {
connection.Label = row.remoteAddr
}
if includeLocal {
connection.Metadata = append(connection.Metadata,
report.MetadataRow{
ID: "foo",
Value: row.addr,
Value: row.localAddr,
Datatype: number,
})
}
Expand Down
18 changes: 9 additions & 9 deletions render/detailed/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func child(t *testing.T, r render.Renderer, id string) detailed.NodeSummary {
return s.SummarizeMetrics()
}

func connectionID(nodeID string) string {
return fmt.Sprintf("%s-%s-%d", nodeID, "", 80)
func connectionID(nodeID string, addr string) string {
return fmt.Sprintf("%s-%s-%s-%d", nodeID, addr, "", 80)
}

func TestMakeDetailedHostNode(t *testing.T) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestMakeDetailedHostNode(t *testing.T) {
Columns: detailed.NormalColumns,
Connections: []detailed.Connection{
{
ID: connectionID(fixture.ServerHostNodeID),
ID: connectionID(fixture.ServerHostNodeID, ""),
NodeID: fixture.ServerHostNodeID,
Label: "server",
Linkable: true,
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestMakeDetailedContainerNode(t *testing.T) {
Columns: detailed.NormalColumns,
Connections: []detailed.Connection{
{
ID: connectionID(fixture.ClientContainerNodeID),
ID: connectionID(fixture.ClientContainerNodeID, ""),
NodeID: fixture.ClientContainerNodeID,
Label: "client",
Linkable: true,
Expand All @@ -279,9 +279,9 @@ func TestMakeDetailedContainerNode(t *testing.T) {
},
},
{
ID: connectionID(render.IncomingInternetID),
ID: connectionID(render.IncomingInternetID, fixture.RandomClientIP),
NodeID: render.IncomingInternetID,
Label: render.InboundMajor,
Label: fixture.RandomClientIP,
Linkable: true,
Metadata: []report.MetadataRow{
{
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestMakeDetailedPodNode(t *testing.T) {
Columns: detailed.NormalColumns,
Connections: []detailed.Connection{
{
ID: connectionID(fixture.ClientPodNodeID),
ID: connectionID(fixture.ClientPodNodeID, ""),
NodeID: fixture.ClientPodNodeID,
Label: "pong-a",
Linkable: true,
Expand All @@ -399,9 +399,9 @@ func TestMakeDetailedPodNode(t *testing.T) {
},
},
{
ID: connectionID(render.IncomingInternetID),
ID: connectionID(render.IncomingInternetID, fixture.RandomClientIP),
NodeID: render.IncomingInternetID,
Label: render.InboundMajor,
Label: fixture.RandomClientIP,
Linkable: true,
Metadata: []report.MetadataRow{
{
Expand Down