Make remote read/write use config.HTTPClientConfig

pull/2499/head
Julius Volz 8 years ago
parent 406b65d0dc
commit eb14678a25

@ -1306,11 +1306,12 @@ func (re Regexp) MarshalYAML() (interface{}, error) {
type RemoteWriteConfig struct {
URL *URL `yaml:"url,omitempty"`
RemoteTimeout model.Duration `yaml:"remote_timeout,omitempty"`
BasicAuth *BasicAuth `yaml:"basic_auth,omitempty"`
TLSConfig TLSConfig `yaml:"tls_config,omitempty"`
ProxyURL URL `yaml:"proxy_url,omitempty"`
WriteRelabelConfigs []*RelabelConfig `yaml:"write_relabel_configs,omitempty"`
// We cannot do proper Go type embedding below as the parser will then parse
// values arbitrarily into the overflow maps of further-down types.
HTTPClientConfig HTTPClientConfig `yaml:",inline"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
}
@ -1332,9 +1333,10 @@ func (c *RemoteWriteConfig) UnmarshalYAML(unmarshal func(interface{}) error) err
type RemoteReadConfig struct {
URL *URL `yaml:"url,omitempty"`
RemoteTimeout model.Duration `yaml:"remote_timeout,omitempty"`
BasicAuth *BasicAuth `yaml:"basic_auth,omitempty"`
TLSConfig TLSConfig `yaml:"tls_config,omitempty"`
ProxyURL URL `yaml:"proxy_url,omitempty"`
// We cannot do proper Go type embedding below as the parser will then parse
// values arbitrarily into the overflow maps of further-down types.
HTTPClientConfig HTTPClientConfig `yaml:",inline"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`

@ -27,8 +27,8 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/retrieval"
"github.com/prometheus/prometheus/storage/metric"
"github.com/prometheus/prometheus/util/httputil"
)
// Client allows reading and writing from/to a remote HTTP endpoint.
@ -41,34 +41,21 @@ type Client struct {
type clientConfig struct {
url *config.URL
tlsConfig config.TLSConfig
proxyURL *config.URL
basicAuth *config.BasicAuth
timeout model.Duration
httpClientConfig config.HTTPClientConfig
}
// NewClient creates a new Client.
func NewClient(index int, conf *clientConfig) (*Client, error) {
tlsConfig, err := httputil.NewTLSConfig(conf.tlsConfig)
httpClient, err := retrieval.NewHTTPClient(conf.httpClientConfig)
if err != nil {
return nil, err
}
// The only timeout we care about is the configured push timeout.
// It is applied on request. So we leave out any timings here.
var rt http.RoundTripper = &http.Transport{
Proxy: http.ProxyURL(conf.proxyURL.URL),
TLSClientConfig: tlsConfig,
}
if conf.basicAuth != nil {
rt = httputil.NewBasicAuthRoundTripper(conf.basicAuth.Username, conf.basicAuth.Password, rt)
}
return &Client{
index: index,
url: conf.url,
client: httputil.NewClient(rt),
client: httpClient,
timeout: time.Duration(conf.timeout),
}, nil
}

@ -37,10 +37,8 @@ func (r *Reader) ApplyConfig(conf *config.Config) error {
for i, rrConf := range conf.RemoteReadConfigs {
c, err := NewClient(i, &clientConfig{
url: rrConf.URL,
tlsConfig: rrConf.TLSConfig,
proxyURL: &rrConf.ProxyURL,
basicAuth: rrConf.BasicAuth,
timeout: rrConf.RemoteTimeout,
httpClientConfig: rrConf.HTTPClientConfig,
})
if err != nil {
return err

@ -38,10 +38,8 @@ func (w *Writer) ApplyConfig(conf *config.Config) error {
for i, rwConf := range conf.RemoteWriteConfigs {
c, err := NewClient(i, &clientConfig{
url: rwConf.URL,
tlsConfig: rwConf.TLSConfig,
proxyURL: &rwConf.ProxyURL,
basicAuth: rwConf.BasicAuth,
timeout: rwConf.RemoteTimeout,
httpClientConfig: rwConf.HTTPClientConfig,
})
if err != nil {
return err

Loading…
Cancel
Save