From 6f26748d6aafeea5d73fcbeff9732fee8a4c638b Mon Sep 17 00:00:00 2001 From: bwplotka Date: Tue, 20 Dec 2022 11:48:25 +0100 Subject: [PATCH] Fixed tests. Signed-off-by: bwplotka --- pkg/dedup/iter_test.go | 1 + pkg/query/querier.go | 3 --- pkg/query/querier_test.go | 2 +- pkg/store/local.go | 3 ++- pkg/store/proxy_heap.go | 6 ++++-- pkg/store/proxy_heap_test.go | 19 +++++++++++++++++++ 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pkg/dedup/iter_test.go b/pkg/dedup/iter_test.go index ace40523d9..0efbc04d7a 100644 --- a/pkg/dedup/iter_test.go +++ b/pkg/dedup/iter_test.go @@ -15,6 +15,7 @@ import ( "github.com/prometheus/prometheus/model/labels" "github.com/prometheus/prometheus/storage" "github.com/prometheus/prometheus/tsdb/chunkenc" + "github.com/thanos-io/thanos/pkg/store/storepb" "github.com/efficientgo/core/testutil" ) diff --git a/pkg/query/querier.go b/pkg/query/querier.go index 5dda9f45a0..9e2cf6280e 100644 --- a/pkg/query/querier.go +++ b/pkg/query/querier.go @@ -5,7 +5,6 @@ package query import ( "context" - "fmt" "strings" "sync" "time" @@ -393,8 +392,6 @@ func (q *querier) selectFn(ctx context.Context, hints *storage.SelectHints, ms . } } - fmt.Println(resp.seriesSet) - if !q.isDedupEnabled() { return &promSeriesSet{ mint: q.mint, diff --git a/pkg/query/querier_test.go b/pkg/query/querier_test.go index 07967ae6db..5bfdc559b5 100644 --- a/pkg/query/querier_test.go +++ b/pkg/query/querier_test.go @@ -677,7 +677,7 @@ func TestQuerier_Select(t *testing.T) { { lset: labels.FromStrings("a", "1", "x", "1"), // We don't expect correctness here, it's just random non-replica data. - samples: []sample{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {100, 1}, {300, 3}}, + samples: []sample{{1, 1}, {2, 2}, {3, 3}, {100, 1}, {300, 3}}, }, { lset: labels.FromStrings("a", "1", "x", "2"), diff --git a/pkg/store/local.go b/pkg/store/local.go index 5cc20ee460..4e88c0a7e3 100644 --- a/pkg/store/local.go +++ b/pkg/store/local.go @@ -182,7 +182,8 @@ func (s *LocalStore) Series(r *storepb.SeriesRequest, srv storepb.Store_SeriesSe chosen = chosen[:0] resp := &storepb.Series{ - Labels: series.Labels, + // Copy labels as in-process clients like proxy tend to work on same memory for labels. + Labels: labelpb.DeepCopy(series.Labels), Chunks: make([]storepb.AggrChunk, 0, len(s.sortedChunks[si])), } diff --git a/pkg/store/proxy_heap.go b/pkg/store/proxy_heap.go index 9099a3b39c..028ac81a7e 100644 --- a/pkg/store/proxy_heap.go +++ b/pkg/store/proxy_heap.go @@ -147,8 +147,10 @@ func chainSeriesAndRemIdenticalChunks(series []*storepb.SeriesResponse) *storepb return finalChunks[i].Compare(finalChunks[j]) > 0 }) - series[0].GetSeries().Chunks = finalChunks - return series[0] + return storepb.NewSeriesResponse(&storepb.Series{ + Labels: series[0].GetSeries().Labels, + Chunks: finalChunks, + }) } func (d *dedupResponseHeap) At() *storepb.SeriesResponse { diff --git a/pkg/store/proxy_heap_test.go b/pkg/store/proxy_heap_test.go index e00d9222a7..448b67cfc9 100644 --- a/pkg/store/proxy_heap_test.go +++ b/pkg/store/proxy_heap_test.go @@ -84,6 +84,25 @@ func TestSortWithoutLabels(t *testing.T) { }, dedupLabels: map[string]struct{}{"b": {}}, }, + // Longer series. + { + input: []*storepb.SeriesResponse{ + storeSeriesResponse(t, labels.FromStrings( + "__name__", "gitlab_transaction_cache_read_hit_count_total", "action", "widget.json", "controller", "Projects::MergeRequests::ContentController", "env", "gprd", "environment", + "gprd", "fqdn", "web-08-sv-gprd.c.gitlab-production.internal", "instance", "web-08-sv-gprd.c.gitlab-production.internal:8083", "job", "gitlab-rails", "monitor", "app", "provider", + "gcp", "region", "us-east", "replica", "01", "shard", "default", "stage", "main", "tier", "sv", "type", "web", + )), + }, + exp: []*storepb.SeriesResponse{ + storeSeriesResponse(t, labels.FromStrings( + // No replica label anymore. + "__name__", "gitlab_transaction_cache_read_hit_count_total", "action", "widget.json", "controller", "Projects::MergeRequests::ContentController", "env", "gprd", "environment", + "gprd", "fqdn", "web-08-sv-gprd.c.gitlab-production.internal", "instance", "web-08-sv-gprd.c.gitlab-production.internal:8083", "job", "gitlab-rails", "monitor", "app", "provider", + "gcp", "region", "us-east", "shard", "default", "stage", "main", "tier", "sv", "type", "web", + )), + }, + dedupLabels: map[string]struct{}{"replica": {}}, + }, } { t.Run("", func(t *testing.T) { sortWithoutLabels(tcase.input, tcase.dedupLabels)