From fc10febc6e9c2b9fc12e64349a912d71217af445 Mon Sep 17 00:00:00 2001 From: Ryan Fitzpatrick Date: Mon, 12 Apr 2021 17:17:00 -0400 Subject: [PATCH] Use agent bundle-relative Collectd ConfigDir default (#263) --- internal/extension/smartagentextension/config.go | 14 ++++++++++++++ .../extension/smartagentextension/config_test.go | 5 +++-- .../smartagentextension/testdata/config.yaml | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/extension/smartagentextension/config.go b/internal/extension/smartagentextension/config.go index 032f26ab1d..b78934cf53 100644 --- a/internal/extension/smartagentextension/config.go +++ b/internal/extension/smartagentextension/config.go @@ -16,6 +16,7 @@ package smartagentextension import ( "fmt" + "path/filepath" "reflect" "strings" @@ -48,6 +49,15 @@ func customUnmarshaller(componentViperSection *viper.Viper, intoCfg interface{}) allSettings := componentViperSection.AllSettings() extensionCfg := intoCfg.(*Config) + configDirSet := false + if collectd, ok := allSettings["collectd"]; ok { + if collectdBlock, ok := collectd.(map[string]interface{}); ok { + if _, ok := collectdBlock["configdir"]; ok { + configDirSet = true + } + } + } + config, err := smartAgentConfigFromSettingsMap(allSettings) if err != nil { return err @@ -58,6 +68,10 @@ func customUnmarshaller(componentViperSection *viper.Viper, intoCfg interface{}) } config.Collectd.BundleDir = config.BundleDir + if !configDirSet { + config.Collectd.ConfigDir = filepath.Join(config.Collectd.BundleDir, "run", "collectd") + } + extensionCfg.Config = *config return nil } diff --git a/internal/extension/smartagentextension/config_test.go b/internal/extension/smartagentextension/config_test.go index 3bcac2a1a7..a2225f812a 100644 --- a/internal/extension/smartagentextension/config_test.go +++ b/internal/extension/smartagentextension/config_test.go @@ -16,6 +16,7 @@ package smartagentextension import ( "path" + "path/filepath" "testing" "time" @@ -95,7 +96,7 @@ func TestLoadConfig(t *testing.T) { cfg.Collectd.ReadThreads = 1 cfg.Collectd.WriteThreads = 4 cfg.Collectd.WriteQueueLimitHigh = 5 - cfg.Collectd.ConfigDir = "/etc/" + cfg.Collectd.ConfigDir = "/var/run/signalfx-agent/collectd" cfg.Collectd.BundleDir = "/opt/" return &cfg }(), partialSettingsConfig) @@ -191,7 +192,7 @@ func defaultConfig() Config { IntervalSeconds: 10, WriteServerIPAddr: "127.9.8.7", WriteServerPort: 0, - ConfigDir: "/var/run/signalfx-agent/collectd", + ConfigDir: filepath.Join(bundleDir, "run", "collectd"), BundleDir: bundleDir, HasGenericJMXMonitor: false, }, diff --git a/internal/extension/smartagentextension/testdata/config.yaml b/internal/extension/smartagentextension/testdata/config.yaml index c576bdd575..73643d77ff 100644 --- a/internal/extension/smartagentextension/testdata/config.yaml +++ b/internal/extension/smartagentextension/testdata/config.yaml @@ -25,7 +25,7 @@ extensions: readThreads: 1 writeThreads: 4 writeQueueLimitHigh: 5 - configDir: /etc/ + configDir: /var/run/signalfx-agent/collectd receivers: nop: