Add build constraint on Linux-only features

Split Reporter into Linux and non-Linux parts, and stubbed it out for
non-Linux targets.
This commit is contained in:
Bryan Boreham
2018-08-05 21:56:03 +00:00
parent 01ef6a104d
commit 95ce2cb1a8
9 changed files with 84 additions and 42 deletions

View File

@@ -1,3 +1,5 @@
// +build linux
package endpoint
import (

View File

@@ -1,3 +1,5 @@
// +build linux
package endpoint
import (

View File

@@ -1,3 +1,5 @@
// +build linux
package endpoint
import (

View File

@@ -1,3 +1,5 @@
// +build linux
package endpoint
import (

View File

@@ -1,3 +1,5 @@
// +build linux
package endpoint
import (

View File

@@ -1,3 +1,5 @@
// +build linux
package endpoint
import (

View File

@@ -31,13 +31,6 @@ type ReporterConfig struct {
DNSSnooper *DNSSnooper
}
// Reporter generates Reports containing the Endpoint topology.
type Reporter struct {
conf ReporterConfig
connectionTracker connectionTracker
natMapper natMapper
}
// SpyDuration is an exported prometheus metric
var SpyDuration = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
@@ -50,40 +43,5 @@ var SpyDuration = prometheus.NewSummaryVec(
[]string{},
)
// NewReporter creates a new Reporter that invokes procspy.Connections to
// generate a report.Report that contains every discovered (spied) connection
// on the host machine, at the granularity of host and port. That information
// is stored in the Endpoint topology. It optionally enriches that topology
// with process (PID) information.
func NewReporter(conf ReporterConfig) *Reporter {
return &Reporter{
conf: conf,
connectionTracker: newConnectionTracker(conf),
natMapper: makeNATMapper(newConntrackFlowWalker(conf.UseConntrack, conf.ProcRoot, conf.BufferSize, true /* natOnly */)),
}
}
// Name of this reporter, for metrics gathering
func (Reporter) Name() string { return "Endpoint" }
// Stop stop stop
func (r *Reporter) Stop() {
r.connectionTracker.Stop()
r.natMapper.stop()
if r.conf.Scanner != nil {
r.conf.Scanner.Stop()
}
}
// Report implements Reporter.
func (r *Reporter) Report() (report.Report, error) {
defer func(begin time.Time) {
SpyDuration.WithLabelValues().Observe(time.Since(begin).Seconds())
}(time.Now())
rpt := report.MakeReport()
r.connectionTracker.ReportConnections(&rpt)
r.natMapper.applyNAT(rpt, r.conf.HostID)
return rpt, nil
}

View File

@@ -0,0 +1,51 @@
// +build linux
package endpoint
import (
"time"
"github.com/weaveworks/scope/report"
)
// Reporter generates Reports containing the Endpoint topology.
type Reporter struct {
conf ReporterConfig
connectionTracker connectionTracker
natMapper natMapper
}
// NewReporter creates a new Reporter that invokes procspy.Connections to
// generate a report.Report that contains every discovered (spied) connection
// on the host machine, at the granularity of host and port. That information
// is stored in the Endpoint topology. It optionally enriches that topology
// with process (PID) information.
func NewReporter(conf ReporterConfig) *Reporter {
return &Reporter{
conf: conf,
connectionTracker: newConnectionTracker(conf),
natMapper: makeNATMapper(newConntrackFlowWalker(conf.UseConntrack, conf.ProcRoot, conf.BufferSize, true /* natOnly */)),
}
}
// Stop stop stop
func (r *Reporter) Stop() {
r.connectionTracker.Stop()
r.natMapper.stop()
if r.conf.Scanner != nil {
r.conf.Scanner.Stop()
}
}
// Report implements Reporter.
func (r *Reporter) Report() (report.Report, error) {
defer func(begin time.Time) {
SpyDuration.WithLabelValues().Observe(time.Since(begin).Seconds())
}(time.Now())
rpt := report.MakeReport()
r.connectionTracker.ReportConnections(&rpt)
r.natMapper.applyNAT(rpt, r.conf.HostID)
return rpt, nil
}

View File

@@ -0,0 +1,21 @@
// +build !linux
package endpoint
import "github.com/weaveworks/scope/report"
// Reporter dummy
type Reporter struct{}
// NewReporter makes a dummy
func NewReporter(conf ReporterConfig) *Reporter {
return &Reporter{}
}
// Stop dummy
func (r *Reporter) Stop() {}
// Report implements Reporter.
func (r *Reporter) Report() (report.Report, error) {
return report.MakeReport(), nil
}