From b4f8ac11fe9ff678ed3e26b4753870c7bcd27288 Mon Sep 17 00:00:00 2001 From: Sam Calder-Mason Date: Fri, 13 Sep 2024 13:52:02 +1000 Subject: [PATCH] perf: Improve retry mechanism by calculating duration --- pkg/output/xatu/exporter.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/output/xatu/exporter.go b/pkg/output/xatu/exporter.go index f48cc64f..5aac573c 100644 --- a/pkg/output/xatu/exporter.go +++ b/pkg/output/xatu/exporter.go @@ -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)),