Skip to content

Commit

Permalink
Use agent bundle-relative Collectd ConfigDir default (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmfitzpatrick authored Apr 12, 2021
1 parent 75dfd86 commit fc10feb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
14 changes: 14 additions & 0 deletions internal/extension/smartagentextension/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package smartagentextension

import (
"fmt"
"path/filepath"
"reflect"
"strings"

Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
5 changes: 3 additions & 2 deletions internal/extension/smartagentextension/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package smartagentextension

import (
"path"
"path/filepath"
"testing"
"time"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extensions:
readThreads: 1
writeThreads: 4
writeQueueLimitHigh: 5
configDir: /etc/
configDir: /var/run/signalfx-agent/collectd

receivers:
nop:
Expand Down

0 comments on commit fc10feb

Please sign in to comment.