fix discovered config default values (#17115)
Ilya Mashchenko committed
Mar 6, 2024 at 10:55 UTC
65f9cc2195ff1612eded4c8b57a78625acff8b55
4 files changed
+34
-19
src/go/collectors/go.d.plugin/agent/discovery/manager.go
+1
@@ -101,6 +101,7 @@ func (m *Manager) registerDiscoverers(cfg Config) error {
101
}
102
103
if len(cfg.SD.ConfDir) != 0 {
104
+ cfg.SD.ConfigDefaults = cfg.Registry
105
d, err := sd.NewServiceDiscovery(cfg.SD)
106
if err != nil {
107
return err
src/go/collectors/go.d.plugin/agent/discovery/sd/pipeline/config.go
+4
-1
@@ -6,12 +6,15 @@ import (
6
"errors"
7
"fmt"
8
9
+ "github.com/netdata/netdata/go/go.d.plugin/agent/confgroup"
10
"github.com/netdata/netdata/go/go.d.plugin/agent/discovery/sd/discoverer/kubernetes"
11
"github.com/netdata/netdata/go/go.d.plugin/agent/discovery/sd/discoverer/netlisteners"
12
)
13
14
type Config struct {
14
- Source string `yaml:"-"`
15
+ Source string `yaml:"-"`
16
+ ConfigDefaults confgroup.Registry `yaml:"-"`
17
+
18
Name string `yaml:"name"`
19
Discover []DiscoveryConfig `yaml:"discover"`
20
Classify []ClassifyRuleConfig `yaml:"classify"`
src/go/collectors/go.d.plugin/agent/discovery/sd/pipeline/pipeline.go
+16
-13
@@ -9,10 +9,9 @@ import (
9
"log/slog"
10
"time"
11
12
+ "github.com/netdata/netdata/go/go.d.plugin/agent/confgroup"
13
"github.com/netdata/netdata/go/go.d.plugin/agent/discovery/sd/discoverer/kubernetes"
14
"github.com/netdata/netdata/go/go.d.plugin/agent/discovery/sd/discoverer/netlisteners"
14
-
15
- "github.com/netdata/netdata/go/go.d.plugin/agent/confgroup"
15
"github.com/netdata/netdata/go/go.d.plugin/agent/discovery/sd/model"
16
"github.com/netdata/netdata/go/go.d.plugin/logger"
17
)
@@ -37,11 +36,12 @@ func New(cfg Config) (*Pipeline, error) {
36
slog.String("component", "service discovery"),
37
slog.String("pipeline", cfg.Name),
38
),
40
- clr: clr,
41
- cmr: cmr,
42
- accum: newAccumulator(),
43
- discoverers: make([]model.Discoverer, 0),
44
- configs: make(map[string]map[uint64][]confgroup.Config),
39
+ configDefaults: cfg.ConfigDefaults,
40
+ clr: clr,
41
+ cmr: cmr,
42
+ accum: newAccumulator(),
43
+ discoverers: make([]model.Discoverer, 0),
44
+ configs: make(map[string]map[uint64][]confgroup.Config),
45
}
46
p.accum.Logger = p.Logger
47
@@ -56,11 +56,12 @@ type (
56
Pipeline struct {
57
*logger.Logger
58
59
- discoverers []model.Discoverer
60
- accum *accumulator
61
- clr classificator
62
- cmr composer
63
- configs map[string]map[uint64][]confgroup.Config // [targetSource][targetHash]
59
+ configDefaults confgroup.Registry
60
+ discoverers []model.Discoverer
61
+ accum *accumulator
62
+ clr classificator
63
+ cmr composer
64
+ configs map[string]map[uint64][]confgroup.Config // [targetSource][targetHash]
65
}
66
classificator interface {
67
classify(model.Target) model.Tags
@@ -186,10 +187,12 @@ func (p *Pipeline) processGroup(tgg model.TargetGroup) *confgroup.Group {
187
changed = true
188
189
for _, cfg := range cfgs {
189
- // TODO: set
190
cfg.SetProvider(tgg.Provider())
191
cfg.SetSource(tgg.Source())
192
cfg.SetSourceType(confgroup.TypeDiscovered)
193
+ if def, ok := p.configDefaults.Lookup(cfg.Module()); ok {
194
+ cfg.ApplyDefaults(def)
195
+ }
196
}
197
}
198
}
src/go/collectors/go.d.plugin/agent/discovery/sd/sd.go
+13
-5
@@ -17,7 +17,8 @@ import (
17
)
18
19
type Config struct {
20
- ConfDir multipath.MultiPath
20
+ ConfigDefaults confgroup.Registry
21
+ ConfDir multipath.MultiPath
22
}
23
24
func NewServiceDiscovery(cfg Config) (*ServiceDiscovery, error) {
@@ -26,8 +27,9 @@ func NewServiceDiscovery(cfg Config) (*ServiceDiscovery, error) {
27
)
28
29
d := &ServiceDiscovery{
29
- Logger: log,
30
- confProv: newConfFileReader(log, cfg.ConfDir),
30
+ Logger: log,
31
+ confProv: newConfFileReader(log, cfg.ConfDir),
32
+ configDefaults: cfg.ConfigDefaults,
33
newPipeline: func(config pipeline.Config) (sdPipeline, error) {
34
return pipeline.New(config)
35
},
@@ -43,8 +45,9 @@ type (
45
46
confProv confFileProvider
47
46
- newPipeline func(config pipeline.Config) (sdPipeline, error)
47
- pipelines map[string]func()
48
+ configDefaults confgroup.Registry
49
+ newPipeline func(config pipeline.Config) (sdPipeline, error)
50
+ pipelines map[string]func()
51
}
52
sdPipeline interface {
53
Run(ctx context.Context, in chan<- []*confgroup.Group)
@@ -55,6 +58,10 @@ type (
58
}
59
)
60
61
+func (d *ServiceDiscovery) String() string {
62
+ return "service discovery"
63
+}
64
+
65
func (d *ServiceDiscovery) Run(ctx context.Context, in chan<- []*confgroup.Group) {
66
d.Info("instance is started")
67
defer func() { d.cleanup(); d.Info("instance is stopped") }()
@@ -106,6 +113,7 @@ func (d *ServiceDiscovery) addPipeline(ctx context.Context, conf confFile, in ch
113
}
114
115
cfg.Source = fmt.Sprintf("file=%s", conf.source)
116
+ cfg.ConfigDefaults = d.configDefaults
117
118
pl, err := d.newPipeline(cfg)
119
if err != nil {