add a cancel func to the scrape pool as it is needed in the scrape loop select block
This commit is contained in:
parent
80182a5d82
commit
60ef2016d5
|
@ -126,6 +126,7 @@ type scrapePool struct {
|
||||||
targets map[uint64]*Target
|
targets map[uint64]*Target
|
||||||
droppedTargets []*Target
|
droppedTargets []*Target
|
||||||
loops map[uint64]loop
|
loops map[uint64]loop
|
||||||
|
cancel context.CancelFunc
|
||||||
|
|
||||||
// Constructor for new scrape loops. This is settable for testing convenience.
|
// Constructor for new scrape loops. This is settable for testing convenience.
|
||||||
newLoop func(*Target, scraper) loop
|
newLoop func(*Target, scraper) loop
|
||||||
|
@ -148,7 +149,9 @@ func newScrapePool(cfg *config.ScrapeConfig, app Appendable, logger log.Logger)
|
||||||
|
|
||||||
buffers := pool.NewBytesPool(163, 100e6, 3)
|
buffers := pool.NewBytesPool(163, 100e6, 3)
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
sp := &scrapePool{
|
sp := &scrapePool{
|
||||||
|
cancel: cancel,
|
||||||
appendable: app,
|
appendable: app,
|
||||||
config: cfg,
|
config: cfg,
|
||||||
client: client,
|
client: client,
|
||||||
|
@ -158,7 +161,7 @@ func newScrapePool(cfg *config.ScrapeConfig, app Appendable, logger log.Logger)
|
||||||
}
|
}
|
||||||
sp.newLoop = func(t *Target, s scraper) loop {
|
sp.newLoop = func(t *Target, s scraper) loop {
|
||||||
return newScrapeLoop(
|
return newScrapeLoop(
|
||||||
context.Background(),
|
ctx,
|
||||||
s,
|
s,
|
||||||
log.With(logger, "target", t),
|
log.With(logger, "target", t),
|
||||||
buffers,
|
buffers,
|
||||||
|
@ -173,6 +176,7 @@ func newScrapePool(cfg *config.ScrapeConfig, app Appendable, logger log.Logger)
|
||||||
|
|
||||||
// stop terminates all scrape loops and returns after they all terminated.
|
// stop terminates all scrape loops and returns after they all terminated.
|
||||||
func (sp *scrapePool) stop() {
|
func (sp *scrapePool) stop() {
|
||||||
|
sp.cancel()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
sp.mtx.Lock()
|
sp.mtx.Lock()
|
||||||
|
|
|
@ -75,6 +75,7 @@ func TestScrapePoolStop(t *testing.T) {
|
||||||
sp := &scrapePool{
|
sp := &scrapePool{
|
||||||
targets: map[uint64]*Target{},
|
targets: map[uint64]*Target{},
|
||||||
loops: map[uint64]loop{},
|
loops: map[uint64]loop{},
|
||||||
|
cancel: func() {},
|
||||||
}
|
}
|
||||||
var mtx sync.Mutex
|
var mtx sync.Mutex
|
||||||
stopped := map[uint64]bool{}
|
stopped := map[uint64]bool{}
|
||||||
|
|
Loading…
Reference in New Issue