Skip to content

Commit

Permalink
Changes from feedback
Browse files Browse the repository at this point in the history
- Assume origin IDs are unique and don't reflect.Dedupe
- Improve origin ID lookup
- Move OriginTable to detailed_node.go, as a free function
  • Loading branch information
peterbourgon committed Jun 9, 2015
1 parent 27598c5 commit aa6f400
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 84 deletions.
83 changes: 68 additions & 15 deletions report/detailed_node.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package report

import (
"reflect"
"strconv"
)
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.
Expand All @@ -29,19 +26,12 @@ func MakeDetailedNode(r Report, n RenderableNode) DetailedNode {
// 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
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)
}
// Naïve equivalence-based deduplication.
for _, existing := range tables {
if reflect.DeepEqual(existing, table) {
continue outer
}
}
tables = append(tables, table)
}

return DetailedNode{
Expand All @@ -52,3 +42,66 @@ outer:
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
}
69 changes: 0 additions & 69 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,72 +110,3 @@ func (r Report) LocalNetworks() []*net.IPNet {
}
return ipNets
}

// 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 (r Report) OriginTable(originID string) (Table, bool) {
for nodeID, nodeMetadata := range r.Endpoint.NodeMetadatas {
if originID == nodeID {
return endpointOriginTable(nodeMetadata)
}
}
for nodeID, nodeMetadata := range r.Address.NodeMetadatas {
if originID == nodeID {
return addressOriginTable(nodeMetadata)
}
}
for nodeID, nodeMetadata := range r.Host.NodeMetadatas {
if originID == nodeID {
return hostOriginTable(nodeMetadata)
}
}
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
}

0 comments on commit aa6f400

Please sign in to comment.