From 0d85bbc3131ce8be23c57e30b213ba6056623976 Mon Sep 17 00:00:00 2001 From: Sophie Gairo <97480023+sophie-gairo@users.noreply.github.com> Date: Tue, 24 Oct 2023 18:10:43 -0500 Subject: [PATCH] NET-6204- Repeating error log in consul-connect-injector (#3128) * better handle gateway timeout errors * strings not refs * changelog * Add missing import, fix import blocking --------- Co-authored-by: Nathan Coleman --- .changelog/3128.txt | 3 +++ control-plane/api-gateway/cache/gateway.go | 14 +++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .changelog/3128.txt diff --git a/.changelog/3128.txt b/.changelog/3128.txt new file mode 100644 index 0000000000..0e7d321518 --- /dev/null +++ b/.changelog/3128.txt @@ -0,0 +1,3 @@ +```release-note:bug +control-plane: only alert on valid errors, not timeouts in gateway +``` diff --git a/control-plane/api-gateway/cache/gateway.go b/control-plane/api-gateway/cache/gateway.go index 0d79542eec..c6d2c31099 100644 --- a/control-plane/api-gateway/cache/gateway.go +++ b/control-plane/api-gateway/cache/gateway.go @@ -6,14 +6,16 @@ package cache import ( "context" "fmt" + "strings" "sync" "github.com/cenkalti/backoff" "github.com/go-logr/logr" - "github.com/hashicorp/consul-k8s/control-plane/api-gateway/common" - "github.com/hashicorp/consul-k8s/control-plane/consul" "github.com/hashicorp/consul/api" "k8s.io/apimachinery/pkg/types" + + "github.com/hashicorp/consul-k8s/control-plane/api-gateway/common" + "github.com/hashicorp/consul-k8s/control-plane/consul" ) type GatewayCache struct { @@ -125,7 +127,13 @@ func (r *GatewayCache) subscribeToGateway(ctx context.Context, ref api.ResourceR return nil }, backoff.WithContext(retryBackoff, ctx)); err != nil { - r.logger.Error(err, fmt.Sprintf("unable to fetch config entry for gateway: %s/%s", ref.Namespace, ref.Name)) + // if we timeout we don't care about the error message because it's expected to happen on long polls + // any other error we want to alert on + if !strings.Contains(strings.ToLower(err.Error()), "timeout") && + !strings.Contains(strings.ToLower(err.Error()), "no such host") && + !strings.Contains(strings.ToLower(err.Error()), "connection refused") { + r.logger.Error(err, fmt.Sprintf("unable to fetch config entry for gateway: %s/%s", ref.Namespace, ref.Name)) + } continue }