From b5c358997cbf126e8f8518cdc024c32da3996d48 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 22 Jul 2021 14:43:37 +0200 Subject: [PATCH] Enable HTTP 2 via env variable Signed-off-by: Julien Pivotto --- config/http_config.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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