@@ -10,6 +10,7 @@ import (
10
10
"net/http"
11
11
"net/url"
12
12
"strconv"
13
+ "strings"
13
14
"time"
14
15
15
16
"github.com/gogo/protobuf/proto"
@@ -74,7 +75,7 @@ func NewClient(
74
75
querierAddress : querierAddress ,
75
76
alertmanagerAddress : alertmanagerAddress ,
76
77
rulerAddress : rulerAddress ,
77
- timeout : 5 * time .Second ,
78
+ timeout : 30 * time .Second ,
78
79
httpClient : & http.Client {},
79
80
querierClient : promv1 .NewAPI (querierAPIClient ),
80
81
orgID : orgID ,
@@ -105,7 +106,7 @@ func NewPromQueryClient(address string) (*Client, error) {
105
106
}
106
107
107
108
c := & Client {
108
- timeout : 5 * time .Second ,
109
+ timeout : 30 * time .Second ,
109
110
httpClient : & http.Client {},
110
111
querierClient : promv1 .NewAPI (querierAPIClient ),
111
112
}
@@ -332,7 +333,26 @@ func (c *Client) OTLP(timeseries []prompb.TimeSeries) (*http.Response, error) {
332
333
333
334
// Query runs an instant query.
334
335
func (c * Client ) Query (query string , ts time.Time ) (model.Value , error ) {
335
- value , _ , err := c .querierClient .Query (context .Background (), query , ts )
336
+ ctx := context .Background ()
337
+ retries := backoff .New (ctx , backoff.Config {
338
+ MinBackoff : 1 * time .Second ,
339
+ MaxBackoff : 3 * time .Second ,
340
+ MaxRetries : 5 ,
341
+ })
342
+ var (
343
+ value model.Value
344
+ err error
345
+ )
346
+ for retries .Ongoing () {
347
+ value , _ , err = c .querierClient .Query (context .Background (), query , ts )
348
+ if err == nil {
349
+ break
350
+ }
351
+ if ! strings .Contains (err .Error (), "EOF" ) {
352
+ break
353
+ }
354
+ retries .Wait ()
355
+ }
336
356
return value , err
337
357
}
338
358
@@ -345,11 +365,31 @@ func (c *Client) QueryExemplars(query string, start, end time.Time) ([]promv1.Ex
345
365
346
366
// QueryRange runs a query range.
347
367
func (c * Client ) QueryRange (query string , start , end time.Time , step time.Duration ) (model.Value , error ) {
348
- value , _ , err := c .querierClient .QueryRange (context .Background (), query , promv1.Range {
349
- Start : start ,
350
- End : end ,
351
- Step : step ,
368
+ ctx := context .Background ()
369
+ retries := backoff .New (ctx , backoff.Config {
370
+ MinBackoff : 1 * time .Second ,
371
+ MaxBackoff : 3 * time .Second ,
372
+ MaxRetries : 5 ,
352
373
})
374
+ var (
375
+ value model.Value
376
+ err error
377
+ )
378
+ for retries .Ongoing () {
379
+ value , _ , err = c .querierClient .QueryRange (context .Background (), query , promv1.Range {
380
+ Start : start ,
381
+ End : end ,
382
+ Step : step ,
383
+ })
384
+ if err == nil {
385
+ break
386
+ }
387
+ if ! strings .Contains (err .Error (), "EOF" ) {
388
+ break
389
+ }
390
+ retries .Wait ()
391
+ }
392
+
353
393
return value , err
354
394
}
355
395
0 commit comments