diff --git a/config/http_config.go b/config/http_config.go index 80502585..6c0c033d 100644 --- a/config/http_config.go +++ b/config/http_config.go @@ -27,6 +27,7 @@ import ( "net" "net/http" "net/url" + "os" "strings" "sync" "time" @@ -379,18 +380,23 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HT ExpectContinueTimeout: 1 * time.Second, DialContext: dialContext, } - if opts.http2Enabled { + if opts.http2Enabled || os.Getenv("PROMETHEUS_COMMON_ENABLE_HTTP2") != "" { // HTTP/2 support is golang has many problematic cornercases where // dead connections would be kept and used in connection pools. // https://github.com/golang/go/issues/32388 // https://github.com/golang/go/issues/39337 // https://github.com/golang/go/issues/39750 - // TODO: Re-Enable HTTP/2 once upstream issue is fixed. - // TODO: use ForceAttemptHTTP2 when we move to Go 1.13+. - err := http2.ConfigureTransport(rt.(*http.Transport)) + + // Enable HTTP2 if the environment variable + // PROMETHEUS_COMMON_ENABLE_HTTP2 is set. + // This is a temporary workaround so that users can safely test this + // and validate that HTTP2 can be enabled Prometheus-Wide again. + + http2t, err := http2.ConfigureTransports(rt.(*http.Transport)) if err != nil { return nil, err } + http2t.ReadIdleTimeout = time.Minute } // If a authorization_credentials is provided, create a round tripper that will set the