From 3b35dc3716d7439da26efdcf29a3667f392e3937 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Mon, 29 Jun 2015 14:25:02 +0100 Subject: [PATCH] aggregate connection details table List Local and Remote endpoints for each TCP connection on the node. --- render/detailed_node.go | 39 +++++++++++++++++++++----------- render/detailed_node_test.go | 44 +++++++++++++++++++++++++++--------- test/report_fixture.go | 25 ++++++++++++-------- 3 files changed, 75 insertions(+), 33 deletions(-) diff --git a/render/detailed_node.go b/render/detailed_node.go index 59d8b6ac90..04b9c27f94 100644 --- a/render/detailed_node.go +++ b/render/detailed_node.go @@ -5,6 +5,7 @@ import ( "reflect" "sort" "strconv" + "strings" "github.com/weaveworks/scope/probe/docker" "github.com/weaveworks/scope/probe/host" @@ -79,6 +80,7 @@ func MakeDetailedNode(r report.Report, n RenderableNode) DetailedNode { // multiple origins. The ultimate goal here is to generate tables to view // in the UI, so we skip the intermediate representations, but we could // add them later. + connections := []Row{} outer: for _, id := range n.Origins { if table, ok := OriginTable(r, id); ok { @@ -89,8 +91,13 @@ outer: } } tables = append(tables, table) + } else if nmd, ok := r.Endpoint.NodeMetadatas[id]; ok { + connections = append(connections, connectionDetailsRows(r.Endpoint, id, nmd)...) } } + if len(connections) > 0 { + tables = append(tables, connectionDetailsTable(connections)) + } // Sort tables by rank sort.Sort(tables) @@ -107,9 +114,6 @@ outer: // OriginTable produces a table (to be consumed directly by the UI) based on // an origin ID, which is (optimistically) a node ID in one of our topologies. func OriginTable(r report.Report, originID string) (Table, bool) { - if nmd, ok := r.Endpoint.NodeMetadatas[originID]; ok { - return endpointOriginTable(nmd) - } if nmd, ok := r.Address.NodeMetadatas[originID]; ok { return addressOriginTable(nmd) } @@ -128,22 +132,31 @@ func OriginTable(r report.Report, originID string) (Table, bool) { return Table{}, false } -func endpointOriginTable(nmd report.NodeMetadata) (Table, bool) { +func connectionDetailsRows(endpointTopology report.Topology, originID string, nmd report.NodeMetadata) []Row { rows := []Row{} - for _, tuple := range []struct{ key, human string }{ - {"addr", "Endpoint"}, - {"port", "Port"}, - } { - if val, ok := nmd[tuple.key]; ok { - rows = append(rows, Row{Key: tuple.human, ValueMajor: val, ValueMinor: ""}) + local := fmt.Sprintf("%s:%s", nmd["addr"], nmd["port"]) + adjacencies := endpointTopology.Adjacency[report.MakeAdjacencyID(originID)] + sort.Strings(adjacencies) + for _, adj := range adjacencies { + segments := strings.SplitN(adj, report.ScopeDelim, 3) + if len(segments) != 3 { + continue } + rows = append(rows, Row{ + Key: local, + ValueMajor: fmt.Sprintf("%s:%s", segments[1], segments[2]), + }) } + return rows +} + +func connectionDetailsTable(connectionRows []Row) Table { return Table{ - Title: "Origin Endpoint", + Title: "Connection Details", Numeric: false, - Rows: rows, + Rows: append([]Row{{Key: "Local", ValueMajor: "Remote"}}, connectionRows...), Rank: endpointRank, - }, len(rows) > 0 + } } func addressOriginTable(nmd report.NodeMetadata) (Table, bool) { diff --git a/render/detailed_node_test.go b/render/detailed_node_test.go index e2dc91183f..bc754b4e1c 100644 --- a/render/detailed_node_test.go +++ b/render/detailed_node_test.go @@ -1,6 +1,7 @@ package render_test import ( + "fmt" "reflect" "testing" @@ -13,14 +14,6 @@ func TestOriginTable(t *testing.T) { t.Errorf("unknown origin ID gave unexpected success") } for originID, want := range map[string]render.Table{ - test.Client54001NodeID: { - Title: "Origin Endpoint", - Numeric: false, - Rows: []render.Row{ - {"Endpoint", test.ClientIP, ""}, - {"Port", test.ClientPort54001, ""}, - }, - }, test.ClientAddressNodeID: { Title: "Origin Address", Numeric: false, @@ -107,11 +100,40 @@ func TestMakeDetailedNode(t *testing.T) { }, }, { - Title: "Origin Endpoint", + Title: "Connection Details", Numeric: false, Rows: []render.Row{ - {"Endpoint", test.ServerIP, ""}, - {"Port", test.ServerPort, ""}, + {"Local", "Remote", ""}, + { + fmt.Sprintf("%s:%s", test.ServerIP, test.ServerPort), + fmt.Sprintf("%s:%s", test.UnknownClient1IP, test.ClientPort54010), + "", + }, + { + fmt.Sprintf("%s:%s", test.ServerIP, test.ServerPort), + fmt.Sprintf("%s:%s", test.UnknownClient1IP, test.ClientPort54020), + "", + }, + { + fmt.Sprintf("%s:%s", test.ServerIP, test.ServerPort), + fmt.Sprintf("%s:%s", test.UnknownClient3IP, test.ClientPort54020), + "", + }, + { + fmt.Sprintf("%s:%s", test.ServerIP, test.ServerPort), + fmt.Sprintf("%s:%s", test.ClientIP, test.ClientPort54001), + "", + }, + { + fmt.Sprintf("%s:%s", test.ServerIP, test.ServerPort), + fmt.Sprintf("%s:%s", test.ClientIP, test.ClientPort54002), + "", + }, + { + fmt.Sprintf("%s:%s", test.ServerIP, test.ServerPort), + fmt.Sprintf("%s:%s", test.RandomClientIP, test.ClientPort12345), + "", + }, }, }, }, diff --git a/test/report_fixture.go b/test/report_fixture.go index 61e2b6635a..b775e0d432 100644 --- a/test/report_fixture.go +++ b/test/report_fixture.go @@ -12,11 +12,18 @@ var ( ServerHostID = "server.hostname.com" UnknownHostID = "" - ClientIP = "10.10.10.20" - ServerIP = "192.168.1.1" - ClientPort54001 = "54001" - ClientPort54002 = "54002" - ServerPort = "80" + ClientIP = "10.10.10.20" + ServerIP = "192.168.1.1" + ClientPort54001 = "54001" + ClientPort54010 = "54010" + ClientPort54002 = "54002" + ClientPort54020 = "54020" + ClientPort12345 = "12345" + ServerPort = "80" + UnknownClient1IP = "10.10.10.10" + UnknownClient2IP = "10.10.10.10" + UnknownClient3IP = "10.10.10.11" + RandomClientIP = "51.52.53.54" ClientHostName = ClientHostID ServerHostName = ServerHostID @@ -32,10 +39,10 @@ var ( Client54001NodeID = report.MakeEndpointNodeID(ClientHostID, ClientIP, ClientPort54001) // curl (1) Client54002NodeID = report.MakeEndpointNodeID(ClientHostID, ClientIP, ClientPort54002) // curl (2) Server80NodeID = report.MakeEndpointNodeID(ServerHostID, ServerIP, ServerPort) // apache - UnknownClient1NodeID = report.MakeEndpointNodeID(ServerHostID, "10.10.10.10", "54010") // we want to ensure two unknown clients, connnected - UnknownClient2NodeID = report.MakeEndpointNodeID(ServerHostID, "10.10.10.10", "54020") // to the same server, are deduped. - UnknownClient3NodeID = report.MakeEndpointNodeID(ServerHostID, "10.10.10.11", "54020") // Check this one isn't deduped - RandomClientNodeID = report.MakeEndpointNodeID(ServerHostID, "51.52.53.54", "12345") // this should become an internet node + UnknownClient1NodeID = report.MakeEndpointNodeID(ServerHostID, UnknownClient1IP, "54010") // we want to ensure two unknown clients, connnected + UnknownClient2NodeID = report.MakeEndpointNodeID(ServerHostID, UnknownClient2IP, "54020") // to the same server, are deduped. + UnknownClient3NodeID = report.MakeEndpointNodeID(ServerHostID, UnknownClient3IP, "54020") // Check this one isn't deduped + RandomClientNodeID = report.MakeEndpointNodeID(ServerHostID, RandomClientIP, "12345") // this should become an internet node ClientProcess1NodeID = report.MakeProcessNodeID(ClientHostID, Client1PID) ClientProcess2NodeID = report.MakeProcessNodeID(ClientHostID, Client2PID)