mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 09:41:57 +00:00
Make control handlers registry an object and extend its functionality
It is not a singleton anymore. Instead it is an object with a registry backend. The default registry backend is provided, which is equivalent to what used to be before. Custom backend can be provided for testing purposes. The registry also supports batch operations to remove and add handlers as an atomic step.
This commit is contained in:
@@ -16,11 +16,11 @@ const (
|
||||
)
|
||||
|
||||
func (r *Reporter) registerControls() {
|
||||
controls.Register(ExecHost, r.execHost)
|
||||
r.handlerRegistry.Register(ExecHost, r.execHost)
|
||||
}
|
||||
|
||||
func (*Reporter) deregisterControls() {
|
||||
controls.Rm(ExecHost)
|
||||
func (r *Reporter) deregisterControls() {
|
||||
r.handlerRegistry.Rm(ExecHost)
|
||||
}
|
||||
|
||||
func (r *Reporter) execHost(req xfer.Request) xfer.Response {
|
||||
|
||||
@@ -52,24 +52,26 @@ var (
|
||||
|
||||
// Reporter generates Reports containing the host topology.
|
||||
type Reporter struct {
|
||||
hostID string
|
||||
hostName string
|
||||
probeID string
|
||||
version string
|
||||
pipes controls.PipeClient
|
||||
hostShellCmd []string
|
||||
hostID string
|
||||
hostName string
|
||||
probeID string
|
||||
version string
|
||||
pipes controls.PipeClient
|
||||
hostShellCmd []string
|
||||
handlerRegistry *controls.HandlerRegistry
|
||||
}
|
||||
|
||||
// NewReporter returns a Reporter which produces a report containing host
|
||||
// topology for this host.
|
||||
func NewReporter(hostID, hostName, probeID, version string, pipes controls.PipeClient) *Reporter {
|
||||
func NewReporter(hostID, hostName, probeID, version string, pipes controls.PipeClient, handlerRegistry *controls.HandlerRegistry) *Reporter {
|
||||
r := &Reporter{
|
||||
hostID: hostID,
|
||||
hostName: hostName,
|
||||
probeID: probeID,
|
||||
pipes: pipes,
|
||||
version: version,
|
||||
hostShellCmd: getHostShellCmd(),
|
||||
hostID: hostID,
|
||||
hostName: hostName,
|
||||
probeID: probeID,
|
||||
pipes: pipes,
|
||||
version: version,
|
||||
hostShellCmd: getHostShellCmd(),
|
||||
handlerRegistry: handlerRegistry,
|
||||
}
|
||||
r.registerControls()
|
||||
return r
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/weaveworks/scope/common/mtime"
|
||||
"github.com/weaveworks/scope/probe/controls"
|
||||
"github.com/weaveworks/scope/probe/host"
|
||||
"github.com/weaveworks/scope/report"
|
||||
)
|
||||
@@ -55,7 +56,8 @@ 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, "", "", nil).Report()
|
||||
hr := controls.NewDefaultHandlerRegistry()
|
||||
rpt, err := host.NewReporter(hostID, hostname, "", "", nil, hr).Report()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user