mirror of
https://github.com/weaveworks/scope.git
synced 2026-08-19 04:16:21 +00:00
Merge pull request #426 from weaveworks/422-panic-map-addr
Don't assume pseudo nodes have edges _away_ from them
This commit is contained in:
+6
-3
@@ -66,7 +66,7 @@ func MapEndpointIdentity(m report.NodeMetadata, local report.Networks) Renderabl
|
||||
|
||||
// We are a 'client' pseudo node if the port is in the ephemeral port range.
|
||||
// Linux uses 32768 to 61000.
|
||||
if p, err := strconv.Atoi(port); err == nil && p >= 32768 && p < 61000 {
|
||||
if p, err := strconv.Atoi(port); err == nil && len(m.Adjacency) > 0 && p >= 32768 && p < 61000 {
|
||||
// We only exist if there is something in our adjacency
|
||||
// Generate a single pseudo node for every (client ip, server ip, server port)
|
||||
dstNodeID := m.Adjacency[0]
|
||||
@@ -170,8 +170,11 @@ func MapAddressIdentity(m report.NodeMetadata, local report.Networks) Renderable
|
||||
}
|
||||
|
||||
// Otherwise generate a pseudo node for every
|
||||
_, dstID, _ := report.ParseAddressNodeID(m.Adjacency[0])
|
||||
outputID := MakePseudoNodeID(addr, dstID)
|
||||
outputID := MakePseudoNodeID(addr, "")
|
||||
if len(m.Adjacency) > 0 {
|
||||
_, dstAddr, _ := report.ParseAddressNodeID(m.Adjacency[0])
|
||||
outputID = MakePseudoNodeID(addr, dstAddr)
|
||||
}
|
||||
return RenderableNodes{outputID: newPseudoNode(outputID, addr, "")}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package render_test
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/weaveworks/scope/probe/docker"
|
||||
@@ -16,6 +17,7 @@ func TestMapEndpointIdentity(t *testing.T) {
|
||||
{report.MakeNodeMetadataWith(map[string]string{endpoint.Addr: "1.2.3.4"}), false},
|
||||
{report.MakeNodeMetadataWith(map[string]string{endpoint.Port: "1234"}), false},
|
||||
{report.MakeNodeMetadataWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Port: "1234"}), true},
|
||||
{report.MakeNodeMetadataWith(map[string]string{endpoint.Addr: "1.2.3.4", endpoint.Port: "40000"}), true},
|
||||
{report.MakeNodeMetadataWith(map[string]string{report.HostNodeID: report.MakeHostNodeID("foo"), endpoint.Addr: "10.0.0.1", endpoint.Port: "20001"}), true},
|
||||
} {
|
||||
testMap(t, render.MapEndpointIdentity, input)
|
||||
@@ -72,7 +74,12 @@ type testcase struct {
|
||||
}
|
||||
|
||||
func testMap(t *testing.T, f render.LeafMapFunc, input testcase) {
|
||||
if have := f(input.md, report.Networks{}); input.ok != (len(have) > 0) {
|
||||
_, ipNet, err := net.ParseCIDR("1.2.3.0/16")
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
localNetworks := report.Networks([]*net.IPNet{ipNet})
|
||||
if have := f(input.md, localNetworks); input.ok != (len(have) > 0) {
|
||||
t.Errorf("%v: want %v, have %v", input.md, input.ok, have)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user