Skip to content

Commit

Permalink
Review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwilkie committed Feb 25, 2016
1 parent a0f4c66 commit 2362e46
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 188 deletions.
128 changes: 128 additions & 0 deletions render/detailed/connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package detailed

import (
"strconv"
"strings"

"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/report"
)

const (
remotePortKey = "remote_port"
localPortKey = "local_port"
countKey = "count"
number = "number"
)

func makeIncomingConnectionsTable(n render.RenderableNode, ns render.RenderableNodes) NodeSummaryGroup {
// Get all endpoint ids which are children of this node
myEndpoints := report.MakeIDList()
n.Children.ForEach(func(child render.RenderableNode) {
if child.Topology == report.Endpoint {
myEndpoints = append(myEndpoints, child.ID)
}
})

// Get the endpoint children of all nodes which point to one of my endpoint children
endpoints := map[string][]render.RenderableNode{}
for _, node := range ns {
if !node.Adjacency.Contains(n.ID) {
continue
}

node.Children.ForEach(func(child render.RenderableNode) {
if child.Topology != report.Endpoint {
return
}

for _, endpoint := range child.Adjacency.Intersection(myEndpoints) {
endpoints[endpoint] = append(endpoints[endpoint], child)
}
})
}

// Dedupe nodes talking to same port multiple times
remotes := map[string]int{}
for myend, nodes := range endpoints {
// what port are they talking to?
parts := strings.SplitN(myend, ":", 4)
if len(parts) != 4 {
continue
}
port := parts[3]

for _, node := range nodes {
// what is their IP address?
if parts := strings.SplitN(node.ID, ":", 4); len(parts) == 4 {
key := parts[2] + "|" + port
remotes[key] = remotes[key] + 1
}
}
}

return NodeSummaryGroup{
ID: "incoming-connections",
Label: "Inbound",
Columns: []Column{
{ID: localPortKey, Label: "Port"},
{ID: countKey, Label: "Count", DefaultSort: true},
},
Nodes: buildConnectionNodes(remotes, localPortKey),
}
}

func makeOutgoingConnectionsTable(n render.RenderableNode, ns render.RenderableNodes) NodeSummaryGroup {
// Get all endpoints which are children of this node
endpoints := []render.RenderableNode{}
n.Children.ForEach(func(child render.RenderableNode) {
if child.Topology == report.Endpoint {
endpoints = append(endpoints, child)
}
})

// Dedupe children talking to same port multiple times
remotes := map[string]int{}
for _, node := range endpoints {
for _, adjacent := range node.Adjacency {
if parts := strings.SplitN(adjacent, ":", 4); len(parts) == 4 {
key := parts[2] + "|" + parts[3]
remotes[key] = remotes[key] + 1
}
}
}

return NodeSummaryGroup{
ID: "outgoing-connections",
Label: "Outbound",
Columns: []Column{
{ID: remotePortKey, Label: "Port"},
{ID: countKey, Label: "Count", DefaultSort: true},
},
Nodes: buildConnectionNodes(remotes, remotePortKey),
}
}

func buildConnectionNodes(in map[string]int, columnKey string) []NodeSummary {
nodes := []NodeSummary{}
for key, count := range in {
parts := strings.SplitN(key, "|", 2)
nodes = append(nodes, NodeSummary{
ID: key,
Label: parts[0],
Metadata: []MetadataRow{
{
ID: columnKey,
Value: parts[1],
Datatype: number,
},
{
ID: countKey,
Value: strconv.Itoa(count),
Datatype: number,
},
},
})
}
return nodes
}
2 changes: 1 addition & 1 deletion render/detailed/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (c Counter) MetadataRows(n report.Node) []MetadataRow {
ID: c.ID,
Value: strconv.Itoa(val),
Prime: c.Prime,
Datatype: numberWang,
Datatype: number,
}}
}
return nil
Expand Down
156 changes: 12 additions & 144 deletions render/detailed/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package detailed

