brake the start provider func so that can run unit tests against it.

pull/3362/head
Krasi Georgiev 7 years ago
parent c5cb0d2910
commit f5c2c5ff8f

@ -103,12 +103,22 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {
m.cancelDiscoverers() m.cancelDiscoverers()
for _, scfg := range cfg.ScrapeConfigs { for _, scfg := range cfg.ScrapeConfigs {
for provName, prov := range m.providersFromConfig(scfg.ServiceDiscoveryConfig) { 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) ctx, cancel := context.WithCancel(m.ctx)
updates := make(chan []*config.TargetGroup) updates := make(chan []*config.TargetGroup)
m.discoverCancel = append(m.discoverCancel, cancel) m.discoverCancel = append(m.discoverCancel, cancel)
go prov.Run(ctx, updates) go worker.Run(ctx, updates)
go func(provName string) { go func(provName string) {
select { select {
case <-ctx.Done(): case <-ctx.Done():
@ -119,7 +129,7 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {
if !ok { if !ok {
break break
} }
m.syncCh <- m.mergeGroups(scfg.JobName, provName, tgs) m.syncCh <- m.mergeGroups(jobName, provName, tgs)
case <-time.After(5 * time.Second): case <-time.After(5 * time.Second):
// Initial set didn't arrive. Act as if it was empty // Initial set didn't arrive. Act as if it was empty
// and wait for updates later on. // and wait for updates later on.
@ -136,16 +146,10 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {
if !ok { if !ok {
return return
} }
m.syncCh <- m.mergeGroups(scfg.JobName, provName, tgs) m.syncCh <- m.mergeGroups(jobName, provName, tgs)
} }
} }
}(provName) }(provName)
}
}
close(err)
}
return <-err
} }
func (m *Manager) cancelDiscoverers() { func (m *Manager) cancelDiscoverers() {

Loading…
Cancel
Save