Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: bug-fix

# Change summary; a 80ish characters long description of the change.
summary: Merge multiple agent keys when loading config

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: elastic-agent

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
issue: https://github.com/elastic/elastic-agent/issues/3717
61 changes: 61 additions & 0 deletions internal/pkg/agent/cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,29 @@
package cmd

import (
_ "embed"
"fmt"
"os"
"path/filepath"
"testing"

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

"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent/internal/pkg/agent/application/paths"
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
monitoringCfg "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config"
)

var (
//go:embed testdata/run/singlelogging.yaml
singleLoggingConfig []byte

//go:embed testdata/run/splitlogging.yaml
splitLoggingConfig []byte
)

func Test_initTracer(t *testing.T) {
tenPercentSamplingRate := float32(0.1)

Expand Down Expand Up @@ -93,3 +108,49 @@ func Test_initTracer(t *testing.T) {
})
}
}

func TestRunLoadConfig(t *testing.T) {
tests := []struct {
name string
file []byte
expect func() *configuration.Configuration
}{{
name: "single logging entry",
file: singleLoggingConfig,
expect: func() *configuration.Configuration {
cfg := configuration.DefaultConfiguration()
cfg.Settings.LoggingConfig.Level = logp.DebugLevel
cfg.Settings.LoggingConfig.ToFiles = true
cfg.Settings.LoggingConfig.ToStderr = false

return cfg
},
}, {
name: "split logging entries",
file: splitLoggingConfig,
expect: func() *configuration.Configuration {
cfg := configuration.DefaultConfiguration()
cfg.Settings.LoggingConfig.Level = logp.DebugLevel
cfg.Settings.LoggingConfig.ToFiles = true
cfg.Settings.LoggingConfig.ToStderr = false

return cfg
},
}}

origCfgDir := paths.Config()
t.Cleanup(func() { paths.SetConfig(origCfgDir) })

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dir := t.TempDir()
paths.SetConfig(dir)
err := os.WriteFile(filepath.Join(dir, paths.DefaultConfigName), tt.file, 0o644)
require.NoError(t, err)

cfg, err := loadConfig(t.Context(), nil)
require.NoError(t, err)
require.Equal(t, tt.expect(), cfg)
})
}
}
5 changes: 5 additions & 0 deletions internal/pkg/agent/cmd/testdata/run/singlelogging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
agent:
logging:
level: debug
to_files: true
to_stderr: false
5 changes: 5 additions & 0 deletions internal/pkg/agent/cmd/testdata/run/splitlogging.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
agent.logging.level: debug
agent.logging.to_files: true
agent:
logging:
to_stderr: false
1 change: 1 addition & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ var DefaultOptions = []interface{}{
ucfg.IgnoreCommas,
ucfg.ResolveEnv,
ucfg.VarExp,
ucfg.FieldMergeValues("agent"),
VarSkipKeys("inputs", "outputs"),
OTelKeys("connectors", "receivers", "processors", "exporters", "extensions", "service"),
}
Expand Down