move cleanup and reload in ApplyConfig

This commit is contained in:
Krasi Georgiev 2018-01-18 11:49:42 +00:00
parent 719c579f7b
commit 910c22418c

View file

@ -15,6 +15,7 @@ package retrieval
import ( import (
"fmt" "fmt"
"reflect"
"sync" "sync"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
@ -84,6 +85,17 @@ func (m *ScrapeManager) ApplyConfig(cfg *config.Config) error {
c[scfg.JobName] = scfg c[scfg.JobName] = scfg
} }
m.scrapeConfigs = c m.scrapeConfigs = c
// Cleanup and reload pool if config has changed.
for name, sp := range m.scrapePools {
if cfg, ok := m.scrapeConfigs[name]; !ok {
sp.stop()
delete(m.scrapePools, name)
} else if !reflect.DeepEqual(sp.config, cfg) {
sp.reload(cfg)
}
}
return nil return nil
} }
@ -141,12 +153,4 @@ func (m *ScrapeManager) reload(t map[string][]*targetgroup.Group) {
existing.Sync(tgroup) existing.Sync(tgroup)
} }
} }
// Cleanup - check the config and cancel the scrape loops if it don't exist in the scrape config.
for name, sp := range m.scrapePools {
if _, ok := m.scrapeConfigs[name]; !ok {
sp.stop()
delete(m.scrapePools, name)
}
}
} }