fix(go.d): prefer env-provided dirs over build-time defaults (#21345)
Ilya Mashchenko committed
Nov 24, 2025 at 13:36 UTC
a7cd2fe51888460184c349fdad0896a17724e70d
1 file changed
+21
-9
src/go/pkg/pluginconfig/pluginconfig.go
+21
-9
@@ -19,6 +19,8 @@ import (
19
"github.com/netdata/netdata/go/plugins/pkg/cli"
20
"github.com/netdata/netdata/go/plugins/pkg/executable"
21
"github.com/netdata/netdata/go/plugins/pkg/multipath"
22
+
23
+ "github.com/mattn/go-isatty"
24
)
25
26
var (
@@ -130,11 +132,11 @@ func (d *directories) initUserRoots(opts *cli.Option, env envData, execDir strin
132
roots = append(roots, p)
133
}
134
133
- // 2) NETDATA_USER_CONFIG_DIR
134
- if buildinfo.UserConfigDir != "" {
135
- roots = append(roots, safePathClean(buildinfo.UserConfigDir))
136
- } else if dir := safePathClean(env.userDir); dir != "" {
135
+ // 2) NETDATA_USER_CONFIG_DIR (env has priority over buildinfo)
136
+ if dir := safePathClean(env.userDir); dir != "" {
137
roots = append(roots, dir)
138
+ } else if buildinfo.UserConfigDir != "" {
139
+ roots = append(roots, safePathClean(buildinfo.UserConfigDir))
140
}
141
142
if len(roots) != 0 {
@@ -164,14 +166,15 @@ func (d *directories) initUserRoots(opts *cli.Option, env envData, execDir strin
166
167
// Build step 2: initialize single "stock" root: env, common locations, build-relative fallback.
168
func (d *directories) initStockRoot(env envData, execDir string) {
167
- if buildinfo.StockConfigDir != "" {
168
- d.stockConfigDir = safePathClean(buildinfo.StockConfigDir)
169
- return
170
- }
169
+ // env.stockDir has priority
170
if stock := safePathClean(env.stockDir); stock != "" {
171
d.stockConfigDir = stock
172
return
173
}
174
+ if buildinfo.StockConfigDir != "" {
175
+ d.stockConfigDir = safePathClean(buildinfo.StockConfigDir)
176
+ return
177
+ }
178
179
relDir := safePathClean(filepath.Join(execDir, "..", "..", "..", "..", "usr", "lib", "netdata", "conf.d"))
180
if isDirExists(relDir) {
@@ -254,19 +257,28 @@ func (d *directories) validate() error {
257
return nil
258
}
259
260
+var isTerm = isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsTerminal(os.Stdout.Fd())
261
+
262
func readEnvFromOS(execDir string) envData {
263
e := envData{
264
cygwinBase: os.Getenv("NETDATA_CYGWIN_BASE_PATH"),
265
userDir: os.Getenv("NETDATA_USER_CONFIG_DIR"),
266
stockDir: os.Getenv("NETDATA_STOCK_CONFIG_DIR"),
262
- varLibDir: os.Getenv("NETDATA_LIB_DIR"),
267
watchPath: os.Getenv("NETDATA_PLUGINS_GOD_WATCH_PATH"),
268
+ varLibDir: os.Getenv("NETDATA_LIB_DIR"),
269
logLevel: os.Getenv("NETDATA_LOG_LEVEL"),
270
}
271
e.userDir = handleDirOnWin(e.cygwinBase, safePathClean(e.userDir), execDir)
272
e.stockDir = handleDirOnWin(e.cygwinBase, safePathClean(e.stockDir), execDir)
273
e.varLibDir = handleDirOnWin(e.cygwinBase, safePathClean(e.varLibDir), execDir)
274
e.watchPath = handleDirOnWin(e.cygwinBase, safePathClean(e.watchPath), execDir)
275
+
276
+ if isTerm {
277
+ e.userDir = ""
278
+ e.stockDir = ""
279
+ e.watchPath = ""
280
+ }
281
+
282
return e
283
}
284