import (
"sort"
"strconv"
"strings"

"github.com/ugorji/go/codec"

Expand Down Expand Up @@ -138,11 +136,19 @@ var (
topologyID string
NodeSummaryGroup
}{
{report.Host, NodeSummaryGroup{TopologyID: "hosts", Label: "Hosts", Columns: []Column{host.CPUUsage, host.MemoryUsage}}},
{report.Host, NodeSummaryGroup{TopologyID: "hosts", Label: "Hosts", Columns: []Column{
MakeColumn(host.CPUUsage), MakeColumn(host.MemoryUsage),
}}},
{report.Pod, NodeSummaryGroup{TopologyID: "pods", Label: "Pods"}},
{report.Container, NodeSummaryGroup{TopologyID: "containers", Label: "Containers", Columns: []Column{docker.CPUTotalUsage, docker.MemoryUsage}}},
{report.Process, NodeSummaryGroup{TopologyID: "processes", Label: "Processes", Columns: []Column{process.PID, process.CPUUsage, process.MemoryUsage}}},
{report.ContainerImage, NodeSummaryGroup{TopologyID: "containers-by-image", Label: "Container Images", Columns: []Column{render.ContainersKey}}},
{report.Container, NodeSummaryGroup{TopologyID: "containers", Label: "Containers", Columns: []Column{
MakeColumn(docker.CPUTotalUsage), MakeColumn(docker.MemoryUsage),
}}},
{report.Process, NodeSummaryGroup{TopologyID: "processes", Label: "Processes", Columns: []Column{
MakeColumn(process.PID), MakeColumn(process.CPUUsage), MakeColumn(process.MemoryUsage),
}}},
{report.ContainerImage, NodeSummaryGroup{TopologyID: "containers-by-image", Label: "Container Images", Columns: []Column{
MakeColumn(render.ContainersKey),
}}},
}
)

Expand All @@ -168,141 +174,3 @@ func children(n render.RenderableNode) []NodeSummaryGroup {

return nodeSummaryGroups
}

const (
remotePortKey = "Remote Port"
localPortKey = "Local Port"
countKey = "Count"
numberWang = "number"
)

func makeIncomingConnectionsTable(n render.RenderableNode, ns render.RenderableNodes) NodeSummaryGroup {
// Get all endpoint ids which are children of this node
myEndpoints := report.MakeIDList()
n.Children.ForEach(func(child render.RenderableNode) {
if child.Topology == report.Endpoint {
myEndpoints = append(myEndpoints, child.ID)
}
})

// Get the endpoint children of all nodes which point to one of my endpoint children
endpoints := map[string][]render.RenderableNode{}
for _, node := range ns {
if !node.Adjacency.Contains(n.ID) {
continue
}

node.Children.ForEach(func(child render.RenderableNode) {
if child.Topology != report.Endpoint {
return
}

intersection := child.Adjacency.Intersection(myEndpoints)
if len(intersection) <= 0 {
return
}

for _, endpoint := range intersection {
endpoints[endpoint] = append(endpoints[endpoint], child)
}
})
}

// Dedupe nodes talking to same port multiple times
remotes := map[string]int{}
for myend, nodes := range endpoints {
// what port are they talking to?
parts := strings.SplitN(myend, ":", 4)
if len(parts) != 4 {
continue
}
port := parts[3]

for _, node := range nodes {
// what is their IP address?
if parts := strings.SplitN(node.ID, ":", 4); len(parts) == 4 {
key := parts[2] + "|" + port
remotes[key] = remotes[key] + 1
}
}
}

// Build rows for these deduped children
nodes := []NodeSummary{}
for key, count := range remotes {
parts := strings.SplitN(key, "|", 2)
nodes = append(nodes, NodeSummary{
ID: key,
Label: parts[0],
Metadata: []MetadataRow{
{
ID: localPortKey,
Value: parts[1],
Datatype: numberWang,
},
{
ID: countKey,
Value: strconv.Itoa(count),
Datatype: numberWang,
},
},
})
}

return NodeSummaryGroup{
TopologyID: report.Endpoint + "-incoming",
Label: "Connections From",
Columns: []Column{localPortKey, countKey},
Nodes: nodes,
}
}

func makeOutgoingConnectionsTable(n render.RenderableNode, ns render.RenderableNodes) NodeSummaryGroup {
// Get all endpoints which are children of this node
endpoints := []render.RenderableNode{}
n.Children.ForEach(func(child render.RenderableNode) {
if child.Topology == report.Endpoint {
endpoints = append(endpoints, child)
}
})

// Dedupe children talking to same port multiple times
remotes := map[string]int{}
for _, node := range endpoints {
for _, adjacent := range node.Adjacency {
if parts := strings.SplitN(adjacent, ":", 4); len(parts) == 4 {
key := parts[2] + "|" + parts[3]
remotes[key] = remotes[key] + 1
}
}
}

// Build rows for these deduped children
nodes := []NodeSummary{}
for key, count := range remotes {
parts := strings.SplitN(key, "|", 2)
nodes = append(nodes, NodeSummary{
ID: key,
Label: parts[0],
Metadata: []MetadataRow{
{
ID: remotePortKey,
Value: parts[1],
Datatype: numberWang,
},
{
ID: countKey,
Value: strconv.Itoa(count),
Datatype: numberWang,
},
},
})
}

return NodeSummaryGroup{
TopologyID: report.Endpoint + "-outgoing",
Label: "Connections To",
Columns: []Column{remotePortKey, countKey},
Nodes: nodes,
}
}
Loading

0 comments on commit 2362e46

Please sign in to comment.