From 3760f56c0c7341cccb6bd8c80f94822a05be4066 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Mon, 23 Oct 2017 14:53:43 +0100 Subject: [PATCH] remote: Expose ClientConfig type (see #3165) --- storage/remote/client.go | 23 +++++++++++++---------- storage/remote/client_test.go | 6 +++--- storage/remote/read_test.go | 10 +++++----- storage/remote/storage.go | 18 +++++++++--------- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/storage/remote/client.go b/storage/remote/client.go index e5b5bf3245..421506382e 100644 --- a/storage/remote/client.go +++ b/storage/remote/client.go @@ -45,26 +45,27 @@ type Client struct { readRecent bool } -type clientConfig struct { - url *config.URL - timeout model.Duration - readRecent bool - httpClientConfig config.HTTPClientConfig +// ClientConfig configures a Client. +type ClientConfig struct { + URL *config.URL + Timeout model.Duration + ReadRecent bool + HTTPClientConfig config.HTTPClientConfig } // NewClient creates a new Client. -func NewClient(index int, conf *clientConfig) (*Client, error) { - httpClient, err := httputil.NewClientFromConfig(conf.httpClientConfig, "remote_storage") +func NewClient(index int, conf *ClientConfig) (*Client, error) { + httpClient, err := httputil.NewClientFromConfig(conf.HTTPClientConfig, "remote_storage") if err != nil { return nil, err } return &Client{ index: index, - url: conf.url, + url: conf.URL, client: httpClient, - timeout: time.Duration(conf.timeout), - readRecent: conf.readRecent, + timeout: time.Duration(conf.Timeout), + readRecent: conf.ReadRecent, }, nil } @@ -129,6 +130,8 @@ func (c *Client) Read(ctx context.Context, from, through int64, matchers []*labe } req := &prompb.ReadRequest{ + // TODO: Support batching multiple queries into one read request, + // as the protobuf interface allows for it. Queries: []*prompb.Query{ query, }, diff --git a/storage/remote/client_test.go b/storage/remote/client_test.go index 5790f3f002..9f3293ceb3 100644 --- a/storage/remote/client_test.go +++ b/storage/remote/client_test.go @@ -64,9 +64,9 @@ func TestStoreHTTPErrorHandling(t *testing.T) { t.Fatal(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) diff --git a/storage/remote/read_test.go b/storage/remote/read_test.go index 7fec0bb8e4..c32ee9f672 100644 --- a/storage/remote/read_test.go +++ b/storage/remote/read_test.go @@ -184,11 +184,11 @@ func TestRemoteStorageQuerier(t *testing.T) { s := NewStorage(nil, func() (int64, error) { return test.localStartTime, nil }) s.clients = []*Client{} for _, readRecent := range test.readRecentClients { - c, _ := NewClient(0, &clientConfig{ - url: nil, - timeout: model.Duration(30 * time.Second), - httpClientConfig: config.HTTPClientConfig{}, - readRecent: readRecent, + c, _ := NewClient(0, &ClientConfig{ + URL: nil, + Timeout: model.Duration(30 * time.Second), + HTTPClientConfig: config.HTTPClientConfig{}, + ReadRecent: readRecent, }) s.clients = append(s.clients, c) } diff --git a/storage/remote/storage.go b/storage/remote/storage.go index 65f3f2d19d..e5bc3aaa5d 100644 --- a/storage/remote/storage.go +++ b/storage/remote/storage.go @@ -58,10 +58,10 @@ func (s *Storage) 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 @@ -88,11 +88,11 @@ func (s *Storage) 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, - readRecent: rrConf.ReadRecent, + c, err := NewClient(i, &ClientConfig{ + URL: rrConf.URL, + Timeout: rrConf.RemoteTimeout, + HTTPClientConfig: rrConf.HTTPClientConfig, + ReadRecent: rrConf.ReadRecent, }) if err != nil { return err