Skip to content

Commit

Permalink
Update Logger interface and use in worker.
Browse files Browse the repository at this point in the history
Based on review comment, removed some of the less likely used logger
methods. Added use of Tracef in some methods, tests updated accordingly.
  • Loading branch information
hmlanigan committed Sep 16, 2022
1 parent 9a1ace1 commit 22cc4e0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 8 deletions.
2 changes: 2 additions & 0 deletions worker/stateconverter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func (w wrapper) Machine(tag names.MachineTag) (Machine, error) {
// SetUp implements NotifyWatchHandler's SetUp method. It returns a watcher that
// checks for changes to the current machine.
func (c *converter) SetUp() (watcher.NotifyWatcher, error) {
c.logger.Tracef("Calling SetUp for %s", c.machineTag)
m, err := c.machiner.Machine(c.machineTag)
if err != nil {
return nil, errors.Trace(err)
Expand All @@ -69,6 +70,7 @@ func (c *converter) SetUp() (watcher.NotifyWatcher, error) {
// that the machine is now expected to manage the environment,
// we throw a fatal error to instigate agent restart.
func (c *converter) Handle(_ <-chan struct{}) error {
c.logger.Tracef("Calling Handle for %s", c.machineTag)
results, err := c.machine.Jobs()
if err != nil {
return errors.Annotate(err, "can't get jobs for machine")
Expand Down
3 changes: 2 additions & 1 deletion worker/stateconverter/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@ func (s *converterSuite) setupMocks(c *gc.C) *gomock.Controller {
}

func (s *converterSuite) newConverter() watcher.NotifyHandler {
return stateconverter.NewConverterForTest(s.machine, s.machiner)
logger := fakeLogger{}
return stateconverter.NewConverterForTest(s.machine, s.machiner, &logger)
}
3 changes: 0 additions & 3 deletions worker/stateconverter/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import (
type Logger interface {
Tracef(string, ...interface{})
Debugf(string, ...interface{})
Warningf(string, ...interface{})
Infof(string, ...interface{})
Errorf(string, ...interface{})
Criticalf(string, ...interface{})
}

Expand Down
1 change: 1 addition & 0 deletions worker/stateconverter/manifold.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (cfg ManifoldConfig) start(context dependency.Context) (worker.Worker, erro
return nil, errors.Trace(err)
}

cfg.Logger.Tracef("starting NotifyWorker for %s", mTag)
handlerCfg := config{
machineTag: mTag,
machiner: machiner,
Expand Down
3 changes: 0 additions & 3 deletions worker/stateconverter/manifold_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ func (s *manifoldConfigSuite) setupMocks(c *gc.C) *gomock.Controller {

type fakeLogger struct{}

func (l *fakeLogger) Errorf(format string, args ...interface{}) {}
func (l *fakeLogger) Debugf(format string, args ...interface{}) {}
func (l *fakeLogger) Warningf(format string, args ...interface{}) {}
func (l *fakeLogger) Infof(format string, args ...interface{}) {}
func (l *fakeLogger) Criticalf(format string, args ...interface{}) {}
func (l *fakeLogger) Tracef(format string, args ...interface{}) {}
3 changes: 2 additions & 1 deletion worker/stateconverter/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ func TestAll(t *testing.T) {
gc.TestingT(t)
}

func NewConverterForTest(machine Machine, machiner Machiner) watcher.NotifyHandler {
func NewConverterForTest(machine Machine, machiner Machiner, logger Logger) watcher.NotifyHandler {
return &converter{
machineTag: names.NewMachineTag("3"),
machiner: machiner,
machine: machine,
logger: logger,
}
}

0 comments on commit 22cc4e0

Please sign in to comment.