Skip to content

Commit

Permalink
Review feedback: merge host controls with reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfonso Acosta committed Mar 29, 2016
1 parent c1c40ad commit 59af5d2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
19 changes: 5 additions & 14 deletions probe/host/controls.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,23 @@ 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)
if err != nil {
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)
}
Expand Down
14 changes: 12 additions & 2 deletions probe/host/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/weaveworks/scope/common/mtime"
"github.com/weaveworks/scope/probe/controls"
"github.com/weaveworks/scope/report"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -119,3 +124,8 @@ func (r *Reporter) Report() (report.Report, error) {

return rep, nil
}

// Stop stops the reporter.
func (r *Reporter) Stop() {
r.deregisterControls()
}
2 changes: 1 addition & 1 deletion probe/host/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 3 additions & 4 deletions prog/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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))
Expand Down

0 comments on commit 59af5d2

Please sign in to comment.