From 26561e71ece6c05bba1fec8a7d0de22130ccce14 Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Tue, 6 Aug 2024 12:01:26 -0400 Subject: [PATCH 1/2] Ship a final batch of logs before shutdown --- pkg/sendbuffer/sendbuffer.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/sendbuffer/sendbuffer.go b/pkg/sendbuffer/sendbuffer.go index 9e44f0b5c..72bda684a 100644 --- a/pkg/sendbuffer/sendbuffer.go +++ b/pkg/sendbuffer/sendbuffer.go @@ -149,6 +149,11 @@ func (sb *SendBuffer) Run(ctx context.Context) error { case <-sb.sendTicker.C: continue case <-ctx.Done(): + // Send one final batch, if possible, so that we can get logs related to shutdowns + time.Sleep(1 * time.Second) + if err := sb.sendAndPurge(); err != nil { + sb.logger.Log("msg", "failed to send final batch of logs on shutdown", "err", err) + } return nil } } From 00f2761602184fdc04c7d7bdf019b281d822a24c Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Tue, 6 Aug 2024 12:48:12 -0400 Subject: [PATCH 2/2] Add comment --- pkg/sendbuffer/sendbuffer.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/sendbuffer/sendbuffer.go b/pkg/sendbuffer/sendbuffer.go index 72bda684a..19db5762a 100644 --- a/pkg/sendbuffer/sendbuffer.go +++ b/pkg/sendbuffer/sendbuffer.go @@ -149,7 +149,8 @@ func (sb *SendBuffer) Run(ctx context.Context) error { case <-sb.sendTicker.C: continue case <-ctx.Done(): - // Send one final batch, if possible, so that we can get logs related to shutdowns + // Send one final batch, if possible, so that we can get logs related to shutdowns. + // Sleep for one second first to allow any shutdown-related logs to be written. time.Sleep(1 * time.Second) if err := sb.sendAndPurge(); err != nil { sb.logger.Log("msg", "failed to send final batch of logs on shutdown", "err", err)