Skip to content

Commit

Permalink
Merge pull request #286 from roidelapluie/http2-env
Browse files Browse the repository at this point in the history
Add an environment variable to enable HTTP2
  • Loading branch information
roidelapluie authored Jul 23, 2021
2 parents 5f27aa2 + b5c3589 commit 8d1c9f8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"net"
"net/http"
"net/url"
"os"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8d1c9f8

Please sign in to comment.