Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify connection join #2714

Merged
merged 4 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 15 additions & 29 deletions render/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package render

import (
"regexp"
"strings"

"github.com/weaveworks/scope/probe/docker"
"github.com/weaveworks/scope/report"
Expand Down Expand Up @@ -36,19 +35,13 @@ var ContainerRenderer = MakeFilter(
MapProcess2Container,
ColorConnectedProcessRenderer,
),

// This mapper brings in connections by joining with container
// IPs.
ConnectionJoin(MapContainer2IP, SelectContainer),

SelectContainer,
),
)

var mapEndpoint2IP = MakeMap(endpoint2IP, SelectEndpoint)

const originalNodeID = "original_node_id"
const originalNodeTopology = "original_node_topology"

// ConnectionJoin joins the given renderer with connections from the
// endpoints topology, using the toIPs function to extract IPs from
Expand All @@ -57,54 +50,47 @@ func ConnectionJoin(toIPs func(report.Node) []string, r Renderer) Renderer {
nodeToIP := func(n report.Node, _ report.Networks) report.Nodes {
result := report.Nodes{}
for _, ip := range toIPs(n) {
result[ip] = NewDerivedNode(ip, n).
result[ip] = report.MakeNode(ip).
WithTopology(IP).
WithLatests(map[string]string{
originalNodeID: n.ID,
originalNodeTopology: n.Topology,
originalNodeID: n.ID,
}).
WithCounters(map[string]int{IP: 1})
}
return result
}

return MakeMap(
ipToNode,
MakeReduce(
MakeMap(nodeToIP, r),
mapEndpoint2IP,
return MakeReduce(
MakeMap(
ipToNode,
MakeReduce(
MakeMap(nodeToIP, r),
mapEndpoint2IP,
),
),
r,
)
}

func ipToNode(n report.Node, _ report.Networks) report.Nodes {
// propagate non-IP nodes
if n.Topology != IP {
return report.Nodes{n.ID: n}
}
// If an IP is shared between multiple nodes, we can't reliably
// attribute an connection based on its IP
if count, _ := n.Counters.Lookup(IP); count > 1 {
return report.Nodes{}
}

// Propagate the internet and service pseudo nodes
if strings.HasSuffix(n.ID, TheInternetID) || strings.HasPrefix(n.ID, ServiceNodeIDPrefix) {
return report.Nodes{n.ID: n}
}

// If this node is not of the original type, exclude it. This
// excludes all the nodes we've dragged in from endpoint that we
// failed to join to a node.
id, ok := n.Latest.Lookup(originalNodeID)
if !ok {
return report.Nodes{}
}
topology, ok := n.Latest.Lookup(originalNodeTopology)
if !ok {
return report.Nodes{}
}

return report.Nodes{
id: NewDerivedNode(id, n).
WithTopology(topology),
}
return report.Nodes{id: NewDerivedNode(id, n)}
}

// endpoint2IP maps endpoint nodes to their IP address, for joining
Expand Down
3 changes: 1 addition & 2 deletions render/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ var PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
),
),
),
selectPodsWithDeployments{},
ConnectionJoin(MapPod2IP, SelectPod),
ConnectionJoin(MapPod2IP, selectPodsWithDeployments{}),
),
),
)
Expand Down