Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: avoid redundant logs on failures to export metrics #20519

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading