Skip to content

Commit

Permalink
Fix: avoid redundant logs on failures to export metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jjti committed Feb 7, 2024
1 parent 1bd2530 commit 47c5c8b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion agent/auto-config/auto_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ func startedAutoConfig(t *testing.T, autoEncrypt bool) testAutoConfig {
originalToken: originalToken,
initialRoots: indexedRoots,
initialCert: cert,
extraCerts: extraCerts,
extraCerts: exrts,
stop: cancel,
}
}
Expand Down
7 changes: 4 additions & 3 deletions agent/hcp/client/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions agent/hcp/client/http_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

"github.com/hashicorp/consul/agent/hcp/config"
"github.com/hashicorp/go-hclog"
"github.com/stretchr/testify/require"
)

Expand All @@ -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
Expand Down
5 changes: 1 addition & 4 deletions agent/hcp/telemetry_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 47c5c8b

Please sign in to comment.