@cryptotaxi247 / netdata-1 / commits / bab848e34

chore(go.d): add build-time configuration directory paths (#20913)

Ilya Mashchenko committed Sep 2, 2025 at 17:49 UTC bab848e34e1482088ce5747f89caadedc55968ee
3 files changed +23 -8
src/go/pkg/buildinfo/buildinfo.go new
+14
@@ -0,0 +1,14 @@
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +package buildinfo
4 +
5 +// Version stores the agent's version number. It's set during the build process using build flags.
6 +var Version = "v0.0.0"
7 +
8 +// UserConfigDir stores the path to the user configuration directory.
9 +// This value is set during the build process using build flags.
10 +var UserConfigDir = ""
11 +
12 +// StockConfigDir stores the path to the stock (default) configuration directory.
13 +// This value is set during the build process using build flags.
14 +var StockConfigDir = ""
src/go/pkg/buildinfo/version.go deleted
-6
@@ -1,6 +0,0 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -package buildinfo
4 -
5 -// Version stores the agent's version number. It's set during the build process using build flags.
6 -var Version = "v0.0.0"
src/go/plugin/go.d/pkg/pluginconfig/pluginconfig.go
+9 -2
@@ -15,6 +15,7 @@ import (
15 "strings"
16 "sync"
17
18 + "github.com/netdata/netdata/go/plugins/pkg/buildinfo"
19 "github.com/netdata/netdata/go/plugins/pkg/executable"
20 "github.com/netdata/netdata/go/plugins/pkg/multipath"
21 "github.com/netdata/netdata/go/plugins/plugin/go.d/cli"
@@ -126,8 +127,10 @@ func (d *directories) initUserRoots(opts *cli.Option, env envData, execDir strin
127 }
128
129 // 2) NETDATA_USER_CONFIG_DIR
129 - if env.userDir != "" {
130 - roots = append(roots, safePathClean(env.userDir))
130 + if buildinfo.UserConfigDir != "" {
131 + roots = append(roots, safePathClean(buildinfo.UserConfigDir))
132 + } else if dir := safePathClean(env.userDir); dir != "" {
133 + roots = append(roots, dir)
134 }
135
136 if len(roots) != 0 {
@@ -157,6 +160,10 @@ func (d *directories) initUserRoots(opts *cli.Option, env envData, execDir strin
160
161 // Build step 2: initialize single "stock" root: env, common locations, build-relative fallback.
162 func (d *directories) initStockRoot(env envData, execDir string) {
163 + if buildinfo.StockConfigDir != "" {
164 + d.stockConfigDir = safePathClean(buildinfo.StockConfigDir)
165 + return
166 + }
167 if stock := safePathClean(env.stockDir); stock != "" {
168 d.stockConfigDir = stock
169 return