Skip to content

Commit e670978

Browse files
committed
added log message
1 parent 350e00b commit e670978

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

internal/pkg/agent/application/coordinator/coordinator.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ func (c *Coordinator) processConfigAgent(ctx context.Context, cfg *config.Config
16371637
// override retrieved config from Fleet with persisted config from AgentConfig file
16381638

16391639
if c.caps != nil {
1640-
if err := applyPersistedConfig(cfg, paths.ConfigFile(), c.isContainerizedEnvironment, c.caps.AllowFleetOverride); err != nil {
1640+
if err := applyPersistedConfig(c.logger, cfg, paths.ConfigFile(), c.isContainerizedEnvironment, c.caps.AllowFleetOverride); err != nil {
16411641
return fmt.Errorf("could not apply persisted configuration: %w", err)
16421642
}
16431643
}
@@ -1729,10 +1729,11 @@ func (c *Coordinator) generateAST(cfg *config.Config, m map[string]interface{})
17291729
return nil
17301730
}
17311731

1732-
func applyPersistedConfig(cfg *config.Config, configFile string, checkFns ...func() bool) error {
1733-
for _, checkFn := range checkFns {
1732+
func applyPersistedConfig(logger *logger.Logger, cfg *config.Config, configFile string, checkFns ...func() bool) error {
1733+
for checkNo, checkFn := range checkFns {
17341734
if !checkFn() {
17351735
// Feature is disabled, nothing to do
1736+
logger.Infof("Applying persisted configuration is disabled by check with idx %d.", checkNo)
17361737
return nil
17371738
}
17381739
}

internal/pkg/agent/application/coordinator/coordinator_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import (
5050
agentclient "github.com/elastic/elastic-agent/pkg/control/v2/client"
5151
"github.com/elastic/elastic-agent/pkg/control/v2/cproto"
5252
"github.com/elastic/elastic-agent/pkg/core/logger"
53+
"github.com/elastic/elastic-agent/pkg/core/logger/loggertest"
5354
)
5455

5556
const (
@@ -1029,9 +1030,22 @@ func Test_ApplyPersistedConfig(t *testing.T) {
10291030
cfg, err := config.LoadFile(filepath.Join(".", "testdata", "config.yaml"))
10301031
require.NoError(t, err)
10311032

1032-
err = applyPersistedConfig(cfg, cfgFile, func() bool { return tc.featureEnable })
1033+
testLogger, observedLogs := loggertest.New("")
1034+
err = applyPersistedConfig(testLogger, cfg, cfgFile, func() bool { return tc.featureEnable })
10331035
require.NoError(t, err)
10341036

1037+
found := false
1038+
// check that a log message was emitted about disabling kafka output
1039+
logs := observedLogs.All()
1040+
for _, logEntry := range logs {
1041+
if strings.Contains(logEntry.Message, "is disabled") {
1042+
found = true
1043+
break
1044+
}
1045+
}
1046+
1047+
require.NotEqualf(t, tc.featureEnable, found, "expected log message")
1048+
10351049
c := &configuration.Configuration{}
10361050
require.NoError(t, cfg.Agent.Unpack(&c))
10371051

0 commit comments

Comments
 (0)