mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 01:31:17 +00:00
Review feedback: merge host controls with reporter
This commit is contained in:
@@ -15,24 +15,15 @@ const (
|
||||
ExecHost = "host_exec"
|
||||
)
|
||||
|
||||
// Controls handles controls for a hosts.
|
||||
type Controls struct {
|
||||
pipes controls.PipeClient
|
||||
func (r *Reporter) registerControls() {
|
||||
controls.Register(ExecHost, r.execHost)
|
||||
}
|
||||
|
||||
// NewControls creates new host controls.
|
||||
func NewControls(pipes controls.PipeClient) *Controls {
|
||||
c := &Controls{pipes: pipes}
|
||||
controls.Register(ExecHost, c.execHost)
|
||||
return c
|
||||
}
|
||||
|
||||
// Stop stops the host controls.
|
||||
func (*Controls) Stop() {
|
||||
func (*Reporter) deregisterControls() {
|
||||
controls.Rm(ExecHost)
|
||||
}
|
||||
|
||||
func (c *Controls) execHost(req xfer.Request) xfer.Response {
|
||||
func (r *Reporter) execHost(req xfer.Request) xfer.Response {
|
||||
cmd := exec.Command(hostShellCmd[0], hostShellCmd[1:]...)
|
||||
cmd.Env = []string{"TERM=xterm"}
|
||||
ptyPipe, err := pty.Start(cmd)
|
||||
@@ -40,7 +31,7 @@ func (c *Controls) execHost(req xfer.Request) xfer.Response {
|
||||
return xfer.ResponseError(err)
|
||||
}
|
||||
|
||||
id, pipe, err := controls.NewPipeFromEnds(nil, ptyPipe, c.pipes, req.AppID)
|
||||
id, pipe, err := controls.NewPipeFromEnds(nil, ptyPipe, r.pipes, req.AppID)
|
||||
if err != nil {
|
||||
return xfer.ResponseError(err)
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/weaveworks/scope/common/mtime"
|
||||
"github.com/weaveworks/scope/probe/controls"
|
||||
"github.com/weaveworks/scope/report"
|
||||
)
|
||||
|
||||
@@ -37,16 +38,20 @@ type Reporter struct {
|
||||
hostID string
|
||||
hostName string
|
||||
probeID string
|
||||
pipes controls.PipeClient
|
||||
}
|
||||
|
||||
// NewReporter returns a Reporter which produces a report containing host
|
||||
// topology for this host.
|
||||
func NewReporter(hostID, hostName, probeID string) *Reporter {
|
||||
return &Reporter{
|
||||
func NewReporter(hostID, hostName, probeID string, pipes controls.PipeClient) *Reporter {
|
||||
r := &Reporter{
|
||||
hostID: hostID,
|
||||
hostName: hostName,
|
||||
probeID: probeID,
|
||||
pipes: pipes,
|
||||
}
|
||||
r.registerControls()
|
||||
return r
|
||||
}
|
||||
|
||||
// Name of this reporter, for metrics gathering
|
||||
@@ -119,3 +124,8 @@ func (r *Reporter) Report() (report.Report, error) {
|
||||
|
||||
return rep, nil
|
||||
}
|
||||
|
||||
// Stop stops the reporter.
|
||||
func (r *Reporter) Stop() {
|
||||
r.deregisterControls()
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ func TestReporter(t *testing.T) {
|
||||
host.GetMemoryUsageBytes = func() (float64, float64) { return 60.0, 100.0 }
|
||||
host.GetLocalNetworks = func() ([]*net.IPNet, error) { return []*net.IPNet{ipnet}, nil }
|
||||
|
||||
rpt, err := host.NewReporter(hostID, hostname, probeID).Report()
|
||||
rpt, err := host.NewReporter(hostID, hostname, probeID, nil).Report()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -129,9 +129,6 @@ func probeMain() {
|
||||
})
|
||||
defer clients.Stop()
|
||||
|
||||
hostControls := host.NewControls(clients)
|
||||
defer hostControls.Stop()
|
||||
|
||||
resolver := appclient.NewResolver(targets, net.LookupIP, clients.Set)
|
||||
defer resolver.Stop()
|
||||
|
||||
@@ -143,9 +140,11 @@ func probeMain() {
|
||||
|
||||
p := probe.New(*spyInterval, *publishInterval, clients)
|
||||
p.AddTicker(processCache)
|
||||
hostReporter := host.NewReporter(hostID, hostName, probeID, clients)
|
||||
defer hostReporter.Stop()
|
||||
p.AddReporter(
|
||||
endpointReporter,
|
||||
host.NewReporter(hostID, hostName, probeID),
|
||||
hostReporter,
|
||||
process.NewReporter(processCache, hostID, process.GetDeltaTotalJiffies),
|
||||
)
|
||||
p.AddTagger(probe.NewTopologyTagger(), host.NewTagger(hostID))
|
||||
|
||||
Reference in New Issue
Block a user