-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor DefaultTransport() from objstore to package exthttp #5447
Changes from 3 commits
ab05957
5e6cb84
55a6464
b98372c
9765391
55fd8bc
7f5d8be
b81eeac
141f32e
8b9377f
df1c015
324a272
22169f7
cd81174
79460cb
8789947
7e949eb
195925f
be8f345
d66d816
04cb13f
a95172b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,28 @@ import ( | |
"net" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/prometheus/common/model" | ||
"github.com/thanos-io/thanos/pkg/objstore" | ||
) | ||
|
||
type HTTPConfig struct { | ||
IdleConnTimeout model.Duration `yaml:"idle_conn_timeout"` | ||
ResponseHeaderTimeout model.Duration `yaml:"response_header_timeout"` | ||
InsecureSkipVerify bool `yaml:"insecure_skip_verify"` | ||
|
||
TLSHandshakeTimeout model.Duration `yaml:"tls_handshake_timeout"` | ||
ExpectContinueTimeout model.Duration `yaml:"expect_continue_timeout"` | ||
MaxIdleConns int `yaml:"max_idle_conns"` | ||
MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"` | ||
MaxConnsPerHost int `yaml:"max_conns_per_host"` | ||
|
||
// Allow upstream callers to inject a round tripper | ||
Transport http.RoundTripper `yaml:"-"` | ||
|
||
TLSConfig objstore.TLSConfig `yaml:"tls_config"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we port this TLSConfig type to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to move TLSConfig struct from objstore to exthttp, but turns out there are functions depending on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in tlsconfig.go |
||
} | ||
|
||
// NewTransport creates a new http.Transport with default settings. | ||
func NewTransport() *http.Transport { | ||
return &http.Transport{ | ||
|
@@ -25,3 +45,45 @@ func NewTransport() *http.Transport { | |
ExpectContinueTimeout: 1 * time.Second, | ||
} | ||
} | ||
|
||
// DefaultTransport - this default transport is based on the Minio | ||
// DefaultTransport up until the following commit: | ||
// https://github.com/minio/minio-go/commit/008c7aa71fc17e11bf980c209a4f8c4d687fc884 | ||
// The values have since diverged. | ||
func DefaultTransport(config HTTPConfig) (*http.Transport, error) { | ||
bwplotka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tlsConfig, err := objstore.NewTLSConfig(&config.TLSConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if config.InsecureSkipVerify { | ||
tlsConfig.InsecureSkipVerify = true | ||
} | ||
SrushtiSapkale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return &http.Transport{ | ||
Proxy: http.ProxyFromEnvironment, | ||
DialContext: (&net.Dialer{ | ||
Timeout: 30 * time.Second, | ||
KeepAlive: 30 * time.Second, | ||
DualStack: true, | ||
}).DialContext, | ||
|
||
MaxIdleConns: config.MaxIdleConns, | ||
MaxIdleConnsPerHost: config.MaxIdleConnsPerHost, | ||
IdleConnTimeout: time.Duration(config.IdleConnTimeout), | ||
MaxConnsPerHost: config.MaxConnsPerHost, | ||
TLSHandshakeTimeout: time.Duration(config.TLSHandshakeTimeout), | ||
ExpectContinueTimeout: time.Duration(config.ExpectContinueTimeout), | ||
// A custom ResponseHeaderTimeout was introduced | ||
// to cover cases where the tcp connection works but | ||
// the server never answers. Defaults to 2 minutes. | ||
ResponseHeaderTimeout: time.Duration(config.ResponseHeaderTimeout), | ||
// Set this value so that the underlying transport round-tripper | ||
// doesn't try to auto decode the body of objects with | ||
// content-encoding set to `gzip`. | ||
// | ||
// Refer: https://golang.org/src/net/http/transport.go?h=roundTrip#L1843. | ||
DisableCompression: true, | ||
TLSClientConfig: tlsConfig, | ||
}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,8 @@ package azure | |
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
|
||
//"net" | ||
"net/http" | ||
"net/url" | ||
"regexp" | ||
|
@@ -18,7 +19,8 @@ import ( | |
"github.com/Azure/go-autorest/autorest/azure/auth" | ||
"github.com/go-kit/log" | ||
"github.com/go-kit/log/level" | ||
"github.com/thanos-io/thanos/pkg/objstore" | ||
"github.com/thanos-io/thanos/pkg/exthttp" | ||
//"github.com/thanos-io/thanos/pkg/objstore" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please avoid commenting code in a PR (: It's easy to merge such and create a bit of mess 🙈 |
||
) | ||
|
||
// DirDelim is the delimiter used to model a directory structure in an object store bucket. | ||
|
@@ -104,7 +106,7 @@ func getContainerURL(ctx context.Context, logger log.Logger, conf Config) (blob. | |
retryOptions.TryTimeout = time.Until(deadline) | ||
} | ||
|
||
dt, err := DefaultTransport(conf) | ||
dt, err := exthttp.DefaultTransport(conf.HTTPConfig) | ||
SrushtiSapkale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return blob.ContainerURL{}, err | ||
} | ||
|
@@ -140,36 +142,6 @@ func getContainerURL(ctx context.Context, logger log.Logger, conf Config) (blob. | |
return service.NewContainerURL(conf.ContainerName), nil | ||
} | ||
|
||
func DefaultTransport(config Config) (*http.Transport, error) { | ||
tlsConfig, err := objstore.NewTLSConfig(&config.HTTPConfig.TLSConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if config.HTTPConfig.InsecureSkipVerify { | ||
tlsConfig.InsecureSkipVerify = true | ||
} | ||
return &http.Transport{ | ||
Proxy: http.ProxyFromEnvironment, | ||
DialContext: (&net.Dialer{ | ||
Timeout: 30 * time.Second, | ||
KeepAlive: 30 * time.Second, | ||
DualStack: true, | ||
}).DialContext, | ||
|
||
MaxIdleConns: config.HTTPConfig.MaxIdleConns, | ||
MaxIdleConnsPerHost: config.HTTPConfig.MaxIdleConnsPerHost, | ||
IdleConnTimeout: time.Duration(config.HTTPConfig.IdleConnTimeout), | ||
MaxConnsPerHost: config.HTTPConfig.MaxConnsPerHost, | ||
TLSHandshakeTimeout: time.Duration(config.HTTPConfig.TLSHandshakeTimeout), | ||
ExpectContinueTimeout: time.Duration(config.HTTPConfig.ExpectContinueTimeout), | ||
|
||
ResponseHeaderTimeout: time.Duration(config.HTTPConfig.ResponseHeaderTimeout), | ||
DisableCompression: config.HTTPConfig.DisableCompression, | ||
TLSClientConfig: tlsConfig, | ||
}, nil | ||
} | ||
|
||
func getContainer(ctx context.Context, logger log.Logger, conf Config) (blob.ContainerURL, error) { | ||
c, err := getContainerURL(ctx, logger, conf) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://thanos.io/tip/contributing/coding-style-guide.md/#comments-should-be-full-sentences