From 47c5c8b7a1c9bbcbbb8aa367f99f0c2a6980c4d3 Mon Sep 17 00:00:00 2001 From: Joshua Timmons Date: Wed, 7 Feb 2024 14:26:30 -0500 Subject: [PATCH 1/2] Fix: avoid redundant logs on failures to export metrics --- agent/auto-config/auto_config_test.go | 2 +- agent/hcp/client/http_client.go | 7 ++++--- agent/hcp/client/http_client_test.go | 3 +-- agent/hcp/telemetry_provider.go | 5 +---- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/agent/auto-config/auto_config_test.go b/agent/auto-config/auto_config_test.go index 7c5c629be2f7..7719fca53c17 100644 --- a/agent/auto-config/auto_config_test.go +++ b/agent/auto-config/auto_config_test.go @@ -850,7 +850,7 @@ func startedAutoConfig(t *testing.T, autoEncrypt bool) testAutoConfig { originalToken: originalToken, initialRoots: indexedRoots, initialCert: cert, - extraCerts: extraCerts, + extraCerts: exrts, stop: cancel, } } diff --git a/agent/hcp/client/http_client.go b/agent/hcp/client/http_client.go index 6692ed586a06..4854f8c022cd 100644 --- a/agent/hcp/client/http_client.go +++ b/agent/hcp/client/http_client.go @@ -28,7 +28,7 @@ const ( ) // NewHTTPClient configures the retryable HTTP client. -func NewHTTPClient(tlsCfg *tls.Config, source oauth2.TokenSource, logger hclog.Logger) *retryablehttp.Client { +func NewHTTPClient(tlsCfg *tls.Config, source oauth2.TokenSource) *retryablehttp.Client { tlsTransport := cleanhttp.DefaultPooledTransport() tlsTransport.TLSClientConfig = tlsCfg @@ -43,8 +43,9 @@ func NewHTTPClient(tlsCfg *tls.Config, source oauth2.TokenSource, logger hclog.L } retryClient := &retryablehttp.Client{ - HTTPClient: client, - Logger: logger, + HTTPClient: client, + // We already log failed requests elsewhere, we pass a null logger here to avoid redundant logs. + Logger: hclog.NewNullLogger(), RetryWaitMin: defaultRetryWaitMin, RetryWaitMax: defaultRetryWaitMax, RetryMax: defaultRetryMax, diff --git a/agent/hcp/client/http_client_test.go b/agent/hcp/client/http_client_test.go index b30329d0b1b4..b8971040892a 100644 --- a/agent/hcp/client/http_client_test.go +++ b/agent/hcp/client/http_client_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/hashicorp/consul/agent/hcp/config" - "github.com/hashicorp/go-hclog" "github.com/stretchr/testify/require" ) @@ -18,7 +17,7 @@ func TestNewHTTPClient(t *testing.T) { mockHCPCfg, err := mockCfg.HCPConfig() require.NoError(t, err) - client := NewHTTPClient(mockHCPCfg.APITLSConfig(), mockHCPCfg, hclog.NewNullLogger()) + client := NewHTTPClient(mockHCPCfg.APITLSConfig(), mockHCPCfg) require.NotNil(t, client) var req *http.Request diff --git a/agent/hcp/telemetry_provider.go b/agent/hcp/telemetry_provider.go index 1ae8682df8c5..a575d63f8a82 100644 --- a/agent/hcp/telemetry_provider.go +++ b/agent/hcp/telemetry_provider.go @@ -300,10 +300,7 @@ func (h *hcpProviderImpl) updateHTTPConfig(cfg config.CloudConfigurer) error { if err != nil { return fmt.Errorf("failed to configure telemetry HTTP client: %v", err) } - h.httpCfg.client = client.NewHTTPClient( - hcpCfg.APITLSConfig(), - hcpCfg, - h.logger.Named("hcp_telemetry_client")) + h.httpCfg.client = client.NewHTTPClient(hcpCfg.APITLSConfig(), hcpCfg) return nil } From 291bbf3cec4ce45b3b8185b3b1e97e9f7307a706 Mon Sep 17 00:00:00 2001 From: Joshua Timmons Date: Wed, 7 Feb 2024 14:32:02 -0500 Subject: [PATCH 2/2] Merge main --- agent/auto-config/auto_config_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/auto-config/auto_config_test.go b/agent/auto-config/auto_config_test.go index 7719fca53c17..7c5c629be2f7 100644 --- a/agent/auto-config/auto_config_test.go +++ b/agent/auto-config/auto_config_test.go @@ -850,7 +850,7 @@ func startedAutoConfig(t *testing.T, autoEncrypt bool) testAutoConfig { originalToken: originalToken, initialRoots: indexedRoots, initialCert: cert, - extraCerts: exrts, + extraCerts: extraCerts, stop: cancel, } }