From 2522be42faa5f3ec8b562ba7a79b8646d4b160c8 Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Wed, 31 Aug 2022 10:49:29 -0400 Subject: [PATCH] Fix lookup issues with inputs.d fragment yml (#840) * Fix lookup issues with inputs.d fragment yml The Elastic Agent was looking next to the binary for the `inputs.d` folder instead it should look up into the `Home` folder where the Elastic Agent symlink is located. Fixes: #663 * Changelog * Fix input.d path, tie to the agent Config() directory * Update CHANGELOG to reflect that the agent configuration directory is used to locate the inputs.d directory Co-authored-by: Aleksandr Maus --- CHANGELOG.next.asciidoc | 1 + internal/pkg/agent/application/local_mode.go | 2 +- internal/pkg/agent/application/paths/files.go | 8 ++++++++ internal/pkg/agent/configuration/settings.go | 5 ----- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 6f7715bdebf..f7793f7b3a9 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -112,6 +112,7 @@ - Allow the / char in variable names in eql and transpiler. {issue}715[715] {pull}718[718] - Fix data duplication for standalone agent on Kubernetes using the default manifest {issue-beats}31512[31512] {pull}742[742] - Agent updates will clean up unneeded artifacts. {issue}693[693] {issue}694[694] {pull}752[752] +- Use the Elastic Agent configuration directory as the root of the `inputs.d` folder. {issues}663[663] - Fix a panic caused by a race condition when installing the Elastic Agent. {issues}806[806] ==== New features diff --git a/internal/pkg/agent/application/local_mode.go b/internal/pkg/agent/application/local_mode.go index e6496b44860..aae202b114f 100644 --- a/internal/pkg/agent/application/local_mode.go +++ b/internal/pkg/agent/application/local_mode.go @@ -173,7 +173,7 @@ func newLocal( } func externalConfigsGlob() string { - return filepath.Join(paths.Config(), configuration.ExternalInputsPattern) + return filepath.Join(paths.AgentInputsDPath(), "*.yml") } // Routes returns a list of routes handled by agent. diff --git a/internal/pkg/agent/application/paths/files.go b/internal/pkg/agent/application/paths/files.go index 7d35549e840..e6a1bf2eda1 100644 --- a/internal/pkg/agent/application/paths/files.go +++ b/internal/pkg/agent/application/paths/files.go @@ -32,6 +32,9 @@ const defaultAgentStateStoreYmlFile = "state.yml" // defaultAgentStateStoreFile is the file that will contain the action that can be replayed after restart encrypted. const defaultAgentStateStoreFile = "state.enc" +// defaultInputDPath return the location of the inputs.d. +const defaultInputsDPath = "inputs.d" + // AgentConfigYmlFile is a name of file used to store agent information func AgentConfigYmlFile() string { return filepath.Join(Config(), defaultAgentFleetYmlFile) @@ -82,3 +85,8 @@ func AgentStateStoreYmlFile() string { func AgentStateStoreFile() string { return filepath.Join(Home(), defaultAgentStateStoreFile) } + +// AgentInputsDPath is directory that contains the fragment of inputs yaml for K8s deployment. +func AgentInputsDPath() string { + return filepath.Join(Config(), defaultInputsDPath) +} diff --git a/internal/pkg/agent/configuration/settings.go b/internal/pkg/agent/configuration/settings.go index 93ef491670f..1531c6f1c95 100644 --- a/internal/pkg/agent/configuration/settings.go +++ b/internal/pkg/agent/configuration/settings.go @@ -5,8 +5,6 @@ package configuration import ( - "path/filepath" - "github.com/elastic/elastic-agent/internal/pkg/artifact" monitoringCfg "github.com/elastic/elastic-agent/internal/pkg/core/monitoring/config" "github.com/elastic/elastic-agent/internal/pkg/core/process" @@ -15,9 +13,6 @@ import ( "github.com/elastic/elastic-agent/pkg/core/server" ) -// ExternalInputsPattern is a glob that matches the paths of external configuration files. -var ExternalInputsPattern = filepath.Join("inputs.d", "*.yml") - // SettingsConfig is an collection of agent settings configuration. type SettingsConfig struct { DownloadConfig *artifact.Config `yaml:"download" config:"download" json:"download"`