Skip to content

Commit

Permalink
Make render module produce The Internet pseudo node.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Jun 19, 2015
1 parent f32d2b5 commit 49dae07
Show file tree
Hide file tree
Showing 19 changed files with 346 additions and 308 deletions.
23 changes: 12 additions & 11 deletions app/api_topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,35 @@ func TestAPITopologyHosts(t *testing.T) {
t.Fatal(err)
}
equals(t, 3, len(topo.Nodes))
node, ok := topo.Nodes["host:host-b"]
node, ok := topo.Nodes["host:hostB"]
if !ok {
t.Errorf("missing host:host-b node")
t.Errorf("missing host:hostB node")
t.Errorf("%+v", topo)
}
equals(t, report.MakeIDList("host:host-a"), node.Adjacency)
equals(t, report.MakeIDList("host:hostA"), node.Adjacency)
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)
equals(t, "node-b", node.LabelMajor)
equals(t, "local", node.LabelMinor)
equals(t, "local", node.Rank)
equals(t, false, node.Pseudo)
}
{
body := getRawJSON(t, ts, "/api/topology/hosts/host:host-b")
body := getRawJSON(t, ts, "/api/topology/hosts/host:hostB")
var node APINode
if err := json.Unmarshal(body, &node); err != nil {
t.Fatal(err)
}
equals(t, "host:host-b", node.Node.ID)
equals(t, "host-b", node.Node.LabelMajor)
equals(t, "", node.Node.LabelMinor)
equals(t, "host:hostB", node.Node.ID)
equals(t, "node-b", node.Node.LabelMajor)
equals(t, "local", node.Node.LabelMinor)
equals(t, false, node.Node.Pseudo)
// Let's not unit-test the specific content of the detail tables
}
{
body := getRawJSON(t, ts, "/api/topology/hosts/host:host-b/host:host-a")
body := getRawJSON(t, ts, "/api/topology/hosts/host:hostB/host:hostA")
var edge APIEdge
if err := json.Unmarshal(body, &edge); err != nil {
t.Fatalf("JSON parse error: %s", err)
Expand Down
20 changes: 11 additions & 9 deletions app/mock_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ func (s StaticReport) Report() report.Report {
},
NodeMetadatas: report.NodeMetadatas{
report.MakeAddressNodeID("hostA", "192.168.1.1"): report.NodeMetadata{
"name": "host-a",
"addr": "192.168.1.1",
report.HostNodeID: report.MakeHostNodeID("hostA"),
},
report.MakeAddressNodeID("hostB", "192.168.1.2"): report.NodeMetadata{
"name": "host-b",
"addr": "192.168.1.2",
report.HostNodeID: report.MakeHostNodeID("hostB"),
},
},
Expand All @@ -157,15 +157,17 @@ func (s StaticReport) Report() report.Report {
EdgeMetadatas: report.EdgeMetadatas{},
NodeMetadatas: report.NodeMetadatas{
report.MakeHostNodeID("hostA"): report.NodeMetadata{
"host_name": "node-a.local",
"os": "Linux",
"local_networks": localNet.String(),
"load": "3.14 2.71 1.61",
"host_name": "node-a.local",
"os": "Linux",
"local_networks": localNet.String(),
"load": "3.14 2.71 1.61",
report.HostNodeID: report.MakeHostNodeID("hostA"),
},
report.MakeHostNodeID("hostB"): report.NodeMetadata{
"host_name": "node-b.local",
"os": "Linux",
"local_networks": localNet.String(),
"host_name": "node-b.local",
"os": "Linux",
"local_networks": localNet.String(),
report.HostNodeID: report.MakeHostNodeID("hostB"),
},
},
},
Expand Down
3 changes: 1 addition & 2 deletions app/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/gorilla/mux"

"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/report"
)

// Router gives of the HTTP dispatcher. It will always use the embedded HTML
Expand Down Expand Up @@ -70,7 +69,7 @@ var topologyRegistry = map[string]topologyView{
"hosts": {
human: "Hosts",
parent: "",
renderer: render.LeafMap{Selector: report.SelectAddress, Mapper: render.NetworkHostname, Pseudo: render.GenericPseudoNode},
renderer: render.HostRenderer,
},
}

Expand Down
31 changes: 2 additions & 29 deletions experimental/bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"syscall"
"time"

"github.com/weaveworks/scope/render"
"github.com/weaveworks/scope/report"
"github.com/weaveworks/scope/xfer"
)
Expand Down Expand Up @@ -112,34 +113,6 @@ func makeAvoid(fixed []string) map[string]struct{} {
return avoid
}

