mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-05 19:21:46 +00:00
aggregate connection details table
List Local and Remote endpoints for each TCP connection on the node.
This commit is contained in:
@@ -79,6 +79,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 +90,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 +113,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 +131,29 @@ 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 {
|
||||
if _, address, port, ok := report.ParseEndpointNodeID(adj); ok {
|
||||
rows = append(rows, Row{
|
||||
Key: local,
|
||||
ValueMajor: fmt.Sprintf("%s:%s", address, port),
|
||||
})
|
||||
}
|
||||
}
|
||||
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) {
|
||||
|
||||
@@ -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),
|
||||
"",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user