Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent configuration overridden by default fleet config #29297

Merged
merged 4 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
- Snapshot artifact lookup will use agent.download proxy settings. {issue}27903[27903] {pull}27904[27904]
- Fix lazy acker to only add new actions to the batch. {pull}27981[27981]
- Allow HTTP metrics to run in bootstrap mode. Add ability to adjust timeouts for Fleet Server. {pull}28260[28260]
- Fix agent configuration overwritten by default fleet config. {pull}29297[29297]

==== New features

Expand Down
4 changes: 2 additions & 2 deletions x-pack/elastic-agent/pkg/agent/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ type upgraderControl interface {
}

// New creates a new Agent and bootstrap the required subsystem.
func New(log *logger.Logger, pathConfigFile string, reexec reexecManager, statusCtrl status.Controller, uc upgraderControl, agentInfo *info.AgentInfo) (Application, error) {
func New(log *logger.Logger, reexec reexecManager, statusCtrl status.Controller, uc upgraderControl, agentInfo *info.AgentInfo) (Application, error) {
// Load configuration from disk to understand in which mode of operation
// we must start the elastic-agent, the mode of operation cannot be changed without restarting the
// elastic-agent.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalpristas , based on the comments, it looks like it's expecting the elastic-agent.yml config instead of what is sent (fleet.yml). Replacing it made sure the standalone version gets the right config, also that mergeFleetConfig can merge the 2 configs

pathConfigFile := paths.ConfigFile()
rawConfig, err := config.LoadFile(pathConfigFile)
if err != nil {
return nil, err
Expand All @@ -66,7 +67,6 @@ func createApplication(
) (Application, error) {
log.Info("Detecting execution mode")
ctx := context.Background()

cfg, err := configuration.NewFromConfig(rawConfig)
if err != nil {
return nil, err
Expand Down
33 changes: 33 additions & 0 deletions x-pack/elastic-agent/pkg/agent/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,36 @@
// you may not use this file except in compliance with the Elastic License.

package application

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
)

func TestMergeFleetConfig(t *testing.T) {
cfg := map[string]interface{}{
"fleet": map[string]interface{}{
"enabled": true,
"kibana": map[string]interface{}{"host": "demo"},
"access_api_key": "123",
},
"agent": map[string]interface{}{
"grpc": map[string]interface{}{
"port": uint16(6790),
},
},
}

rawConfig := config.MustNewConfigFrom(cfg)
storage, conf, err := mergeFleetConfig(rawConfig)
require.NoError(t, err)
assert.NotNil(t, storage)
assert.NotNil(t, conf)
assert.Equal(t, conf.Fleet.Enabled, cfg["fleet"].(map[string]interface{})["enabled"])
assert.Equal(t, conf.Fleet.AccessAPIKey, cfg["fleet"].(map[string]interface{})["access_api_key"])
assert.Equal(t, conf.Settings.GRPC.Port, cfg["agent"].(map[string]interface{})["grpc"].(map[string]interface{})["port"].(uint16))
}
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/agent/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func run(streams *cli.IOStreams, override cfgOverrider) error {
}
defer control.Stop()

app, err := application.New(logger, pathConfigFile, rex, statusCtrl, control, agentInfo)
app, err := application.New(logger, rex, statusCtrl, control, agentInfo)
if err != nil {
return err
}
Expand Down