remote: Expose ClientConfig type (see #3165)

This commit is contained in:
Tom Wilkie 2017-10-23 14:53:43 +01:00
parent 16f71a7723
commit 3760f56c0c
4 changed files with 30 additions and 27 deletions

View file

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

View file

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

View file

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

View file

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