Skip to content

Commit

Permalink
Update tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Oct 17, 2015
1 parent 6f30d64 commit 06ff0dd
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 121 deletions.
2 changes: 1 addition & 1 deletion app/api_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestAPITopologyWebsocket(t *testing.T) {
if err := json.Unmarshal(p, &d); err != nil {
t.Fatalf("JSON parse error: %s", err)
}
equals(t, 7, len(d.Add))
equals(t, 8, len(d.Add))
equals(t, 0, len(d.Update))
equals(t, 0, len(d.Remove))
}
Expand Down
196 changes: 94 additions & 102 deletions render/expected/expected.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ var (
),
}
}
theInternetNode = func(adjacent string) render.RenderableNode {
theIncomingInternetNode = func(adjacent string) render.RenderableNode {
return render.RenderableNode{
ID: render.TheInternetID,
ID: render.IncomingInternetID,
LabelMajor: render.TheInternetMajor,
LabelMinor: render.Incoming,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(adjacent),
EdgeMetadata: report.EdgeMetadata{
Expand All @@ -56,10 +57,20 @@ var (
},
Origins: report.MakeIDList(
test.RandomClientNodeID,
test.GoogleEndpointNodeID,
),
}
}
theOutgoingInternetNode = render.RenderableNode{
ID: render.OutgoingInternetID,
LabelMajor: render.TheInternetMajor,
LabelMinor: render.Outgoing,
Pseudo: true,
Node: report.MakeNode(),
EdgeMetadata: report.EdgeMetadata{},
Origins: report.MakeIDList(
test.GoogleEndpointNodeID,
),
}
ClientProcess1ID = render.MakeProcessID(test.ClientHostID, test.Client1PID)
ClientProcess2ID = render.MakeProcessID(test.ClientHostID, test.Client2PID)
ServerProcessID = render.MakeProcessID(test.ServerHostID, test.ServerPID)
Expand Down Expand Up @@ -128,12 +139,13 @@ var (
test.ServerHostNodeID,
test.NonContainerNodeID,
),
Node: report.MakeNode().WithAdjacent(render.TheInternetID),
Node: report.MakeNode().WithAdjacent(render.OutgoingInternetID),
EdgeMetadata: report.EdgeMetadata{},
},
unknownPseudoNode1ID: unknownPseudoNode1(ServerProcessID),
unknownPseudoNode2ID: unknownPseudoNode2(ServerProcessID),
render.TheInternetID: theInternetNode(ServerProcessID),
unknownPseudoNode1ID: unknownPseudoNode1(ServerProcessID),
unknownPseudoNode2ID: unknownPseudoNode2(ServerProcessID),
render.IncomingInternetID: theIncomingInternetNode(ServerProcessID),
render.OutgoingInternetID: theOutgoingInternetNode,
}).Prune()

RenderedProcessNames = (render.RenderableNodes{
Expand Down Expand Up @@ -184,12 +196,13 @@ var (
test.ServerHostNodeID,
test.NonContainerNodeID,
),
Node: report.MakeNode().WithAdjacent(render.TheInternetID),
Node: report.MakeNode().WithAdjacent(render.OutgoingInternetID),
EdgeMetadata: report.EdgeMetadata{},
},
unknownPseudoNode1ID: unknownPseudoNode1("apache"),
unknownPseudoNode2ID: unknownPseudoNode2("apache"),
render.TheInternetID: theInternetNode("apache"),
unknownPseudoNode1ID: unknownPseudoNode1("apache"),
unknownPseudoNode2ID: unknownPseudoNode2("apache"),
render.IncomingInternetID: theIncomingInternetNode("apache"),
render.OutgoingInternetID: theOutgoingInternetNode,
}).Prune()

RenderedContainers = (render.RenderableNodes{
Expand Down Expand Up @@ -244,10 +257,11 @@ var (
test.ServerHostNodeID,
test.NonContainerNodeID,
),
Node: report.MakeNode().WithAdjacent(render.TheInternetID),
Node: report.MakeNode().WithAdjacent(render.OutgoingInternetID),
EdgeMetadata: report.EdgeMetadata{},
},
render.TheInternetID: theInternetNode(test.ServerContainerID),
render.IncomingInternetID: theIncomingInternetNode(test.ServerContainerID),
render.OutgoingInternetID: theOutgoingInternetNode,
}).Prune()

RenderedContainerImages = (render.RenderableNodes{
Expand Down Expand Up @@ -301,72 +315,11 @@ var (
test.NonContainerProcessNodeID,
test.ServerHostNodeID,
),
Node: report.MakeNode().WithAdjacent(render.TheInternetID),
EdgeMetadata: report.EdgeMetadata{},
},
render.TheInternetID: theInternetNode(test.ServerContainerImageName),
}).Prune()

ServerHostRenderedID = render.MakeHostID(test.ServerHostID)
ClientHostRenderedID = render.MakeHostID(test.ClientHostID)
pseudoHostID1 = render.MakePseudoNodeID(test.UnknownClient1IP, test.ServerIP)
pseudoHostID2 = render.MakePseudoNodeID(test.UnknownClient3IP, test.ServerIP)

