chore(go.d/snmp-profiles): skip abstract when loading (#20576)
Ilya Mashchenko committed
Jun 25, 2025 at 13:30 UTC
8f46a5e9d7180ea1118d0d4f7b29443d4a31e34d
2 files changed
+22
-15
src/go/plugin/go.d/collector/snmp/ddsnmp/load.go
+15
-14
@@ -31,16 +31,11 @@ var (
31
32
func loadProfiles() {
33
loadOnce.Do(func() {
34
- userDirs, stockDirs := getProfilesDirs()
35
- extendsPaths := multipath.New(userDirs, stockDirs)
36
-
34
+ profilesPaths := getProfilesDirs()
35
seen := make(map[string]bool)
36
39
- for _, dir := range extendsPaths {
40
- if dir == "" {
41
- continue
42
- }
43
- profiles, err := loadProfilesFromDir(dir, extendsPaths)
37
+ for _, dir := range profilesPaths {
38
+ profiles, err := loadProfilesFromDir(dir, profilesPaths)
39
if err != nil {
40
log.Errorf("failed to load dd snmp profiles from '%s': %v", dir, err)
41
continue
@@ -65,7 +60,7 @@ func loadProfiles() {
60
}
61
62
if len(ddProfiles) == 0 {
68
- log.Warningf("no dd snmp profiles found in any of the searched directories: %v", extendsPaths)
63
+ log.Warningf("no dd snmp profiles found in any of the searched directories: %v", profilesPaths)
64
} else {
65
log.Infof("loaded %d dd snmp profiles total", len(ddProfiles))
66
}
@@ -82,6 +77,10 @@ func loadProfilesFromDir(dirpath string, extendsPaths multipath.MultiPath) ([]*P
77
if !(strings.HasSuffix(d.Name(), ".yaml") || strings.HasSuffix(d.Name(), ".yml")) {
78
return nil
79
}
80
+ // Skip abstract profiles
81
+ if strings.HasPrefix(d.Name(), "_") {
82
+ return nil
83
+ }
84
85
profile, err := loadProfile(path, extendsPaths)
86
if err != nil {
@@ -150,12 +149,14 @@ func loadProfileWithExtendsMap(filename string, extendsPaths multipath.MultiPath
149
return &prof, nil
150
}
151
153
-func getProfilesDirs() (userDir, stockDir string) {
152
+func getProfilesDirs() multipath.MultiPath {
153
if executable.Name == "test" {
154
dir, _ := filepath.Abs("../../../config/go.d/snmp.profiles/default")
156
- return "", dir
155
+ return multipath.New(dir)
156
}
157
158
+ var userDir, stockDir string
159
+
160
if userDir = handleDirOnWin(os.Getenv("NETDATA_USER_CONFIG_DIR")); userDir != "" {
161
if dir := filepath.Join(userDir, "go.d/snmp.profiles"); isDirExists(dir) {
162
userDir = dir
@@ -168,13 +169,13 @@ func getProfilesDirs() (userDir, stockDir string) {
169
}
170
171
if userDir != "" || stockDir != "" {
171
- return userDir, stockDir
172
+ return multipath.New(userDir, stockDir)
173
}
174
175
// Development: When running from source (netdata/src/go/plugin/go.d/bin)
176
// Looks for profiles in the local git repository
177
if dir := filepath.Join(executable.Directory, "../config/go.d/snmp.profiles/default"); isDirExists(dir) {
177
- return "", dir
178
+ return multipath.New(dir)
179
}
180
181
possibleDirs := []string{
@@ -199,7 +200,7 @@ func getProfilesDirs() (userDir, stockDir string) {
200
}
201
}
202
202
- return userDir, stockDir
203
+ return multipath.New(userDir, stockDir)
204
}
205
206
func isDirExists(dir string) bool {
src/go/plugin/go.d/collector/snmp/ddsnmp/profile_test.go
+7
-1
@@ -15,6 +15,7 @@ import (
15
16
"github.com/netdata/netdata/go/plugins/pkg/multipath"
17
"github.com/netdata/netdata/go/plugins/plugin/go.d/collector/snmp/ddsnmp/ddprofiledefinition"
18
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrix"
19
)
20
21
func Test_loadDDSnmpProfiles(t *testing.T) {
@@ -32,7 +33,12 @@ func Test_loadDDSnmpProfiles(t *testing.T) {
33
names, err := f.Readdirnames(-1)
34
require.NoError(t, err)
35
35
- require.Equal(t, len(names)-1 /*README.md*/, len(profiles))
36
+ var want int64
37
+ for _, name := range names {
38
+ want += metrix.Bool(!strings.HasPrefix(name, "_"))
39
+ }
40
+
41
+ require.Equal(t, want-1 /*README.md*/, int64(len(profiles)))
42
}
43
44
func Test_FindProfiles(t *testing.T) {