Skip to content

Commit

Permalink
[Fleet] Fix merge config with APM change (#3508) (#3509)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3fbba14)

Co-authored-by: Nicolas Chaulet <nicolas.chaulet@elastic.co>
  • Loading branch information
mergify[bot] and nchaulet authored May 1, 2024
1 parent e9ed1a8 commit 2d4a1bc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ var DefaultOptions = []ucfg.Option{
ucfg.FieldReplaceValues("inputs"),
}

var MergeOptions = []ucfg.Option{
ucfg.PathSep("."),
ucfg.ResolveEnv,
ucfg.VarExp,
ucfg.FieldMergeValues("inputs"),
}

const kRedacted = "[redacted]"

// Config is the global configuration.
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/server/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func (a *Agent) configFromUnits(ctx context.Context) (*config.Config, error) {
},
},
}}
err = cfgData.Merge(obj, config.DefaultOptions...)
err = cfgData.Merge(obj, config.MergeOptions...)
if err != nil {
zerolog.Ctx(ctx).Warn().Err(err).Msg("Failed to merge APM config into cfgData")
}
Expand Down
16 changes: 15 additions & 1 deletion internal/pkg/server/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ func Test_Agent_configFromUnits(t *testing.T) {
"server": map[string]interface{}{
"host": "0.0.0.0",
},
"policy": map[string]interface{}{
"id": "test-policy",
},
})
require.NoError(t, err)
mockInClient := &mockClientUnit{}
Expand All @@ -276,8 +279,18 @@ func Test_Agent_configFromUnits(t *testing.T) {
},
})

cliCfg, err := ucfg.NewFrom(map[string]interface{}{
"inputs": []interface{}{
map[string]interface{}{
"policy": map[string]interface{}{
"id": "test-policy",
},
},
},
})
require.NoError(t, err)
a := &Agent{
cliCfg: ucfg.New(),
cliCfg: cliCfg,
agent: mockAgent,
inputUnit: mockInClient,
outputUnit: mockOutClient,
Expand All @@ -287,6 +300,7 @@ func Test_Agent_configFromUnits(t *testing.T) {
require.NoError(t, err)
require.Len(t, cfg.Inputs, 1)
assert.Equal(t, "fleet-server", cfg.Inputs[0].Type)
assert.Equal(t, "test-policy", cfg.Inputs[0].Policy.ID)
assert.Equal(t, "0.0.0.0", cfg.Inputs[0].Server.Host)
assert.True(t, cfg.Inputs[0].Server.Instrumentation.Enabled)
assert.False(t, cfg.Inputs[0].Server.Instrumentation.TLS.SkipVerify)
Expand Down

0 comments on commit 2d4a1bc

Please sign in to comment.