mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-12 16:44:05 -08:00
Make remote read/write use config.HTTPClientConfig
This commit is contained in:
parent
406b65d0dc
commit
eb14678a25
|
@ -1306,11 +1306,12 @@ func (re Regexp) MarshalYAML() (interface{}, error) {
|
||||||
type RemoteWriteConfig struct {
|
type RemoteWriteConfig struct {
|
||||||
URL *URL `yaml:"url,omitempty"`
|
URL *URL `yaml:"url,omitempty"`
|
||||||
RemoteTimeout model.Duration `yaml:"remote_timeout,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"`
|
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.
|
// Catches all undefined fields and must be empty after parsing.
|
||||||
XXX map[string]interface{} `yaml:",inline"`
|
XXX map[string]interface{} `yaml:",inline"`
|
||||||
}
|
}
|
||||||
|
@ -1332,9 +1333,10 @@ func (c *RemoteWriteConfig) UnmarshalYAML(unmarshal func(interface{}) error) err
|
||||||
type RemoteReadConfig struct {
|
type RemoteReadConfig struct {
|
||||||
URL *URL `yaml:"url,omitempty"`
|
URL *URL `yaml:"url,omitempty"`
|
||||||
RemoteTimeout model.Duration `yaml:"remote_timeout,omitempty"`
|
RemoteTimeout model.Duration `yaml:"remote_timeout,omitempty"`
|
||||||
BasicAuth *BasicAuth `yaml:"basic_auth,omitempty"`
|
|
||||||
TLSConfig TLSConfig `yaml:"tls_config,omitempty"`
|
// We cannot do proper Go type embedding below as the parser will then parse
|
||||||
ProxyURL URL `yaml:"proxy_url,omitempty"`
|
// values arbitrarily into the overflow maps of further-down types.
|
||||||
|
HTTPClientConfig HTTPClientConfig `yaml:",inline"`
|
||||||
|
|
||||||
// Catches all undefined fields and must be empty after parsing.
|
// Catches all undefined fields and must be empty after parsing.
|
||||||
XXX map[string]interface{} `yaml:",inline"`
|
XXX map[string]interface{} `yaml:",inline"`
|
||||||
|
|
|
@ -27,8 +27,8 @@ import (
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/prometheus/prometheus/config"
|
"github.com/prometheus/prometheus/config"
|
||||||
|
"github.com/prometheus/prometheus/retrieval"
|
||||||
"github.com/prometheus/prometheus/storage/metric"
|
"github.com/prometheus/prometheus/storage/metric"
|
||||||
"github.com/prometheus/prometheus/util/httputil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client allows reading and writing from/to a remote HTTP endpoint.
|
// Client allows reading and writing from/to a remote HTTP endpoint.
|
||||||
|
@ -41,34 +41,21 @@ type Client struct {
|
||||||
|
|
||||||
type clientConfig struct {
|
type clientConfig struct {
|
||||||
url *config.URL
|
url *config.URL
|
||||||
tlsConfig config.TLSConfig
|
|
||||||
proxyURL *config.URL
|
|
||||||
basicAuth *config.BasicAuth
|
|
||||||
timeout model.Duration
|
timeout model.Duration
|
||||||
|
httpClientConfig config.HTTPClientConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a new Client.
|
// NewClient creates a new Client.
|
||||||
func NewClient(index int, conf *clientConfig) (*Client, error) {
|
func NewClient(index int, conf *clientConfig) (*Client, error) {
|
||||||
tlsConfig, err := httputil.NewTLSConfig(conf.tlsConfig)
|
httpClient, err := retrieval.NewHTTPClient(conf.httpClientConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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{
|
return &Client{
|
||||||
index: index,
|
index: index,
|
||||||
url: conf.url,
|
url: conf.url,
|
||||||
client: httputil.NewClient(rt),
|
client: httpClient,
|
||||||
timeout: time.Duration(conf.timeout),
|
timeout: time.Duration(conf.timeout),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,10 +37,8 @@ func (r *Reader) ApplyConfig(conf *config.Config) error {
|
||||||
for i, rrConf := range conf.RemoteReadConfigs {
|
for i, rrConf := range conf.RemoteReadConfigs {
|
||||||
c, err := NewClient(i, &clientConfig{
|
c, err := NewClient(i, &clientConfig{
|
||||||
url: rrConf.URL,
|
url: rrConf.URL,
|
||||||
tlsConfig: rrConf.TLSConfig,
|
|
||||||
proxyURL: &rrConf.ProxyURL,
|
|
||||||
basicAuth: rrConf.BasicAuth,
|
|
||||||
timeout: rrConf.RemoteTimeout,
|
timeout: rrConf.RemoteTimeout,
|
||||||
|
httpClientConfig: rrConf.HTTPClientConfig,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -38,10 +38,8 @@ func (w *Writer) ApplyConfig(conf *config.Config) error {
|
||||||
for i, rwConf := range conf.RemoteWriteConfigs {
|
for i, rwConf := range conf.RemoteWriteConfigs {
|
||||||
c, err := NewClient(i, &clientConfig{
|
c, err := NewClient(i, &clientConfig{
|
||||||
url: rwConf.URL,
|
url: rwConf.URL,
|
||||||
tlsConfig: rwConf.TLSConfig,
|
|
||||||
proxyURL: &rwConf.ProxyURL,
|
|
||||||
basicAuth: rwConf.BasicAuth,
|
|
||||||
timeout: rwConf.RemoteTimeout,
|
timeout: rwConf.RemoteTimeout,
|
||||||
|
httpClientConfig: rwConf.HTTPClientConfig,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue