From cc8eb55a225e6951859759075bd99dee73d7cdf0 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 27 Mar 2023 18:03:03 +0000 Subject: [PATCH] tsdb: call StableHash as appropriate labels.Labels.Hash() is not guaranteed to be stable over time. --- tsdb/compact_test.go | 2 +- tsdb/head_test.go | 2 +- tsdb/index/index_test.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tsdb/compact_test.go b/tsdb/compact_test.go index 4db5f3b17..ef62c6966 100644 --- a/tsdb/compact_test.go +++ b/tsdb/compact_test.go @@ -593,7 +593,7 @@ func TestCompaction_CompactWithSplitting(t *testing.T) { ref := p.At() require.NoError(t, idxr.Series(ref, &lbls, nil)) - require.Equal(t, uint64(shardIndex), lbls.Labels().Hash()%shardCount) + require.Equal(t, uint64(shardIndex), labels.StableHash(lbls.Labels())%shardCount) // Collect all symbols used by series. lbls.Labels().Range(func(l labels.Label) { diff --git a/tsdb/head_test.go b/tsdb/head_test.go index 36f498b9e..4571e4db9 100644 --- a/tsdb/head_test.go +++ b/tsdb/head_test.go @@ -2495,7 +2495,7 @@ func TestHeadShardedPostings(t *testing.T) { var lbls labels.ScratchBuilder require.NoError(t, ir.Series(id, &lbls, nil)) - require.Equal(t, shardIndex, lbls.Labels().Hash()%shardCount) + require.Equal(t, shardIndex, labels.StableHash(lbls.Labels())%shardCount) } } } diff --git a/tsdb/index/index_test.go b/tsdb/index/index_test.go index 930c2ba04..64f8674f7 100644 --- a/tsdb/index/index_test.go +++ b/tsdb/index/index_test.go @@ -292,7 +292,7 @@ func TestIndexRW_Postings(t *testing.T) { var lbls labels.ScratchBuilder require.NoError(t, ir.Series(id, &lbls, nil)) - require.Equal(t, shardIndex, lbls.Labels().Hash()%shardCount) + require.Equal(t, shardIndex, labels.StableHash(lbls.Labels())%shardCount) } } })