From 94af4f5181d2ad3af0d62cbdc684a2787df1cd7b Mon Sep 17 00:00:00 2001 From: David Grove Date: Tue, 6 Jun 2023 12:15:28 -0400 Subject: [PATCH] don't log errors from within backoff loop (#391) Signed-off-by: David Grove --- core/internal/runtime/http_client.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/internal/runtime/http_client.go b/core/internal/runtime/http_client.go index b842ddf2..d8724bb2 100644 --- a/core/internal/runtime/http_client.go +++ b/core/internal/runtime/http_client.go @@ -114,7 +114,7 @@ func invoke(ctx context.Context, method string, msg map[string]string, metricLab var res *http.Response start := time.Now() res, err = client.Do(req) - elapsed := time.Now().Sub(start) + elapsed := time.Since(start) if metricLabel != "" { userCodeDurationHistogram.WithLabelValues(metricLabel).Observe(elapsed.Seconds()) } @@ -130,7 +130,6 @@ func invoke(ctx context.Context, method string, msg map[string]string, metricLab reply = &Reply{StatusCode: http.StatusRequestTimeout, Payload: err.Error(), ContentType: "text/plain"} return nil } - logger.Warning("failed to invoke %s: %v", msg["path"], err) if err == ctx.Err() { return backoff.Permanent(err) } @@ -142,7 +141,6 @@ func invoke(ctx context.Context, method string, msg map[string]string, metricLab reply = &Reply{StatusCode: http.StatusRequestTimeout, Payload: err.Error(), ContentType: "text/plain"} return nil } - logger.Warning("failed to invoke %s: %v", msg["path"], err) if err == ctx.Err() { return backoff.Permanent(err) } @@ -159,6 +157,9 @@ func invoke(ctx context.Context, method string, msg map[string]string, metricLab if ctx.Err() != nil { CloseIdleConnections() // don't keep connection alive once ctx is cancelled } + if err != nil && err != ctx.Err() { + logger.Warning("failed to invoke %s: %v", msg["path"], err) + } return reply, err }