Skip to content

Commit

Permalink
Merge pull request #194 from weaveworks/origins
Browse files Browse the repository at this point in the history
OriginHosts and OriginNodes become Origins
  • Loading branch information
peterbourgon committed Jun 9, 2015
2 parents b817031 + 667d8b8 commit ff14a61
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 180 deletions.
4 changes: 1 addition & 3 deletions app/api_topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ func handleNode(rep Reporter, t topologyView, w http.ResponseWriter, r *http.Req
http.NotFound(w, r)
return
}
originHostFunc := func(id string) (OriginHost, bool) { return getOriginHost(rpt.Host, id) }
originNodeFunc := func(id string) (OriginNode, bool) { return getOriginNode(t.selector(rpt), id) }
respondWith(w, http.StatusOK, APINode{Node: makeDetailed(node, originHostFunc, originNodeFunc)})
respondWith(w, http.StatusOK, APINode{Node: report.MakeDetailedNode(rpt, node)})
}

// Individual edges.
Expand Down
12 changes: 10 additions & 2 deletions app/api_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ func TestAPITopologyApplications(t *testing.T) {
}
equals(t, 1, len(node.Adjacency))
equals(t, report.MakeIDList("pid:node-b.local:215"), node.Adjacency)
equals(t, report.MakeIDList("hostA"), node.OriginHosts)
equals(t, report.MakeIDList(
report.MakeEndpointNodeID("hostA", "192.168.1.1", "12345"),
report.MakeEndpointNodeID("hostA", "192.168.1.1", "12346"),
report.MakeHostNodeID("hostA"),
), node.Origins,
)
equals(t, "curl", node.LabelMajor)
equals(t, "node-a.local (23128)", node.LabelMinor)
equals(t, "23128", node.Rank)
Expand Down Expand Up @@ -79,7 +84,10 @@ func TestAPITopologyHosts(t *testing.T) {
t.Errorf("missing host:host-b node")
}
equals(t, report.MakeIDList("host:host-a"), node.Adjacency)
equals(t, report.MakeIDList("hostB"), node.OriginHosts)
equals(t, report.MakeIDList(
report.MakeAddressNodeID("hostB", "192.168.1.2"),
report.MakeHostNodeID("hostB"),
), node.Origins)
equals(t, "host-b", node.LabelMajor)
equals(t, "", node.LabelMinor)
equals(t, "host-b", node.Rank)
Expand Down
94 changes: 0 additions & 94 deletions app/detail_pane.go

This file was deleted.

107 changes: 107 additions & 0 deletions report/detailed_node.go
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
}
7 changes: 7 additions & 0 deletions report/detailed_node_test.go
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")
}
17 changes: 8 additions & 9 deletions report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@ type Report struct {
// an element of a topology. It should contain information that's relevant
// to rendering a node when there are many nodes visible at once.
type RenderableNode struct {
ID string `json:"id"` //
LabelMajor string `json:"label_major"` // e.g. "process", human-readable
LabelMinor string `json:"label_minor,omitempty"` // e.g. "hostname", human-readable, optional
Rank string `json:"rank"` // to help the layout engine
Pseudo bool `json:"pseudo,omitempty"` // sort-of a placeholder node, for rendering purposes
Adjacency IDList `json:"adjacency,omitempty"` // Node IDs (in the same topology domain)
OriginHosts IDList `json:"origin_hosts,omitempty"` // Which hosts contributed information to this node
OriginNodes IDList `json:"origin_nodes,omitempty"` // Which origin nodes (depends on topology) contributed
Metadata AggregateMetadata `json:"metadata"` // Numeric sums
ID string `json:"id"` //
LabelMajor string `json:"label_major"` // e.g. "process", human-readable
LabelMinor string `json:"label_minor,omitempty"` // e.g. "hostname", human-readable, optional
Rank string `json:"rank"` // to help the layout engine
Pseudo bool `json:"pseudo,omitempty"` // sort-of a placeholder node, for rendering purposes
Adjacency IDList `json:"adjacency,omitempty"` // Node IDs (in the same topology domain)
Origins IDList `json:"origins,omitempty"` // Core node IDs that contributed information
Metadata AggregateMetadata `json:"metadata"` // Numeric sums
}

// DetailedNode is the data type that's yielded to the JavaScript layer when
Expand Down
21 changes: 10 additions & 11 deletions report/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,14 @@ func (t Topology) RenderBy(mapFunc MapFunc, pseudoFunc PseudoFunc) map[string]Re
// the existing data, on the assumption that the MapFunc returns the same
// data.
nodes[mapped.ID] = RenderableNode{
ID: mapped.ID,
LabelMajor: mapped.Major,
LabelMinor: mapped.Minor,
Rank: mapped.Rank,
Pseudo: false,
Adjacency: IDList{}, // later
OriginHosts: IDList{}, // later
OriginNodes: IDList{}, // later
Metadata: AggregateMetadata{}, // later
ID: mapped.ID,
LabelMajor: mapped.Major,
LabelMinor: mapped.Minor,
Rank: mapped.Rank,
Pseudo: false,
Adjacency: IDList{}, // later
Origins: IDList{}, // later
Metadata: AggregateMetadata{}, // later
}
address2mapped[addressID] = mapped.ID
}
Expand Down Expand Up @@ -142,8 +141,8 @@ func (t Topology) RenderBy(mapFunc MapFunc, pseudoFunc PseudoFunc) map[string]Re
}

srcRenderableNode.Adjacency = srcRenderableNode.Adjacency.Add(dstRenderableID)
srcRenderableNode.OriginHosts = srcRenderableNode.OriginHosts.Add(srcOriginHostID)
srcRenderableNode.OriginNodes = srcRenderableNode.OriginNodes.Add(srcNodeAddress)
srcRenderableNode.Origins = srcRenderableNode.Origins.Add(MakeHostNodeID(srcOriginHostID))
srcRenderableNode.Origins = srcRenderableNode.Origins.Add(srcNodeAddress)
edgeID := MakeEdgeID(srcNodeAddress, dstNodeAddress)
if md, ok := t.EdgeMetadatas[edgeID]; ok {
srcRenderableNode.Metadata.Merge(md.Transform())
Expand Down
Loading

0 comments on commit ff14a61

Please sign in to comment.