From 419d323a3f6beaab644772d942c9a05760b11afb Mon Sep 17 00:00:00 2001 From: Filip Petkovski Date: Thu, 20 Oct 2022 10:12:30 +0200 Subject: [PATCH] Fix querier tests Signed-off-by: Filip Petkovski --- pkg/query/querier_test.go | 10 +++++----- pkg/query/query_bench_test.go | 2 +- pkg/receive/multitsdb.go | 13 ++++++++----- pkg/store/bucket.go | 3 ++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/query/querier_test.go b/pkg/query/querier_test.go index 5fd95a56f3b..2403651adee 100644 --- a/pkg/query/querier_test.go +++ b/pkg/query/querier_test.go @@ -641,7 +641,7 @@ func TestQuerier_Select(t *testing.T) { } { g := gate.New(2) - proxy := newProxyForStore(tcase.storeAPI) + proxy := newProxyForStore(false, tcase.storeAPI) q := newQuerier(context.Background(), nil, tcase.mint, tcase.maxt, tcase.replicaLabels, nil, proxy, sc.dedup, 0, true, false, false, g, timeout, nil, NoopSeriesStatsReporter) t.Cleanup(func() { testutil.Ok(t, q.Close()) }) @@ -685,13 +685,13 @@ func TestQuerier_Select(t *testing.T) { } } -func newProxyForStore(storeAPI ...storepb.StoreServer) *store.ProxyStore { +func newProxyForStore(storesWithSortedSeries bool, storeAPI ...storepb.StoreServer) *store.ProxyStore { labelsFunc := func() []labelpb.ZLabelSet { return nil } timeFunc := func() (int64, int64) { return math.MinInt64, math.MaxInt64 } clientsFunc := func() []store.Client { clients := make([]store.Client, 0, len(storeAPI)) for _, s := range storeAPI { - clients = append(clients, receive.NewLocalClient(storepb.ServerAsClient(s, 0), labelsFunc, timeFunc)) + clients = append(clients, receive.NewLocalClient(storepb.ServerAsClient(s, 0), storesWithSortedSeries, labelsFunc, timeFunc)) } return clients } @@ -886,7 +886,7 @@ func TestQuerierWithDedupUnderstoodByPromQL_Rate(t *testing.T) { timeout := 100 * time.Second g := gate.New(2) - proxy := newProxyForStore(s) + proxy := newProxyForStore(false, s) q := newQuerier(context.Background(), logger, realSeriesWithStaleMarkerMint, realSeriesWithStaleMarkerMaxt, []string{"replica"}, nil, proxy, false, 0, true, false, false, g, timeout, nil, NoopSeriesStatsReporter) t.Cleanup(func() { @@ -959,7 +959,7 @@ func TestQuerierWithDedupUnderstoodByPromQL_Rate(t *testing.T) { timeout := 5 * time.Second g := gate.New(2) - proxy := newProxyForStore(s) + proxy := newProxyForStore(false, s) q := newQuerier(context.Background(), logger, realSeriesWithStaleMarkerMint, realSeriesWithStaleMarkerMaxt, []string{"replica"}, nil, proxy, true, 0, true, false, false, g, timeout, nil, NoopSeriesStatsReporter) t.Cleanup(func() { diff --git a/pkg/query/query_bench_test.go b/pkg/query/query_bench_test.go index 3b15b5eba71..020609e84c4 100644 --- a/pkg/query/query_bench_test.go +++ b/pkg/query/query_bench_test.go @@ -84,7 +84,7 @@ func benchQuerySelect(t testutil.TB, totalSamples, totalSeries int, dedup bool) q := &querier{ ctx: context.Background(), logger: logger, - proxy: newProxyForStore(stores...), + proxy: newProxyForStore(true, stores...), replicaLabels: []string{"z_replica"}, replicaLabelSet: map[string]struct{}{"z_replica": {}}, deduplicate: dedup, diff --git a/pkg/receive/multitsdb.go b/pkg/receive/multitsdb.go index a647c401771..8cb721a5839 100644 --- a/pkg/receive/multitsdb.go +++ b/pkg/receive/multitsdb.go @@ -93,16 +93,18 @@ func NewMultiTSDB( type localClient struct { storepb.StoreClient - labelSetFunc func() []labelpb.ZLabelSet - timeRangeFunc func() (int64, int64) + sendsSortedSeries bool + labelSetFunc func() []labelpb.ZLabelSet + timeRangeFunc func() (int64, int64) } func NewLocalClient( c storepb.StoreClient, + sendsSortedSeries bool, labelSetFunc func() []labelpb.ZLabelSet, timeRangeFunc func() (int64, int64), ) store.Client { - return &localClient{c, labelSetFunc, timeRangeFunc} + return &localClient{c, sendsSortedSeries, labelSetFunc, timeRangeFunc} } func (l *localClient) LabelSets() []labels.Labels { @@ -130,7 +132,7 @@ func (l *localClient) SupportsSharding() bool { } func (l *localClient) SendsSortedSeries() bool { - return true + return l.sendsSortedSeries } type tenant struct { @@ -165,7 +167,8 @@ func (t *tenant) client() store.Client { store := t.store() client := storepb.ServerAsClient(store, 0) - return NewLocalClient(client, store.LabelSet, store.TimeRange) + + return NewLocalClient(client, true, store.LabelSet, store.TimeRange) } func (t *tenant) exemplars() *exemplars.TSDB { diff --git a/pkg/store/bucket.go b/pkg/store/bucket.go index d8dc981e6d5..b8ea47027f2 100644 --- a/pkg/store/bucket.go +++ b/pkg/store/bucket.go @@ -1048,7 +1048,8 @@ func (s *BucketStore) Series(req *storepb.SeriesRequest, srv storepb.Store_Serie } } - // Label from individual series are already sorted by wrapping respones in sortedSeriesSet. + // Label from individual series are already sorted by wrapping responses in sortedSeriesSet. + // Because of that, we can set the sortLabels argument to false and save some CPU cycles. sortedSeriesSrv := newSortedSeriesServer(srv, sortWithoutLabelSet, false, sortSeries) for _, bs := range s.blockSets { blockMatchers, ok := bs.labelMatchers(matchers...)