// LocalNetworks returns a superset of the networks (think: CIDRs) that are
// "local" from the perspective of each host represented in the report. It's
// used to determine which nodes in the report are "remote", i.e. outside of
// our infrastructure.
func LocalNetworks(r report.Report) []*net.IPNet {
var ipNets []*net.IPNet
for _, md := range r.Host.NodeMetadatas {
val, ok := md["local_networks"]
if !ok {
continue
}
outer:
for _, s := range strings.Fields(val) {
_, ipNet, err := net.ParseCIDR(s)
if err != nil {
continue
}
for _, existing := range ipNets {
if ipNet.String() == existing.String() {
continue outer
}
}
ipNets = append(ipNets, ipNet)
}
}
return ipNets
}

// discover reads reports from a collector and republishes them on the
// publisher, while scanning the reports for IPs to connect to. Only addresses
// in the network topology of the report are considered. IPs listed in fixed
Expand All @@ -155,7 +128,7 @@ func discover(c collector, p publisher, fixed []string) {

var (
now = time.Now()
localNets = LocalNetworks(r)
localNets = render.LocalNetworks(r)
)

for _, adjacent := range r.Address.Adjacency {
Expand Down
2 changes: 1 addition & 1 deletion experimental/graphviz/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func engine(r *http.Request) string {
func mapFunc(r *http.Request) render.LeafMapFunc {
switch strings.ToLower(r.FormValue("map_func")) {
case "hosts", "networkhost", "networkhostname":
return render.NetworkHostname
return render.MapAddressIdentity
}
return render.MapProcessIdentity
}
Expand Down
4 changes: 3 additions & 1 deletion probe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ func main() {
select {
case <-pubTick:
publishTicks.WithLabelValues().Add(1)
r.Host = hostTopology(hostID, hostName)
publisher.Publish(r)
r = report.MakeReport()

case <-spyTick:
r.Merge(spy(hostID, hostName, *spyProcs))

// Do this every tick so it gets tagged by the OriginHostTagger
r.Host = hostTopology(hostID, hostName)

// TODO abstract PIDTree to a process provider, and provide an
// alternate implementation for Darwin.
if runtime.GOOS == linux {
Expand Down
1 change: 1 addition & 0 deletions probe/spy.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func addConnection(
if _, ok := r.Address.NodeMetadatas[scopedLocal]; !ok {
r.Address.NodeMetadatas[scopedLocal] = report.NodeMetadata{
"name": hostName,
"addr": c.LocalAddress.String(),
}
}

Expand Down
5 changes: 1 addition & 4 deletions render/detailed_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,9 @@ func endpointOriginTable(nmd report.NodeMetadata) (Table, bool) {

func addressOriginTable(nmd report.NodeMetadata) (Table, bool) {
rows := []Row{}
if val, ok := nmd["address"]; ok {
if val, ok := nmd["addr"]; 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,
Expand Down
2 changes: 1 addition & 1 deletion render/detailed_node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestOriginTable(t *testing.T) {
Title: "Origin Address",
Numeric: false,
Rows: []render.Row{
{"Host name", clientHostName, ""},
{"Address", clientIP, ""},
},
},
serverProcessNodeID: {
Expand Down
Loading

0 comments on commit 49dae07

Please sign in to comment.