Skip to content

Commit 47fbc56

Browse files
authored
Run more test cases per query fuzz test (#6311)
* run more test cases per query fuzz test Signed-off-by: Ben Ye <[email protected]> * run 1000 test cases Signed-off-by: Ben Ye <[email protected]> * add retry to EOF errors Signed-off-by: Ben Ye <[email protected]> --------- Signed-off-by: Ben Ye <[email protected]>
1 parent e1c3d79 commit 47fbc56

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

Diff for: integration/e2ecortex/client.go

+47-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"net/url"
1212
"strconv"
13+
"strings"
1314
"time"
1415

1516
"github.com/gogo/protobuf/proto"
@@ -74,7 +75,7 @@ func NewClient(
7475
querierAddress: querierAddress,
7576
alertmanagerAddress: alertmanagerAddress,
7677
rulerAddress: rulerAddress,
77-
timeout: 5 * time.Second,
78+
timeout: 30 * time.Second,
7879
httpClient: &http.Client{},
7980
querierClient: promv1.NewAPI(querierAPIClient),
8081
orgID: orgID,
@@ -105,7 +106,7 @@ func NewPromQueryClient(address string) (*Client, error) {
105106
}
106107

107108
c := &Client{
108-
timeout: 5 * time.Second,
109+
timeout: 30 * time.Second,
109110
httpClient: &http.Client{},
110111
querierClient: promv1.NewAPI(querierAPIClient),
111112
}
@@ -332,7 +333,26 @@ func (c *Client) OTLP(timeseries []prompb.TimeSeries) (*http.Response, error) {
332333

333334
// Query runs an instant query.
334335
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+
}
336356
return value, err
337357
}
338358

@@ -345,11 +365,31 @@ func (c *Client) QueryExemplars(query string, start, end time.Time) ([]promv1.Ex
345365

346366
// QueryRange runs a query range.
347367
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,
352373
})
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+
353393
return value, err
354394
}
355395

Diff for: integration/query_fuzz_test.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func TestVerticalShardingFuzz(t *testing.T) {
515515
}
516516
ps := promqlsmith.New(rnd, lbls, opts...)
517517

518-
runQueryFuzzTestCases(t, ps, c1, c2, now, start, end, scrapeInterval, 100)
518+
runQueryFuzzTestCases(t, ps, c1, c2, now, start, end, scrapeInterval, 1000)
519519
}
520520

521521
// comparer should be used to compare promql results between engines.
@@ -1065,7 +1065,7 @@ func TestBackwardCompatibilityQueryFuzz(t *testing.T) {
10651065
}
10661066
ps := promqlsmith.New(rnd, lbls, opts...)
10671067

1068-
runQueryFuzzTestCases(t, ps, c1, c2, end, start, end, scrapeInterval, 100)
1068+
runQueryFuzzTestCases(t, ps, c1, c2, end, start, end, scrapeInterval, 1000)
10691069
}
10701070

10711071
// TestPrometheusCompatibilityQueryFuzz compares Cortex with latest Prometheus release.
@@ -1178,7 +1178,7 @@ func TestPrometheusCompatibilityQueryFuzz(t *testing.T) {
11781178
}
11791179
ps := promqlsmith.New(rnd, lbls, opts...)
11801180

1181-
runQueryFuzzTestCases(t, ps, c1, c2, end, start, end, scrapeInterval, 100)
1181+
runQueryFuzzTestCases(t, ps, c1, c2, end, start, end, scrapeInterval, 1000)
11821182
}
11831183

11841184
// waitUntilReady is a helper function to wait and check if both servers to test load the expected data.
@@ -1201,8 +1201,11 @@ func waitUntilReady(t *testing.T, ctx context.Context, c1, c2 *e2ecortex.Client,
12011201
labelSet2, err = c2.Series([]string{query}, start, end)
12021202
require.NoError(t, err)
12031203

1204-
if cmp.Equal(labelSet1, labelSet2, labelSetsComparer) {
1205-
break
1204+
// Make sure series can be queried.
1205+
if len(labelSet1) > 0 {
1206+
if cmp.Equal(labelSet1, labelSet2, labelSetsComparer) {
1207+
break
1208+
}
12061209
}
12071210

12081211
retries.Wait()

0 commit comments

Comments
 (0)