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 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
} }

View file

@ -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)

View file

@ -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

View file

@ -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