* scrape: rename ctx name for readability

Signed-off-by: johncming <johncming@yahoo.com>

* scrape: use self ctx instead of parent ctx.

Signed-off-by: johncming <johncming@yahoo.com>
This commit is contained in:
johncming 2019-08-28 21:55:09 +08:00 committed by Ganesh Vernekar
parent 50d453b3c3
commit 1fa5a75a3a

View file

@ -601,8 +601,8 @@ type scrapeLoop struct {
sampleMutator labelsMutator sampleMutator labelsMutator
reportSampleMutator labelsMutator reportSampleMutator labelsMutator
parentCtx context.Context
ctx context.Context ctx context.Context
scrapeCtx context.Context
cancel func() cancel func()
stopped chan struct{} stopped chan struct{}
} }
@ -857,10 +857,10 @@ func newScrapeLoop(ctx context.Context,
stopped: make(chan struct{}), stopped: make(chan struct{}),
jitterSeed: jitterSeed, jitterSeed: jitterSeed,
l: l, l: l,
ctx: ctx, parentCtx: ctx,
honorTimestamps: honorTimestamps, honorTimestamps: honorTimestamps,
} }
sl.scrapeCtx, sl.cancel = context.WithCancel(ctx) sl.ctx, sl.cancel = context.WithCancel(ctx)
return sl return sl
} }
@ -869,7 +869,7 @@ func (sl *scrapeLoop) run(interval, timeout time.Duration, errc chan<- error) {
select { select {
case <-time.After(sl.scraper.offset(interval, sl.jitterSeed)): case <-time.After(sl.scraper.offset(interval, sl.jitterSeed)):
// Continue after a scraping offset. // Continue after a scraping offset.
case <-sl.scrapeCtx.Done(): case <-sl.ctx.Done():
close(sl.stopped) close(sl.stopped)
return return
} }
@ -882,10 +882,10 @@ func (sl *scrapeLoop) run(interval, timeout time.Duration, errc chan<- error) {
mainLoop: mainLoop:
for { for {
select { select {
case <-sl.ctx.Done(): case <-sl.parentCtx.Done():
close(sl.stopped) close(sl.stopped)
return return
case <-sl.scrapeCtx.Done(): case <-sl.ctx.Done():
break mainLoop break mainLoop
default: default:
} }
@ -947,10 +947,10 @@ mainLoop:
last = start last = start
select { select {
case <-sl.ctx.Done(): case <-sl.parentCtx.Done():
close(sl.stopped) close(sl.stopped)
return return
case <-sl.scrapeCtx.Done(): case <-sl.ctx.Done():
break mainLoop break mainLoop
case <-ticker.C: case <-ticker.C:
} }
@ -977,7 +977,7 @@ func (sl *scrapeLoop) endOfRunStaleness(last time.Time, ticker *time.Ticker, int
// Wait for when the next scrape would have been, record its timestamp. // Wait for when the next scrape would have been, record its timestamp.
var staleTime time.Time var staleTime time.Time
select { select {
case <-sl.ctx.Done(): case <-sl.parentCtx.Done():
return return
case <-ticker.C: case <-ticker.C:
staleTime = time.Now() staleTime = time.Now()
@ -986,14 +986,14 @@ func (sl *scrapeLoop) endOfRunStaleness(last time.Time, ticker *time.Ticker, int
// Wait for when the next scrape would have been, if the target was recreated // Wait for when the next scrape would have been, if the target was recreated
// samples should have been ingested by now. // samples should have been ingested by now.
select { select {
case <-sl.ctx.Done(): case <-sl.parentCtx.Done():
return return
case <-ticker.C: case <-ticker.C:
} }
// Wait for an extra 10% of the interval, just to be safe. // Wait for an extra 10% of the interval, just to be safe.
select { select {
case <-sl.ctx.Done(): case <-sl.parentCtx.Done():
return return
case <-time.After(interval / 10): case <-time.After(interval / 10):
} }