RenderedHosts = (render.RenderableNodes{
ServerHostRenderedID: {
ID: ServerHostRenderedID,
LabelMajor: "server", // before first .
LabelMinor: "hostname.com", // after first .
Rank: "hostname.com",
Pseudo: false,
Origins: report.MakeIDList(
test.ServerHostNodeID,
test.ServerAddressNodeID,
),
Node: report.MakeNode(),
EdgeMetadata: report.EdgeMetadata{
MaxConnCountTCP: newu64(3),
},
},
ClientHostRenderedID: {
ID: ClientHostRenderedID,
LabelMajor: "client", // before first .
LabelMinor: "hostname.com", // after first .
Rank: "hostname.com",
Pseudo: false,
Origins: report.MakeIDList(
test.ClientHostNodeID,
test.ClientAddressNodeID,
),
Node: report.MakeNode().WithAdjacent(ServerHostRenderedID),
EdgeMetadata: report.EdgeMetadata{
MaxConnCountTCP: newu64(3),
},
},
pseudoHostID1: {
ID: pseudoHostID1,
LabelMajor: test.UnknownClient1IP,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(ServerHostRenderedID),
Node: report.MakeNode().WithAdjacent(render.OutgoingInternetID),
EdgeMetadata: report.EdgeMetadata{},
Origins: report.MakeIDList(test.UnknownAddress1NodeID, test.UnknownAddress2NodeID),
},
pseudoHostID2: {
ID: pseudoHostID2,
LabelMajor: test.UnknownClient3IP,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(ServerHostRenderedID),
EdgeMetadata: report.EdgeMetadata{},
Origins: report.MakeIDList(test.UnknownAddress3NodeID),
},
render.TheInternetID: {
ID: render.TheInternetID,
LabelMajor: render.TheInternetMajor,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(ServerHostRenderedID),
EdgeMetadata: report.EdgeMetadata{},
Origins: report.MakeIDList(test.RandomAddressNodeID),
},
render.IncomingInternetID: theIncomingInternetNode(test.ServerContainerImageName),
render.OutgoingInternetID: theOutgoingInternetNode,
}).Prune()

RenderedPods = (render.RenderableNodes{
Expand Down Expand Up @@ -423,23 +376,11 @@ var (
test.NonContainerProcessNodeID,
test.NonContainerNodeID,
),
Node: report.MakeNode().WithAdjacent(render.TheInternetID),
Node: report.MakeNode().WithAdjacent(render.OutgoingInternetID),
EdgeMetadata: report.EdgeMetadata{},
},
render.TheInternetID: {
ID: render.TheInternetID,
LabelMajor: render.TheInternetMajor,
Pseudo: true,
Node: report.MakeNode().WithAdjacent("ping/pong-b"),
EdgeMetadata: report.EdgeMetadata{
EgressPacketCount: newu64(60),
EgressByteCount: newu64(600),
},
Origins: report.MakeIDList(
test.RandomClientNodeID,
test.GoogleEndpointNodeID,
),
},
render.IncomingInternetID: theIncomingInternetNode("ping/pong-b"),
render.OutgoingInternetID: theOutgoingInternetNode,
}).Prune()

RenderedPodServices = (render.RenderableNodes{
Expand Down Expand Up @@ -485,22 +426,73 @@ var (
test.NonContainerProcessNodeID,
test.NonContainerNodeID,
),
Node: report.MakeNode().WithAdjacent(render.TheInternetID),
Node: report.MakeNode().WithAdjacent(render.OutgoingInternetID),
EdgeMetadata: report.EdgeMetadata{},
},
render.TheInternetID: {
ID: render.TheInternetID,
LabelMajor: render.TheInternetMajor,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(test.ServiceID),
render.IncomingInternetID: theIncomingInternetNode(test.ServiceID),
render.OutgoingInternetID: theOutgoingInternetNode,
}).Prune()

ServerHostRenderedID = render.MakeHostID(test.ServerHostID)
ClientHostRenderedID = render.MakeHostID(test.ClientHostID)
pseudoHostID1 = render.MakePseudoNodeID(test.UnknownClient1IP, test.ServerIP)
pseudoHostID2 = render.MakePseudoNodeID(test.UnknownClient3IP, test.ServerIP)

