brake the start provider func so that can run unit tests against it.
@@ -103,12 +103,22 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {
m.cancelDiscoverers()
for _, scfg := range cfg.ScrapeConfigs {
for provName, prov := range m.providersFromConfig(scfg.ServiceDiscoveryConfig) {
+ m.startProvider(scfg.JobName, provName, prov)
+ }
+ }
+ close(err)
+ }
+
+ return <-err
+}
+
+func (m *Manager) startProvider(jobName, provName string, worker Discoverer) {
ctx, cancel := context.WithCancel(m.ctx)
updates := make(chan []*config.TargetGroup)
m.discoverCancel = append(m.discoverCancel, cancel)
- go prov.Run(ctx, updates)
+ go worker.Run(ctx, updates)
go func(provName string) {
select {
case <-ctx.Done():
@@ -119,7 +129,7 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {
if !ok {
break
}
- m.syncCh <- m.mergeGroups(scfg.JobName, provName, tgs)
+ m.syncCh <- m.mergeGroups(jobName, provName, tgs)
case <-time.After(5 * time.Second):
// Initial set didn't arrive. Act as if it was empty
// and wait for updates later on.
@@ -136,17 +146,11 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {
if !ok {
return
}
- m.syncCh <- m.mergeGroups(scfg.JobName, provName, tgs)
+ m.syncCh <- m.mergeGroups(jobName, provName, tgs)
}
}
}(provName)
}
- }
- close(err)
- }
-
- return <-err
-}
func (m *Manager) cancelDiscoverers() {
for _, c := range m.discoverCancel {
