diff --git a/collector/service.go b/collector/service.go index 330766bd4..78f63ce32 100644 --- a/collector/service.go +++ b/collector/service.go @@ -166,13 +166,15 @@ func NewService(opts *ServiceOpts) (*Service, error) { remoteClient, err := promremote.NewClient( promremote.ClientOpts{ - Timeout: 30 * time.Second, + Timeout: 10 * time.Second, InsecureSkipVerify: opts.InsecureSkipVerify, Close: false, - MaxIdleConnsPerHost: 2, + MaxIdleConnsPerHost: 1, MaxConnsPerHost: 5, - MaxIdleConns: 2, - ResponseHeaderTimeout: 30 * time.Second, + MaxIdleConns: 1, + ResponseHeaderTimeout: 10 * time.Second, + DisableHTTP2: true, + DisableKeepAlives: true, }) if err != nil { return nil, fmt.Errorf("failed to create prometheus remote client: %w", err) diff --git a/pkg/promremote/client.go b/pkg/promremote/client.go index 68659dbc8..04c799183 100644 --- a/pkg/promremote/client.go +++ b/pkg/promremote/client.go @@ -3,6 +3,7 @@ package promremote import ( "bytes" "context" + "crypto/tls" "fmt" "io" "net/http" @@ -48,6 +49,12 @@ type ClientOpts struct { // TLSHandshakeTimeout specifies the maximum amount of time to // wait for a TLS handshake. Zero means no timeout. TLSHandshakeTimeout time.Duration + + // DisableHTTP2 controls whether the client disables HTTP/2 support. + DisableHTTP2 bool + + // DisableKeepAlives controls whether the client disables HTTP keep-alives. + DisableKeepAlives bool } func (c ClientOpts) WithDefaults() ClientOpts { @@ -90,6 +97,14 @@ func NewClient(opts ClientOpts) (*Client, error) { t.IdleConnTimeout = opts.IdleConnTimeout t.TLSClientConfig.InsecureSkipVerify = opts.InsecureSkipVerify t.TLSHandshakeTimeout = opts.TLSHandshakeTimeout + t.DisableKeepAlives = opts.DisableKeepAlives + + if opts.DisableHTTP2 { + t.ForceAttemptHTTP2 = false + t.TLSNextProto = make(map[string]func(authority string, c *tls.Conn) http.RoundTripper) + t.TLSClientConfig = &tls.Config{} + t.TLSClientConfig.NextProtos = []string{"http/1.1"} + } httpClient := &http.Client{ Timeout: opts.Timeout,