Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run more test cases per query fuzz test #6311

Merged
merged 3 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions integration/e2ecortex/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"strconv"
"strings"
"time"

"github.com/gogo/protobuf/proto"
Expand Down Expand Up @@ -74,7 +75,7 @@ func NewClient(
querierAddress: querierAddress,
alertmanagerAddress: alertmanagerAddress,
rulerAddress: rulerAddress,
timeout: 5 * time.Second,
timeout: 30 * time.Second,
httpClient: &http.Client{},
querierClient: promv1.NewAPI(querierAPIClient),
orgID: orgID,
Expand Down Expand Up @@ -105,7 +106,7 @@ func NewPromQueryClient(address string) (*Client, error) {
}

c := &Client{
timeout: 5 * time.Second,
timeout: 30 * time.Second,
httpClient: &http.Client{},
querierClient: promv1.NewAPI(querierAPIClient),
}
Expand Down Expand Up @@ -332,7 +333,26 @@ func (c *Client) OTLP(timeseries []prompb.TimeSeries) (*http.Response, error) {

// Query runs an instant query.
func (c *Client) Query(query string, ts time.Time) (model.Value, error) {
value, _, err := c.querierClient.Query(context.Background(), query, ts)
ctx := context.Background()
retries := backoff.New(ctx, backoff.Config{
MinBackoff: 1 * time.Second,
MaxBackoff: 3 * time.Second,
MaxRetries: 5,
})
var (
value model.Value
err error
)
for retries.Ongoing() {
value, _, err = c.querierClient.Query(context.Background(), query, ts)
if err == nil {
break
}
if !strings.Contains(err.Error(), "EOF") {
break
}
retries.Wait()
}
return value, err
}

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

// QueryRange runs a query range.
func (c *Client) QueryRange(query string, start, end time.Time, step time.Duration) (model.Value, error) {
value, _, err := c.querierClient.QueryRange(context.Background(), query, promv1.Range{
Start: start,
End: end,
Step: step,
ctx := context.Background()
retries := backoff.New(ctx, backoff.Config{
MinBackoff: 1 * time.Second,
MaxBackoff: 3 * time.Second,
MaxRetries: 5,
})
var (
value model.Value
err error
)
for retries.Ongoing() {
value, _, err = c.querierClient.QueryRange(context.Background(), query, promv1.Range{
Start: start,
End: end,
Step: step,
})
if err == nil {
break
}
if !strings.Contains(err.Error(), "EOF") {
break
}
retries.Wait()
}

return value, err
}

Expand Down
13 changes: 8 additions & 5 deletions integration/query_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ func TestVerticalShardingFuzz(t *testing.T) {
}
ps := promqlsmith.New(rnd, lbls, opts...)

runQueryFuzzTestCases(t, ps, c1, c2, now, start, end, scrapeInterval, 100)
runQueryFuzzTestCases(t, ps, c1, c2, now, start, end, scrapeInterval, 1000)
}

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

runQueryFuzzTestCases(t, ps, c1, c2, end, start, end, scrapeInterval, 100)
runQueryFuzzTestCases(t, ps, c1, c2, end, start, end, scrapeInterval, 1000)
}

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

runQueryFuzzTestCases(t, ps, c1, c2, end, start, end, scrapeInterval, 100)
runQueryFuzzTestCases(t, ps, c1, c2, end, start, end, scrapeInterval, 1000)
}

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

if cmp.Equal(labelSet1, labelSet2, labelSetsComparer) {
break
// Make sure series can be queried.
if len(labelSet1) > 0 {
if cmp.Equal(labelSet1, labelSet2, labelSetsComparer) {
break
}
}

retries.Wait()
Expand Down
Loading