Skip to content

Commit

Permalink
On post failure, only roll metrics over to next batch if retry is ena…
Browse files Browse the repository at this point in the history
…bled
  • Loading branch information
DarcyRaynerDD committed Jun 17, 2019
1 parent 0f938c4 commit c21a875
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions internal/metrics/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c21a875

Please sign in to comment.