chore(go.d/ddsnmp): lazy ddsnmp profile loading (#20427)
Ilya Mashchenko committed
Jun 5, 2025 at 21:57 UTC
75029c074d85990d4fe4ba5bb6a2dc63afcabb33
1 file changed
+22
-16
src/go/plugin/go.d/collector/snmp/ddsnmp/profile.go
+22
-16
@@ -8,6 +8,7 @@ import (
8
"os"
9
"path/filepath"
10
"strings"
11
+ "sync"
12
13
"gopkg.in/yaml.v2"
14
@@ -19,29 +20,34 @@ import (
20
21
var log = logger.New().With("component", "snmp/ddsnmp")
22
22
-var ddProfiles []*Profile
23
+var (
24
+ ddProfiles []*Profile
25
+ loadOnce sync.Once
26
+)
27
24
-func init() {
25
- dir := getProfilesDir()
28
+func load() {
29
+ loadOnce.Do(func() {
30
+ dir := getProfilesDir()
31
27
- profiles, err := loadProfiles(dir)
28
- if err != nil {
29
- log.Errorf("failed to loadProfiles dd snmp profiles: %v", err)
30
- return
31
- }
32
-
33
- if len(profiles) == 0 {
34
- log.Warningf("no dd snmp profiles found in '%s'", dir)
35
- return
36
- }
32
+ profiles, err := loadProfiles(dir)
33
+ if err != nil {
34
+ log.Errorf("failed to loadProfiles dd snmp profiles: %v", err)
35
+ return
36
+ }
37
38
- log.Infof("found %d profiles in '%s'", len(profiles), dir)
39
- ddProfiles = profiles
38
+ if len(profiles) == 0 {
39
+ log.Warningf("no dd snmp profiles found in '%s'", dir)
40
+ return
41
+ }
42
41
- return
43
+ log.Infof("found %d profiles in '%s'", len(profiles), dir)
44
+ ddProfiles = profiles
45
+ })
46
}
47
48
func FindProfiles(sysObjId string) []*Profile {
49
+ load()
50
+
51
var profiles []*Profile
52
53
for _, prof := range ddProfiles {