-
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.
- Loading branch information
1 parent
d5dd377
commit 27598c5
Showing
8 changed files
with
211 additions
and
179 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 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 |
---|---|---|
@@ -1,94 +1 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"strconv" | ||
|
||
"github.com/weaveworks/scope/report" | ||
) | ||
|
||
func makeDetailed( | ||
n report.RenderableNode, | ||
originHostLookup func(string) (OriginHost, bool), | ||
originNodeLookup func(string) (OriginNode, bool), | ||
) report.DetailedNode { | ||
tables := []report.Table{{ | ||
Title: "Connections", | ||
Numeric: true, | ||
Rows: []report.Row{ | ||
// TODO omit these rows if there's no data? | ||
{"TCP connections", strconv.FormatInt(int64(n.Metadata[report.KeyMaxConnCountTCP]), 10), ""}, | ||
{"Bytes ingress", strconv.FormatInt(int64(n.Metadata[report.KeyBytesIngress]), 10), ""}, | ||
{"Bytes egress", strconv.FormatInt(int64(n.Metadata[report.KeyBytesEgress]), 10), ""}, | ||
}, | ||
}} | ||
|
||
// Note that a RenderableNode may be the result of merge operation(s), and | ||
// so may have multiple origin hosts and nodes. | ||
|
||
outer: | ||
for _, id := range n.OriginNodes { | ||
// Origin node IDs in e.g. the process topology are actually network | ||
// n-tuples. (The process topology is actually more like a network | ||
// n-tuple topology.) So we can have multiple IDs mapping to the same | ||
// process. There are several ways to dedupe that, but here we take | ||
// the lazy way and do simple equivalence of the resulting table. | ||
node, ok := originNodeLookup(id) | ||
if !ok { | ||
node = unknownOriginNode(id) | ||
} | ||
for _, table := range tables { | ||
if reflect.DeepEqual(table, node.Table) { | ||
continue outer | ||
} | ||
} | ||
tables = append(tables, node.Table) | ||
} | ||
|
||
for _, id := range n.OriginHosts { | ||
host, ok := originHostLookup(id) | ||
if !ok { | ||
host = unknownOriginHost(id) | ||
} | ||
tables = append(tables, report.Table{ | ||
Title: "Origin Host", | ||
Numeric: false, | ||
Rows: []report.Row{ | ||
{"Hostname", host.Hostname, ""}, | ||
{"Load", host.Load, ""}, | ||
{"OS", host.OS, ""}, | ||
{"ID", id, ""}, | ||
}, | ||
}) | ||
} | ||
|
||
return report.DetailedNode{ | ||
ID: n.ID, | ||
LabelMajor: n.LabelMajor, | ||
LabelMinor: n.LabelMinor, | ||
Pseudo: n.Pseudo, | ||
Tables: tables, | ||
} | ||
} | ||
|
||
func unknownOriginHost(id string) OriginHost { | ||
return OriginHost{ | ||
Hostname: fmt.Sprintf("[%s]", id), | ||
OS: "unknown", | ||
Networks: []string{}, | ||
Load: "", | ||
} | ||
} | ||
|
||
func unknownOriginNode(id string) OriginNode { | ||
return OriginNode{ | ||
Table: report.Table{ | ||
Title: "Origin Node", | ||
Numeric: false, | ||
Rows: []report.Row{ | ||
{"ID", id, ""}, | ||
}, | ||
}, | ||
} | ||
} |
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,54 @@ | ||
package report | ||
|
||
import ( | ||
"reflect" | ||
"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. | ||
outer: | ||
for _, id := range n.Origins { | ||
table, ok := r.OriginTable(id) | ||
if !ok { | ||
continue | ||
} | ||
// Naïve equivalence-based deduplication. | ||
for _, existing := range tables { | ||
if reflect.DeepEqual(existing, table) { | ||
continue outer | ||
} | ||
} | ||
tables = append(tables, table) | ||
} | ||
|
||
return DetailedNode{ | ||
ID: n.ID, | ||
LabelMajor: n.LabelMajor, | ||
LabelMinor: n.LabelMinor, | ||
Pseudo: n.Pseudo, | ||
Tables: tables, | ||
} | ||
} |
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.