Skip to content

Commit

Permalink
Make sure we don't try to count metrics if scraper returns an error (o…
Browse files Browse the repository at this point in the history
  • Loading branch information
fld-opensource authored and Fabien Lebaillif - Delamare committed Apr 8, 2021
1 parent 8cac172 commit cac8f34
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions receiver/scraperhelper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ func (ms metricsScraper) Scrape(ctx context.Context, receiverName string) (pdata
ctx = obsreport.ScraperContext(ctx, receiverName, ms.Name())
ctx = obsreport.StartMetricsScrapeOp(ctx, receiverName, ms.Name())
metrics, err := ms.ScrapeMetrics(ctx)
obsreport.EndMetricsScrapeOp(ctx, metrics.Len(), err)
count := 0
if err == nil {
count = metrics.Len()
}
obsreport.EndMetricsScrapeOp(ctx, count, err)
return metrics, err
}

Expand Down Expand Up @@ -155,7 +159,11 @@ func (rms resourceMetricsScraper) Scrape(ctx context.Context, receiverName strin
ctx = obsreport.ScraperContext(ctx, receiverName, rms.Name())
ctx = obsreport.StartMetricsScrapeOp(ctx, receiverName, rms.Name())
resourceMetrics, err := rms.ScrapeResourceMetrics(ctx)
obsreport.EndMetricsScrapeOp(ctx, metricCount(resourceMetrics), err)
count := 0
if err == nil {
count = metricCount(resourceMetrics)
}
obsreport.EndMetricsScrapeOp(ctx, count, err)
return resourceMetrics, err
}

Expand Down

0 comments on commit cac8f34

Please sign in to comment.