Skip to content

Commit

Permalink
Remove report squash logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Wilkie committed Jun 18, 2015
1 parent e8a9c3c commit f32d2b5
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 150 deletions.
2 changes: 1 addition & 1 deletion app/mock_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,5 +170,5 @@ func (s StaticReport) Report() report.Report {
},
},
}
return testReport.Squash()
return testReport
}
1 change: 0 additions & 1 deletion app/report_lifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ func NewReportLIFO(r reporter, maxAge time.Duration) *ReportLIFO {
for _, r := range l.reports {
report.Merge(r.Report)
}
report = report.Squash() // TODO?: make this a CLI argument.
req <- report

case q := <-l.quit:
Expand Down
30 changes: 29 additions & 1 deletion experimental/bridge/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,34 @@ 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 @@ -127,7 +155,7 @@ func discover(c collector, p publisher, fixed []string) {

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

for _, adjacent := range r.Address.Adjacency {
Expand Down
1 change: 0 additions & 1 deletion experimental/graphviz/report_lifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func NewReportLIFO(r reporter, maxAge time.Duration) *ReportLIFO {
for {
select {
case report := <-r.Reports():
report = report.Squash()
tr := timedReport{
Timestamp: time.Now(),
Report: report,
Expand Down
47 changes: 0 additions & 47 deletions report/report.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package report

import (
"net"
"strings"
)

// Report is the core data type. It's produced by probes, and consumed and
// stored by apps. It's composed of multiple topologies, each representing
// a different (related, but not equivalent) view of the network.
Expand Down Expand Up @@ -91,48 +86,6 @@ func MakeReport() Report {
}
}

// Squash squashes all non-local nodes in the report to a super-node called
// the Internet.
func (r Report) Squash() Report {
localNetworks := r.LocalNetworks()
r.Endpoint = r.Endpoint.Squash(EndpointIDAddresser, localNetworks)
r.Address = r.Address.Squash(AddressIDAddresser, localNetworks)
r.Process = r.Process.Squash(PanicIDAddresser, localNetworks)
r.Container = r.Container.Squash(PanicIDAddresser, localNetworks)
r.ContainerImage = r.ContainerImage.Squash(PanicIDAddresser, localNetworks)
r.Host = r.Host.Squash(PanicIDAddresser, localNetworks)
r.Overlay = r.Overlay.Squash(PanicIDAddresser, localNetworks)
return r
}

// 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 (r Report) LocalNetworks() []*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
}

// Topologies returns a slice of Topologies in this report
func (r Report) Topologies() []Topology {
return []Topology{r.Endpoint, r.Address, r.Process, r.Container,
Expand Down
55 changes: 0 additions & 55 deletions report/report_test.go

This file was deleted.

44 changes: 0 additions & 44 deletions report/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package report

import (
"fmt"
"net"
"strings"
)

Expand Down Expand Up @@ -75,49 +74,6 @@ func NewTopology() Topology {
}
}

// Squash squashes all non-local nodes in the topology to a super-node called
// the Internet.
// We rely on the values in the t.Adjacency lists being valid keys in
// t.NodeMetadata (or t.Adjacency).
func (t Topology) Squash(f IDAddresser, localNets []*net.IPNet) Topology {
isRemote := func(id string) bool {
if _, ok := t.NodeMetadatas[id]; ok {
return false // it is a node, cannot possibly be remote
}

if _, ok := t.Adjacency[MakeAdjacencyID(id)]; ok {
return false // it is in our adjacency list, cannot possibly be remote
}

if ip := f(id); ip != nil && netsContain(localNets, ip) {
return false // it is in our local nets, so it is not remote
}

return true
}

for srcID, dstIDs := range t.Adjacency {
newDstIDs := make(IDList, 0, len(dstIDs))
for _, dstID := range dstIDs {
if isRemote(dstID) {
dstID = TheInternet
}
newDstIDs = newDstIDs.Add(dstID)
}
t.Adjacency[srcID] = newDstIDs
}
return t
}

func netsContain(nets []*net.IPNet, ip net.IP) bool {
for _, net := range nets {
if net.Contains(ip) {
return true
}
}
return false
}

// Validate checks the topology for various inconsistencies.
func (t Topology) Validate() error {
// Check all edge metadata keys must have the appropriate entries in
Expand Down

0 comments on commit f32d2b5

Please sign in to comment.