-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OriginHosts and OriginNodes become Origins
Another baby step towards #123, this change follows from #192 and merges the two concepts of Origin in a renderable node. We also cut out a layer of abstraction, and add an OriginTable method to Report, which directly generates a table of info for the detail pane given any origin node ID. Other changes from feedback: - Assume origin IDs are unique and don't reflect.Dedupe - Improve origin ID lookup - Move OriginTable to detailed_node.go, as a free function - rm app/detail_pane.go (empty)
- Loading branch information
1 parent
d5dd377
commit 667d8b8
Showing
8 changed files
with
195 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package report | ||
|
||
import "strconv" | ||
|
||
// MakeDetailedNode transforms a renderable node to a detailed node. It uses | ||
// aggregate metadata, plus the set of origin node IDs, to produce tables. | ||
func MakeDetailedNode(r Report, n RenderableNode) DetailedNode { | ||
tables := []Table{} | ||
{ | ||
rows := []Row{} | ||
if val, ok := n.Metadata[KeyMaxConnCountTCP]; ok { | ||
rows = append(rows, Row{"TCP connections", strconv.FormatInt(int64(val), 10), ""}) | ||
} | ||
if val, ok := n.Metadata[KeyBytesIngress]; ok { | ||
rows = append(rows, Row{"Bytes ingress", strconv.FormatInt(int64(val), 10), ""}) | ||
} | ||
if val, ok := n.Metadata[KeyBytesEgress]; ok { | ||
rows = append(rows, Row{"Bytes egress", strconv.FormatInt(int64(val), 10), ""}) | ||
} | ||
if len(rows) > 0 { | ||
tables = append(tables, Table{"Connections", true, rows}) | ||
} | ||
} | ||
|
||
// RenderableNode may be the result of merge operation(s), and so may have | ||
// multiple origins. The ultimate goal here is to generate tables to view | ||
// in the UI, so we skip the intermediate representations, but we could | ||
// add them later. | ||
for _, id := range n.Origins { | ||
if table, ok := OriginTable(r, id); ok { | ||
// Origin node IDs are unique, so we'll be optimistic, here, and | ||
// assume they'll also produce unique tables. | ||
tables = append(tables, table) | ||
} | ||
} | ||
|
||
return DetailedNode{ | ||
ID: n.ID, | ||
LabelMajor: n.LabelMajor, | ||
LabelMinor: n.LabelMinor, | ||
Pseudo: n.Pseudo, | ||
Tables: tables, | ||
} | ||
} | ||
|
||
// OriginTable produces a table (to be consumed directly by the UI) based on | ||
// an origin ID, which is (optimistically) a node ID in one of our topologies. | ||
func OriginTable(r Report, originID string) (Table, bool) { | ||
if nmd, ok := r.Endpoint.NodeMetadatas[originID]; ok { | ||
return endpointOriginTable(nmd) | ||
} | ||
if nmd, ok := r.Address.NodeMetadatas[originID]; ok { | ||
return addressOriginTable(nmd) | ||
} | ||
if nmd, ok := r.Host.NodeMetadatas[originID]; ok { | ||
return hostOriginTable(nmd) | ||
} | ||
return Table{}, false | ||
} | ||
|
||
func endpointOriginTable(nmd NodeMetadata) (Table, bool) { | ||
rows := []Row{} | ||
if val, ok := nmd["endpoint"]; ok { | ||
rows = append(rows, Row{"Endpoint", val, ""}) | ||
} | ||
if val, ok := nmd["host_name"]; ok { | ||
rows = append(rows, Row{"Host name", val, ""}) | ||
} | ||
return Table{ | ||
Title: "Origin Endpoint", | ||
Numeric: false, | ||
Rows: rows, | ||
}, len(rows) > 0 | ||
} | ||
|
||
func addressOriginTable(nmd NodeMetadata) (Table, bool) { | ||
rows := []Row{} | ||
if val, ok := nmd["address"]; ok { | ||
rows = append(rows, Row{"Address", val, ""}) | ||
} | ||
if val, ok := nmd["host_name"]; ok { | ||
rows = append(rows, Row{"Host name", val, ""}) | ||
} | ||
return Table{ | ||
Title: "Origin Address", | ||
Numeric: false, | ||
Rows: rows, | ||
}, len(rows) > 0 | ||
} | ||
|
||
func hostOriginTable(nmd NodeMetadata) (Table, bool) { | ||
rows := []Row{} | ||
if val, ok := nmd["host_name"]; ok { | ||
rows = append(rows, Row{"Host name", val, ""}) | ||
} | ||
if val, ok := nmd["load"]; ok { | ||
rows = append(rows, Row{"Load", val, ""}) | ||
} | ||
if val, ok := nmd["os"]; ok { | ||
rows = append(rows, Row{"Operating system", val, ""}) | ||
} | ||
return Table{ | ||
Title: "Origin Host", | ||
Numeric: false, | ||
Rows: rows, | ||
}, len(rows) > 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package report_test | ||
|
||
import "testing" | ||
|
||
func TestMakeDetailedNode(t *testing.T) { | ||
t.Skip("TODO") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.