mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-01 17:20:29 +00:00
Review feedback
This commit is contained in:
@@ -29,76 +29,13 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func endpointChildrenOf(n render.RenderableNode) []render.RenderableNode {
|
||||
result := []render.RenderableNode{}
|
||||
n.Children.ForEach(func(child render.RenderableNode) {
|
||||
if _, _, _, ok := render.ParseEndpointID(child.ID); ok {
|
||||
result = append(result, child)
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
func endpointChildIDsOf(n render.RenderableNode) report.IDList {
|
||||
result := report.MakeIDList()
|
||||
n.Children.ForEach(func(child render.RenderableNode) {
|
||||
if _, _, _, ok := render.ParseEndpointID(child.ID); ok {
|
||||
result = append(result, child.ID)
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
type connectionsRow struct {
|
||||
remoteNode, localNode *render.RenderableNode
|
||||
remoteAddr, localAddr string
|
||||
port string // always the server-side port
|
||||
}
|
||||
|
||||
func buildConnectionRows(in map[connectionsRow]int, includeLocal bool) []NodeSummary {
|
||||
nodes := []NodeSummary{}
|
||||
for row, count := range in {
|
||||
id, label, linkable := row.remoteNode.ID, row.remoteNode.LabelMajor, true
|
||||
if row.remoteAddr != "" {
|
||||
id, label, linkable = row.remoteAddr+":"+row.port, row.remoteAddr, false
|
||||
}
|
||||
metadata := []MetadataRow{}
|
||||
if includeLocal {
|
||||
metadata = append(metadata,
|
||||
MetadataRow{
|
||||
ID: "foo",
|
||||
Value: row.localAddr,
|
||||
Datatype: number,
|
||||
})
|
||||
}
|
||||
metadata = append(metadata,
|
||||
MetadataRow{
|
||||
ID: portKey,
|
||||
Value: row.port,
|
||||
Datatype: number,
|
||||
},
|
||||
MetadataRow{
|
||||
ID: countKey,
|
||||
Value: strconv.Itoa(count),
|
||||
Datatype: number,
|
||||
},
|
||||
)
|
||||
nodes = append(nodes, NodeSummary{
|
||||
ID: id,
|
||||
Label: label,
|
||||
Linkable: linkable,
|
||||
Metadata: metadata,
|
||||
})
|
||||
}
|
||||
sort.Sort(nodeSummariesByID(nodes))
|
||||
return nodes
|
||||
}
|
||||
|
||||
func isInternetNode(n render.RenderableNode) bool {
|
||||
return n.ID == render.IncomingInternetID || n.ID == render.OutgoingInternetID
|
||||
}
|
||||
|
||||
func makeIncomingConnectionsTable(topologyID string, n render.RenderableNode, ns render.RenderableNodes) NodeSummaryGroup {
|
||||
func incomingConnectionsTable(topologyID string, n render.RenderableNode, ns render.RenderableNodes) NodeSummaryGroup {
|
||||
localEndpointIDs := endpointChildIDsOf(n)
|
||||
|
||||
// For each node which has an edge TO me
|
||||
@@ -143,11 +80,11 @@ func makeIncomingConnectionsTable(topologyID string, n render.RenderableNode, ns
|
||||
TopologyID: topologyID,
|
||||
Label: "Inbound",
|
||||
Columns: columnHeaders,
|
||||
Nodes: buildConnectionRows(counts, isInternetNode(n)),
|
||||
Nodes: connectionRows(counts, isInternetNode(n)),
|
||||
}
|
||||
}
|
||||
|
||||
func makeOutgoingConnectionsTable(topologyID string, n render.RenderableNode, ns render.RenderableNodes) NodeSummaryGroup {
|
||||
func outgoingConnectionsTable(topologyID string, n render.RenderableNode, ns render.RenderableNodes) NodeSummaryGroup {
|
||||
localEndpoints := endpointChildrenOf(n)
|
||||
|
||||
// For each node which has an edge FROM me
|
||||
@@ -192,6 +129,69 @@ func makeOutgoingConnectionsTable(topologyID string, n render.RenderableNode, ns
|
||||
TopologyID: topologyID,
|
||||
Label: "Outbound",
|
||||
Columns: columnHeaders,
|
||||
Nodes: buildConnectionRows(counts, isInternetNode(n)),
|
||||
Nodes: connectionRows(counts, isInternetNode(n)),
|
||||
}
|
||||
}
|
||||
|
||||
func endpointChildrenOf(n render.RenderableNode) []render.RenderableNode {
|
||||
result := []render.RenderableNode{}
|
||||
n.Children.ForEach(func(child render.RenderableNode) {
|
||||
if _, _, _, ok := render.ParseEndpointID(child.ID); ok {
|
||||
result = append(result, child)
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
func endpointChildIDsOf(n render.RenderableNode) report.IDList {
|
||||
result := report.MakeIDList()
|
||||
n.Children.ForEach(func(child render.RenderableNode) {
|
||||
if _, _, _, ok := render.ParseEndpointID(child.ID); ok {
|
||||
result = append(result, child.ID)
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
func isInternetNode(n render.RenderableNode) bool {
|
||||
return n.ID == render.IncomingInternetID || n.ID == render.OutgoingInternetID
|
||||
}
|
||||
|
||||
func connectionRows(in map[connectionsRow]int, includeLocal bool) []NodeSummary {
|
||||
nodes := []NodeSummary{}
|
||||
for row, count := range in {
|
||||
id, label, linkable := row.remoteNode.ID, row.remoteNode.LabelMajor, true
|
||||
if row.remoteAddr != "" {
|
||||
id, label, linkable = row.remoteAddr+":"+row.port, row.remoteAddr, false
|
||||
}
|
||||
metadata := []MetadataRow{}
|
||||
if includeLocal {
|
||||
metadata = append(metadata,
|
||||
MetadataRow{
|
||||
ID: "foo",
|
||||
Value: row.localAddr,
|
||||
Datatype: number,
|
||||
})
|
||||
}
|
||||
metadata = append(metadata,
|
||||
MetadataRow{
|
||||
ID: portKey,
|
||||
Value: row.port,
|
||||
Datatype: number,
|
||||
},
|
||||
MetadataRow{
|
||||
ID: countKey,
|
||||
Value: strconv.Itoa(count),
|
||||
Datatype: number,
|
||||
},
|
||||
)
|
||||
nodes = append(nodes, NodeSummary{
|
||||
ID: id,
|
||||
Label: label,
|
||||
Linkable: linkable,
|
||||
Metadata: metadata,
|
||||
})
|
||||
}
|
||||
sort.Sort(nodeSummariesByID(nodes))
|
||||
return nodes
|
||||
}
|
||||
|
||||
@@ -92,8 +92,8 @@ func MakeNode(topologyID string, r report.Report, ns render.RenderableNodes, n r
|
||||
Children: children(n),
|
||||
Parents: Parents(r, n),
|
||||
Connections: []NodeSummaryGroup{
|
||||
makeIncomingConnectionsTable(topologyID, n, ns),
|
||||
makeOutgoingConnectionsTable(topologyID, n, ns),
|
||||
incomingConnectionsTable(topologyID, n, ns),
|
||||
outgoingConnectionsTable(topologyID, n, ns),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,10 @@ func theInternetNode(m RenderableNode) RenderableNode {
|
||||
return node
|
||||
}
|
||||
|
||||
// RemapEndpointIDs remaps endpoints to have the right id format.
|
||||
// RemapEndpointIDs remaps endpoints to have an id format consistent
|
||||
// with render/id.go; no pseudo nodes are introduced in this step, so
|
||||
// that pseudo nodes introduces later are guaranteed to have endpoints
|
||||
// as children. This is needed to construct the connection details tables.
|
||||
func RemapEndpointIDs(m RenderableNode, _ report.Networks) RenderableNodes {
|
||||
addr, ok := m.Latest.Lookup(endpoint.Addr)
|
||||
if !ok {
|
||||
@@ -414,7 +417,7 @@ func MapIP2Container(n RenderableNode, _ report.Networks) RenderableNodes {
|
||||
return RenderableNodes{}
|
||||
}
|
||||
|
||||
// Propogate the internet pseudo node
|
||||
// Propagate the internet pseudo node
|
||||
if strings.HasSuffix(n.ID, TheInternetID) {
|
||||
return RenderableNodes{n.ID: n}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user