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:
Julius Volz 2017-09-14 15:25:09 +02:00 committed by GitHub
parent f66f882d08
commit 8ebeed0b44
4 changed files with 22 additions and 21 deletions

View file

@ -43,29 +43,30 @@ type Client struct {
timeout time.Duration
}
type clientConfig struct {
url *config.URL
timeout model.Duration
httpClientConfig config.HTTPClientConfig
// ClientConfig configures a Client.
type ClientConfig struct {
URL *config.URL
Timeout model.Duration
HTTPClientConfig config.HTTPClientConfig
}
// 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 conf.httpClientConfig.KeepAlive == nil {
if conf.HTTPClientConfig.KeepAlive == nil {
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 {
return nil, err
}
return &Client{
index: index,
url: conf.url,
url: conf.URL,
client: httpClient,
timeout: time.Duration(conf.timeout),
timeout: time.Duration(conf.Timeout),
}, nil
}

View file

@ -64,9 +64,9 @@ func TestStoreHTTPErrorHandling(t *testing.T) {
panic(err)
}
c, err := NewClient(0, &clientConfig{
url: &config.URL{serverURL},
timeout: model.Duration(time.Second),
c, err := NewClient(0, &ClientConfig{
URL: &config.URL{serverURL},
Timeout: model.Duration(time.Second),
})
if err != nil {
t.Fatal(err)

View file

@ -37,10 +37,10 @@ type Reader struct {
func (r *Reader) ApplyConfig(conf *config.Config) error {
clients := []*Client{}
for i, rrConf := range conf.RemoteReadConfigs {
c, err := NewClient(i, &clientConfig{
url: rrConf.URL,
timeout: rrConf.RemoteTimeout,
httpClientConfig: rrConf.HTTPClientConfig,
c, err := NewClient(i, &ClientConfig{
URL: rrConf.URL,
Timeout: rrConf.RemoteTimeout,
HTTPClientConfig: rrConf.HTTPClientConfig,
})
if err != nil {
return err

View file

@ -36,10 +36,10 @@ func (w *Writer) ApplyConfig(conf *config.Config) error {
// TODO: we should only stop & recreate queues which have changes,
// as this can be quite disruptive.
for i, rwConf := range conf.RemoteWriteConfigs {
c, err := NewClient(i, &clientConfig{
url: rwConf.URL,
timeout: rwConf.RemoteTimeout,
httpClientConfig: rwConf.HTTPClientConfig,
c, err := NewClient(i, &ClientConfig{
URL: rwConf.URL,
Timeout: rwConf.RemoteTimeout,
HTTPClientConfig: rwConf.HTTPClientConfig,
})
if err != nil {
return err