mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-23 22:36:24 +00:00
aggregate connection details table
List Local and Remote endpoints for each TCP connection on the node.
This commit is contained in:
@@ -103,6 +103,17 @@ func ParseNodeID(nodeID string) (hostID string, remainder string, ok bool) {
|
||||
return fields[0], fields[1], true
|
||||
}
|
||||
|
||||
// ParseEndpointNodeID produces the host ID, address, and port and remainder
|
||||
// (typically an address) from an endpoint node ID. Note that hostID may be
|
||||
// blank.
|
||||
func ParseEndpointNodeID(endpointNodeID string) (hostID, address, port string, ok bool) {
|
||||
fields := strings.SplitN(endpointNodeID, ScopeDelim, 3)
|
||||
if len(fields) != 3 {
|
||||
return "", "", "", false
|
||||
}
|
||||
return fields[0], fields[1], fields[2], true
|
||||
}
|
||||
|
||||
// ExtractHostID extracts the host id from NodeMetadata
|
||||
func ExtractHostID(m NodeMetadata) string {
|
||||
hostid, _, _ := ParseNodeID(m[HostNodeID])
|
||||
|
||||
@@ -75,6 +75,42 @@ func TestAdjacencyID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestEndpointNodeID(t *testing.T) {
|
||||
for _, bad := range []string{
|
||||
clientAddressNodeID,
|
||||
serverAddressNodeID,
|
||||
unknownAddressNodeID,
|
||||
clientHostNodeID,
|
||||
serverHostNodeID,
|
||||
"host.com;1.2.3.4",
|
||||
"a;b",
|
||||
"a;",
|
||||
";b",
|
||||
";",
|
||||
"",
|
||||
} {
|
||||
if haveName, haveAddress, havePort, ok := report.ParseEndpointNodeID(bad); ok {
|
||||
t.Errorf("%q: expected failure, but got {%q, %q, %q}", bad, haveName, haveAddress, havePort)
|
||||
}
|
||||
}
|
||||
|
||||
for input, want := range map[string]struct{ name, address, port string }{
|
||||
report.MakeEndpointNodeID("host.com", "1.2.3.4", "c"): {"", "1.2.3.4", "c"},
|
||||
"a;b;c": {"a", "b", "c"},
|
||||
} {
|
||||
haveName, haveAddress, havePort, ok := report.ParseEndpointNodeID(input)
|
||||
if !ok {
|
||||
t.Errorf("%q: not OK", input)
|
||||
continue
|
||||
}
|
||||
if want.name != haveName ||
|
||||
want.address != haveAddress ||
|
||||
want.port != havePort {
|
||||
t.Errorf("%q: want %q, have {%q, %q, %q}", input, want, haveName, haveAddress, havePort)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEdgeID(t *testing.T) {
|
||||
for _, bad := range []string{
|
||||
client54001EndpointNodeID,
|
||||
|
||||
Reference in New Issue
Block a user