From a39e14e304f65aa8b30df39934b9ef8b44d6c067 Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Mon, 20 Mar 2023 16:29:01 -0400 Subject: [PATCH] Undo unintentional changes --- magefile.go | 4 +- pkg/component/fake/component/comp/actions.go | 19 ++++---- .../fake/component/comp/component.go | 44 ++++++++++++------- pkg/component/fake/component/comp/dialer.go | 1 + pkg/component/fake/shipper/actions.go | 1 - 5 files changed, 43 insertions(+), 26 deletions(-) diff --git a/magefile.go b/magefile.go index bab63bf6032..0718ee035ee 100644 --- a/magefile.go +++ b/magefile.go @@ -320,14 +320,14 @@ func (Test) All() { // Unit runs all the unit tests. func (Test) Unit(ctx context.Context) error { - mg.Deps(Prepare.Env) + mg.Deps(Prepare.Env, Build.TestBinaries) params := devtools.DefaultGoTestUnitArgs() return devtools.GoTest(ctx, params) } // Coverage takes the coverages report from running all the tests and display the results in the browser. func (Test) Coverage() error { - mg.Deps(Prepare.Env) + mg.Deps(Prepare.Env, Build.TestBinaries) return RunGo("tool", "cover", "-html="+filepath.Join(buildDir, "coverage.out")) } diff --git a/pkg/component/fake/component/comp/actions.go b/pkg/component/fake/component/comp/actions.go index e915d2c4a7e..7ac7332bc20 100644 --- a/pkg/component/fake/component/comp/actions.go +++ b/pkg/component/fake/component/comp/actions.go @@ -113,20 +113,23 @@ func (s *killAction) Execute(_ context.Context, _ map[string]interface{}) (map[s } func newRunningUnit(logger zerolog.Logger, manager *StateManager, unit *client.Unit) (runningUnit, error) { - _, logLevel, config := unit.Expected() - if config.Type == "" { + expected := unit.Expected() + if expected.Config.Type == "" { return nil, fmt.Errorf("unit config type empty") } if unit.Type() == client.UnitTypeOutput { - switch config.Type { + switch expected.Config.Type { case fakeShipper: - return newFakeShipperOutput(logger, logLevel, unit, config) + return newFakeShipperOutput( + logger, expected.LogLevel, unit, expected.Config) } - return nil, fmt.Errorf("unknown output unit config type: %s", config.Type) + return nil, fmt.Errorf("unknown output unit config type: %s", + expected.Config.Type) } - switch config.Type { + switch expected.Config.Type { case Fake: - return newFakeInput(logger, logLevel, manager, unit, config) + return newFakeInput(logger, expected.LogLevel, manager, unit, expected.Config) } - return nil, fmt.Errorf("unknown input unit config type: %s", config.Type) + return nil, fmt.Errorf("unknown input unit config type: %s", + expected.Config.Type) } diff --git a/pkg/component/fake/component/comp/component.go b/pkg/component/fake/component/comp/component.go index ff2c9c868b4..dd12ac6d7b7 100644 --- a/pkg/component/fake/component/comp/component.go +++ b/pkg/component/fake/component/comp/component.go @@ -9,7 +9,6 @@ import ( "crypto/x509" "errors" "fmt" - "github.com/elastic/elastic-agent-libs/config" "os" "strconv" "time" @@ -87,7 +86,6 @@ func (s *StateManager) Modified(change client.UnitChanged) { _ = unit.UpdateState(client.UnitStateFailed, fmt.Sprintf("Error: %s", err), nil) } return - } case client.UnitTypeInput: existingInput, ok := s.inputs[unit.ID()] @@ -187,16 +185,17 @@ func (f *fakeShipperOutput) Update(u *client.Unit, triggers client.Trigger) erro return nil } - if config.Type == "" { + if expected.Config.Type == "" { return fmt.Errorf("unit missing config type") } - if config.Type != fakeShipper { - return fmt.Errorf("unit type changed with the same unit ID: %s", config.Type) + if expected.Config.Type != fakeShipper { + return fmt.Errorf("unit type changed with the same unit ID: %s", + expected.Config.Type) } f.stop() - f.cfg = config - f.start(u, config) + f.cfg = expected.Config + f.start(u, expected.Config) return nil } @@ -298,6 +297,8 @@ type fakeInput struct { state client.UnitState stateMsg string + features *proto.Features + canceller context.CancelFunc killerCanceller context.CancelFunc } @@ -325,6 +326,8 @@ func newFakeInput(logger zerolog.Logger, logLevel client.UnitLogLevel, manager * unit.RegisterAction(&sendEventAction{i}) logger.Trace().Msg("registering kill action for unit") unit.RegisterAction(&killAction{i.logger}) + logger.Trace().Msg("registering " + ActionRetrieveFeatures + " action for unit") + unit.RegisterAction(&retrieveFeaturesAction{i}) logger.Debug(). Str("state", i.state.String()). @@ -369,32 +372,43 @@ func (f *fakeInput) Update(u *client.Unit, triggers client.Trigger) error { expected := u.Expected() if expected.State == client.UnitStateStopped { // agent is requesting this input to stop - f.logger.Debug().Str("state", client.UnitStateStopping.String()).Str("message", stoppingMsg).Msg("updating unit state") + f.logger.Debug(). + Str("state", client.UnitStateStopping.String()). + Str("message", stoppingMsg). + Msg("updating unit state") _ = u.UpdateState(client.UnitStateStopping, stoppingMsg, nil) f.canceller() go func() { <-time.After(1 * time.Second) - f.logger.Debug().Str("state", client.UnitStateStopped.String()).Str("message", stoppedMsg).Msg("updating unit state") + f.logger.Debug(). + Str("state", client.UnitStateStopped.String()). + Str("message", stoppedMsg). + Msg("updating unit state") _ = u.UpdateState(client.UnitStateStopped, stoppedMsg, nil) }() return nil } - if config.Type == "" { + if expected.Config.Type == "" { return fmt.Errorf("unit missing config type") } - if config.Type != Fake { - return fmt.Errorf("unit type changed with the same unit ID: %s", config.Type) + if expected.Config.Type != Fake { + return fmt.Errorf("unit type changed with the same unit ID: %s", + expected.Config.Type) } - f.parseConfig(config) - state, stateMsg, err := getStateFromConfig(config) + f.parseConfig(expected.Config) + state, stateMsg, err := getStateFromConfig(expected.Config) if err != nil { return fmt.Errorf("unit config parsing error: %w", err) } + f.state = state f.stateMsg = stateMsg - f.logger.Debug().Str("state", f.state.String()).Str("message", f.stateMsg).Msg("updating unit state") + f.logger.Debug(). + Str("state", f.state.String()). + Str("message", f.stateMsg). + Msg("updating unit state") _ = u.UpdateState(f.state, f.stateMsg, nil) if triggers&client.TriggeredFeatureChange == client.TriggeredFeatureChange { diff --git a/pkg/component/fake/component/comp/dialer.go b/pkg/component/fake/component/comp/dialer.go index 7dfb5b5f0ce..4dedea72da2 100644 --- a/pkg/component/fake/component/comp/dialer.go +++ b/pkg/component/fake/component/comp/dialer.go @@ -3,6 +3,7 @@ // you may not use this file except in compliance with the Elastic License. //go:build !windows +// +build !windows package comp diff --git a/pkg/component/fake/shipper/actions.go b/pkg/component/fake/shipper/actions.go index 00983041659..0e78033dd81 100644 --- a/pkg/component/fake/shipper/actions.go +++ b/pkg/component/fake/shipper/actions.go @@ -54,7 +54,6 @@ func newRunningUnit(logger zerolog.Logger, manager *stateManager, unit *client.U } return nil, fmt.Errorf("unknown input unit config type: %s", expected.Config.Type) } - return nil, fmt.Errorf("unknown unit type: %+v", unit.Type()) }