From 11dfc817f39b355d869ead98230737c6569270d2 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Thu, 17 Aug 2023 14:53:43 -0700 Subject: [PATCH] do not log client canceled events (#17838) --- internal/logger/target/http/http.go | 6 +++++- internal/logger/target/kafka/kafka.go | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/logger/target/http/http.go b/internal/logger/target/http/http.go index 5eff28142..9644830a5 100644 --- a/internal/logger/target/http/http.go +++ b/internal/logger/target/http/http.go @@ -377,7 +377,11 @@ func (h *Target) Send(ctx context.Context, entry interface{}) error { select { case h.logCh <- entry: case <-ctx.Done(): - return ctx.Err() + // return error only for context timedout. + if errors.Is(ctx.Err(), context.DeadlineExceeded) { + return ctx.Err() + } + return nil default: nWorkers := atomic.LoadInt64(&h.workers) if nWorkers < maxWorkers { diff --git a/internal/logger/target/kafka/kafka.go b/internal/logger/target/kafka/kafka.go index 89cba52f0..8995e8527 100644 --- a/internal/logger/target/kafka/kafka.go +++ b/internal/logger/target/kafka/kafka.go @@ -330,6 +330,12 @@ func (h *Target) Send(ctx context.Context, entry interface{}) error { select { case h.logCh <- entry: + case <-ctx.Done(): + // return error only for context timedout. + if errors.Is(ctx.Err(), context.DeadlineExceeded) { + return ctx.Err() + } + return nil default: // log channel is full, do not wait and return // an error immediately to the caller