From c21a875e12506716f72074debc41a075a112ef13 Mon Sep 17 00:00:00 2001 From: "darcy.rayner" Date: Mon, 17 Jun 2019 16:20:30 -0400 Subject: [PATCH] On post failure, only roll metrics over to next batch if retry is enabled --- internal/metrics/processor.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/metrics/processor.go b/internal/metrics/processor.go index fcb18e17..6d92c3c7 100644 --- a/internal/metrics/processor.go +++ b/internal/metrics/processor.go @@ -132,14 +132,17 @@ func (p *processor) processMetrics() { func (p *processor) sendMetricsBatch() error { mts := p.batcher.ToAPIMetrics() if len(mts) > 0 { + oldBatcher := p.batcher + p.batcher = MakeBatcher(p.batchInterval) + err := p.client.SendMetrics(mts) if err != nil { + if p.shouldRetryOnFail { + // If we want to retry on error, keep the metrics in the batcher until they are sent correctly. + p.batcher = oldBatcher + } return err } - // All the metrics in the batcher were sent successfully, - // the batcher can now be cleared. If there was an error, - // the metrics will stay in the batcher and be sent in the next cycle. - p.batcher = MakeBatcher(p.batchInterval) } return nil }