RenderedHosts = (render.RenderableNodes{
ServerHostRenderedID: {
ID: ServerHostRenderedID,
LabelMajor: "server", // before first .
LabelMinor: "hostname.com", // after first .
Rank: "hostname.com",
Pseudo: false,
Origins: report.MakeIDList(
test.ServerHostNodeID,
test.ServerAddressNodeID,
),
Node: report.MakeNode(),
EdgeMetadata: report.EdgeMetadata{
EgressPacketCount: newu64(60),
EgressByteCount: newu64(600),
MaxConnCountTCP: newu64(3),
},
},
ClientHostRenderedID: {
ID: ClientHostRenderedID,
LabelMajor: "client", // before first .
LabelMinor: "hostname.com", // after first .
Rank: "hostname.com",
Pseudo: false,
Origins: report.MakeIDList(
test.RandomClientNodeID,
test.GoogleEndpointNodeID,
test.ClientHostNodeID,
test.ClientAddressNodeID,
),
Node: report.MakeNode().WithAdjacent(ServerHostRenderedID),
EdgeMetadata: report.EdgeMetadata{
MaxConnCountTCP: newu64(3),
},
},
pseudoHostID1: {
ID: pseudoHostID1,
LabelMajor: test.UnknownClient1IP,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(ServerHostRenderedID),
EdgeMetadata: report.EdgeMetadata{},
Origins: report.MakeIDList(test.UnknownAddress1NodeID, test.UnknownAddress2NodeID),
},
pseudoHostID2: {
ID: pseudoHostID2,
LabelMajor: test.UnknownClient3IP,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(ServerHostRenderedID),
EdgeMetadata: report.EdgeMetadata{},
Origins: report.MakeIDList(test.UnknownAddress3NodeID),
},
render.IncomingInternetID: {
ID: render.IncomingInternetID,
LabelMajor: render.TheInternetMajor,
LabelMinor: render.Incoming,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(ServerHostRenderedID),
EdgeMetadata: report.EdgeMetadata{},
Origins: report.MakeIDList(test.RandomAddressNodeID),
},
}).Prune()
)
Expand Down
40 changes: 24 additions & 16 deletions render/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ const (
UncontainedID = "uncontained"
UncontainedMajor = "Uncontained"

TheInternetID = "theinternet"
TheInternetMajor = "The Internet"
TheInternetID = "theinternet"
IncomingInternetID = "in-" + TheInternetID
OutgoingInternetID = "out-" + TheInternetID
TheInternetMajor = "The Internet"
Incoming = "Incoming"
Outgoing = "Outgoing"

containersKey = "containers"
podsKey = "pods"
Expand All @@ -37,6 +41,19 @@ const (
// If the output is empty, the node shall be omitted from the rendered topology.
type MapFunc func(RenderableNode, report.Networks) RenderableNodes

func generateInternetNodeFor(m RenderableNode) RenderableNodes {
node := newDerivedPseudoNode("", TheInternetMajor, m)
// emit one internet node for incoming, one for outgoing
if len(m.Adjacency) > 0 {
node.ID = IncomingInternetID
node.LabelMinor = Incoming
} else {
node.ID = OutgoingInternetID
node.LabelMinor = Outgoing
}
return RenderableNodes{node.ID: node}
}

// MapEndpointIdentity maps an endpoint topology node to a single endpoint
// renderable node. As it is only ever run on endpoint topology nodes, we
// expect that certain keys are present.
Expand All @@ -62,16 +79,7 @@ func MapEndpointIdentity(m RenderableNode, local report.Networks) RenderableNode
// If the dstNodeAddr is not in a network local to this report, we emit an
// internet node
if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
node := newDerivedPseudoNode(TheInternetID, TheInternetMajor, m)
// emit one internet node for incoming, one for outgoing
if len(m.Adjacency) > 0 {
node.ID = "in-" + TheInternetID
node.LabelMinor = "Incoming"
} else {
node.ID = "out-" + TheInternetID
node.LabelMinor = "Outgoing"
}
return RenderableNodes{node.ID: node}
return generateInternetNodeFor(m)
}

// We are a 'client' pseudo node if the port is in the ephemeral port range.
Expand Down Expand Up @@ -239,8 +247,8 @@ func MapAddressIdentity(m RenderableNode, local report.Networks) RenderableNodes
if !hasHostID {
// If the addr is not in a network local to this report, we emit an
// internet node
if !local.Contains(net.ParseIP(addr)) {
return RenderableNodes{TheInternetID: newDerivedPseudoNode(TheInternetID, TheInternetMajor, m)}
if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
return generateInternetNodeFor(m)
}

// Otherwise generate a pseudo node for every
Expand Down Expand Up @@ -296,8 +304,8 @@ func MapEndpoint2IP(m RenderableNode, local report.Networks) RenderableNodes {
if !ok {
return RenderableNodes{}
}
if !local.Contains(net.ParseIP(addr)) {
return RenderableNodes{TheInternetID: newDerivedPseudoNode(TheInternetID, TheInternetMajor, m)}
if ip := net.ParseIP(addr); ip != nil && !local.Contains(ip) {
return generateInternetNodeFor(m)
}

result := RenderableNodes{addr: NewRenderableNodeWith(addr, "", "", "", m)}
Expand Down
5 changes: 3 additions & 2 deletions render/short_lived_connections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ var (
}

want = (render.RenderableNodes{
render.TheInternetID: {
ID: render.TheInternetID,
render.IncomingInternetID: {
ID: render.IncomingInternetID,
LabelMajor: render.TheInternetMajor,
LabelMinor: render.Incoming,
Pseudo: true,
Node: report.MakeNode().WithAdjacent(containerID),
Origins: report.MakeIDList(randomEndpointNodeID),
Expand Down

0 comments on commit 06ff0dd

Please sign in to comment.