Skip to content

Commit

Permalink
perf: Improve retry mechanism by calculating duration
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Sep 13, 2024
1 parent ddd737d commit b4f8ac1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/output/xatu/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,21 @@ func (e *ItemExporter) sendUpstream(ctx context.Context, items []*pb.DecoratedEv
grpc.UseCompressor(gzip.Name),
}

startTime := time.Now()

if e.config.Retry.Enabled {
opts = append(opts,
retry.WithOnRetryCallback(func(ctx context.Context, attempt uint, err error) {
duration := time.Since(startTime)

logCtx.
WithField("attempt", attempt).
WithError(err).
WithField("duration", duration).
Warn("Failed to export events. Retrying...")

// Reset the startTime to the current time
startTime = time.Now()
}),
retry.WithMax(uint(e.config.Retry.MaxAttempts)),
retry.WithBackoff(retry.BackoffExponential(e.config.Retry.Scalar)),
Expand Down

0 comments on commit b4f8ac1

Please sign in to comment.