Skip to content

Commit

Permalink
[chore][receiver/splunkenterprise] added ctx to error handling (#32670)
Browse files Browse the repository at this point in the history
Modified error watching/aggregation goroutine to check
for `context.Done()` to improve shutdown performance.
  • Loading branch information
shalper2 authored Apr 26, 2024
1 parent dafb594 commit baeed80
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions receiver/splunkenterprisereceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,22 @@ func (s *splunkScraper) start(ctx context.Context, h component.Host) (err error)
// listens to the error channel and combines errors sent from different metric scrape functions,
// returning the combined error list should context timeout or a nil error value is sent in the
// channel signifying the end of a scrape cycle
func errorListener(eQueue <-chan error, eOut chan<- *scrapererror.ScrapeErrors) {
func errorListener(ctx context.Context, eQueue <-chan error, eOut chan<- *scrapererror.ScrapeErrors) {
errs := &scrapererror.ScrapeErrors{}

for err := range eQueue {
errs.Add(err)
for {
select {
case <-ctx.Done():
eOut <- errs
return
case err, ok := <-eQueue:
if !ok {
eOut <- errs
return
}
errs.Add(err)
}
}
eOut <- errs
}

// The big one: Describes how all scraping tasks should be performed. Part of the scraper interface
Expand Down Expand Up @@ -96,7 +105,7 @@ func (s *splunkScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
errChan := make(chan error, len(metricScrapes))

go func() {
errorListener(errChan, errOut)
errorListener(ctx, errChan, errOut)
}()

for _, fn := range metricScrapes {
Expand Down

0 comments on commit baeed80

Please sign in to comment.