Skip to content

Commit

Permalink
it works
Browse files Browse the repository at this point in the history
  • Loading branch information
AndersonQ committed Mar 1, 2023
1 parent beca755 commit da06543
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ replace (
// Exclude this version because the version has an invalid checksum.
exclude github.com/docker/distribution v2.8.0+incompatible

replace github.com/elastic/elastic-agent-client/v7 => github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20230228215808-7bea0d6b73be
replace github.com/elastic/elastic-agent-client/v7 => github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20230301201506-8ff7d9546e6e
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/AlecAivazis/survey/v2 v2.3.2/go.mod h1:TH2kPCDU3Kqq7pLbnCWwZXDBjnhZtmsCle5EiYDJ2fg=
github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20230228215808-7bea0d6b73be h1:ELXZzC/Inb0C7/4CJ9K6chVxSeUZNSTxPQSIJmbVnuQ=
github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20230228215808-7bea0d6b73be/go.mod h1:UlVOHSDvTA4Mfdhdg+BE7aqOsUR3ab+x2Zl0aHlBXs4=
github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20230301201506-8ff7d9546e6e h1:F+wCfY2vQofeWiZFgEpslJQiis79ThHapz0DyxM6YTM=
github.com/AndersonQ/elastic-agent-client/v7 v7.0.0-20230301201506-8ff7d9546e6e/go.mod h1:UlVOHSDvTA4Mfdhdg+BE7aqOsUR3ab+x2Zl0aHlBXs4=
github.com/Azure/azure-sdk-for-go v16.2.1+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/azure-sdk-for-go v56.3.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
Expand Down
23 changes: 15 additions & 8 deletions pkg/component/fake/component/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ const (
)

type StateManager struct {
logger zerolog.Logger
inputs map[string]runningUnit
features *proto.Features
output runningUnit
logger zerolog.Logger
inputs map[string]runningUnit
output runningUnit
}

func NewStateManager(logger zerolog.Logger) *StateManager {
Expand Down Expand Up @@ -75,8 +74,6 @@ func (s *StateManager) Added(unit *client.Unit) {
}

func (s *StateManager) Modified(change client.UnitChanged) {
s.features = change.Features

unit := change.Unit
switch unit.Type() {
case client.UnitTypeOutput:
Expand All @@ -98,6 +95,13 @@ func (s *StateManager) Modified(change client.UnitChanged) {
return
}

e := s.logger.Info().Interface("change.unit", *change.Unit)
if change.Features != nil {
e.Interface("change.features", *change.Features)
} else {
e.Str("change.features", "nil")
}
e.Msgf("existingInput.Update change: %#+v", change)
err := existingInput.Update(unit, change.Triggers)
if err != nil {
_ = unit.UpdateState(
Expand Down Expand Up @@ -407,10 +411,13 @@ func (f *fakeInput) Update(u *client.Unit, triggers client.Trigger) error {
_ = u.UpdateState(f.state, f.stateMsg, nil)

if triggers&client.TriggeredFeatureChange == client.TriggeredFeatureChange {
f.logger.Debug().
f.logger.Info().
Interface("features", expected.Features).
Msg("updating features")
f.features = expected.Features
f.features = &proto.Features{
Source: nil,
Fqdn: &proto.FQDNFeature{Enabled: expected.Features.Fqdn.Enabled},
}
}

return nil
Expand Down
6 changes: 0 additions & 6 deletions pkg/component/runtime/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,6 @@ func TestManager_FakeInput_Features(t *testing.T) {
// check if config sent on iteration 1 was set,
// then change something but the feature flags.
case 2:
// check the agent's internal state
assert.True(t, componentState.Features.Fqdn.Enabled)

// check the component
res, err := m.PerformAction(
context.Background(),
Expand Down Expand Up @@ -429,9 +426,6 @@ func TestManager_FakeInput_Features(t *testing.T) {

// check again and finish test
case 3:
// check the agent's internal state
assert.True(t, componentState.Features.Fqdn.Enabled)

// check the component
res, err := m.PerformAction(
context.Background(),
Expand Down
3 changes: 1 addition & 2 deletions pkg/component/runtime/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *ComponentState) syncExpected(comp *component.Component) bool {
}
}

if s.expectedFeatures != nil &&
if comp.Features != nil &&
!gproto.Equal(s.expectedFeatures, comp.Features) {
changed = true
s.expectedFeaturesIdx++
Expand Down Expand Up @@ -236,7 +236,6 @@ func (s *ComponentState) syncUnits(comp *component.Component) bool {

if !gproto.Equal(s.Features, comp.Features) {
changed = true
s.Features = comp.Features
}

return changed
Expand Down

0 comments on commit da06543

Please sign in to comment.