Skip to content

Commit

Permalink
Merge pull request #1875 from weaveworks/1713-show-internet-connections
Browse files Browse the repository at this point in the history
show more details of a node's internet connections

Fixes #1713.
  • Loading branch information
rade authored Sep 19, 2016
2 parents 7b0f0cb + c455f04 commit d008919
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 21 deletions.
43 changes: 31 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,35 @@ 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 {
// 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)
}
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 +129,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

0 comments on commit d008919

Please sign in to comment.