Skip to content

Commit

Permalink
Make HTTP2 user visible
Browse files Browse the repository at this point in the history
We still get reports from users that have issues with HTTP2. Let's make
it explicitly possible to disable it.

Because we previously introduced FollowRedirects, most lib users already
use our defaults.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
  • Loading branch information
roidelapluie committed Mar 16, 2022
1 parent 0762b59 commit 252ff6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions config/http_config.go
Expand Up @@ -28,7 +28,6 @@ import (
"net"
"net/http"
"net/url"
"os"
"strings"
"sync"
"time"
Expand All @@ -43,6 +42,7 @@ import (
// DefaultHTTPClientConfig is the default HTTP client configuration.
var DefaultHTTPClientConfig = HTTPClientConfig{
FollowRedirects: true,
EnableHTTP2: true,
}

// defaultHTTPClientOptions holds the default HTTP client options.
Expand Down Expand Up @@ -198,6 +198,10 @@ type HTTPClientConfig struct {
// The omitempty flag is not set, because it would be hidden from the
// marshalled configuration when set to false.
FollowRedirects bool `yaml:"follow_redirects" json:"follow_redirects"`
// EnableHTTP2 specifies whether the client should configure HTTP2.
// The omitempty flag is not set, because it would be hidden from the
// marshalled configuration when set to false.
EnableHTTP2 bool `yaml:"enable_http2" json:"enable_http2"`
}

// SetDirectory joins any relative file paths with dir.
Expand Down Expand Up @@ -401,7 +405,7 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string, optFuncs ...HT
ExpectContinueTimeout: 1 * time.Second,
DialContext: dialContext,
}
if opts.http2Enabled && os.Getenv("PROMETHEUS_COMMON_DISABLE_HTTP2") == "" {
if opts.http2Enabled && cfg.EnableHTTP2 {
// HTTP/2 support is golang had many problematic cornercases where
// dead connections would be kept and used in connection pools.
// https://github.com/golang/go/issues/32388
Expand Down
1 change: 1 addition & 0 deletions config/testdata/http.conf.good.yml
Expand Up @@ -2,3 +2,4 @@ basic_auth:
username: username
password: "mysecret"
proxy_url: "http://remote.host"
enable_http2: true

0 comments on commit 252ff6f

Please sign in to comment.