mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-27 22:49:40 -08:00
remote: Expose ClientConfig type (#3165)
The Client type is already exposed, but can't be used without the config for it also being exposed. Using the remote.Client from other programs is useful to do full end-to-end tests of Prometheus's remote protocol against adapter implementations.
This commit is contained in:
parent
f66f882d08
commit
8ebeed0b44
|
@ -43,29 +43,30 @@ type Client struct {
|
||||||
timeout time.Duration
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type clientConfig struct {
|
// ClientConfig configures a Client.
|
||||||
url *config.URL
|
type ClientConfig struct {
|
||||||
timeout model.Duration
|
URL *config.URL
|
||||||
httpClientConfig config.HTTPClientConfig
|
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) {
|
||||||
// If not specified in config, allow HTTP connections for remote API to use keep-alive
|
// If not specified in config, allow HTTP connections for remote API to use keep-alive
|
||||||
if conf.httpClientConfig.KeepAlive == nil {
|
if conf.HTTPClientConfig.KeepAlive == nil {
|
||||||
val := true
|
val := true
|
||||||
conf.httpClientConfig.KeepAlive = &val
|
conf.HTTPClientConfig.KeepAlive = &val
|
||||||
}
|
}
|
||||||
httpClient, err := httputil.NewClientFromConfig(conf.httpClientConfig)
|
httpClient, err := httputil.NewClientFromConfig(conf.HTTPClientConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Client{
|
return &Client{
|
||||||
index: index,
|
index: index,
|
||||||
url: conf.url,
|
url: conf.URL,
|
||||||
client: httpClient,
|
client: httpClient,
|
||||||
timeout: time.Duration(conf.timeout),
|
timeout: time.Duration(conf.Timeout),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,9 +64,9 @@ func TestStoreHTTPErrorHandling(t *testing.T) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := NewClient(0, &clientConfig{
|
c, err := NewClient(0, &ClientConfig{
|
||||||
url: &config.URL{serverURL},
|
URL: &config.URL{serverURL},
|
||||||
timeout: model.Duration(time.Second),
|
Timeout: model.Duration(time.Second),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -37,10 +37,10 @@ type Reader struct {
|
||||||
func (r *Reader) ApplyConfig(conf *config.Config) error {
|
func (r *Reader) ApplyConfig(conf *config.Config) error {
|
||||||
clients := []*Client{}
|
clients := []*Client{}
|
||||||
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,
|
||||||
timeout: rrConf.RemoteTimeout,
|
Timeout: rrConf.RemoteTimeout,
|
||||||
httpClientConfig: rrConf.HTTPClientConfig,
|
HTTPClientConfig: rrConf.HTTPClientConfig,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -36,10 +36,10 @@ func (w *Writer) ApplyConfig(conf *config.Config) error {
|
||||||
// TODO: we should only stop & recreate queues which have changes,
|
// TODO: we should only stop & recreate queues which have changes,
|
||||||
// as this can be quite disruptive.
|
// as this can be quite disruptive.
|
||||||
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,
|
||||||
timeout: rwConf.RemoteTimeout,
|
Timeout: rwConf.RemoteTimeout,
|
||||||
httpClientConfig: rwConf.HTTPClientConfig,
|
HTTPClientConfig: rwConf.HTTPClientConfig,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue