From 55f53330b2118f0ba72d28df8b08a4a0c954f87e Mon Sep 17 00:00:00 2001 From: Carrie Edwards Date: Tue, 25 Jun 2024 11:01:50 -0700 Subject: [PATCH] Use storage.ExpandSamples instead of samplesFromIterator Co-authored by: Fiona Liao : Signed-off-by: Carrie Edwards --- tsdb/db_test.go | 4 +++- tsdb/ooo_head_read_test.go | 6 ++++-- tsdb/testutil.go | 26 +++----------------------- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/tsdb/db_test.go b/tsdb/db_test.go index a9c7dee75..770b1a1b4 100644 --- a/tsdb/db_test.go +++ b/tsdb/db_test.go @@ -5469,7 +5469,9 @@ func testWBLAndMmapReplay(t *testing.T, scenario sampleTypeScenario) { chk, err := db.head.chunkDiskMapper.Chunk(mc.ref) require.NoError(t, err) it := chk.Iterator(nil) - s1MmapSamples = append(s1MmapSamples, samplesFromIterator(t, it)...) + smpls, err := storage.ExpandSamples(it, newSample) + require.NoError(t, err) + s1MmapSamples = append(s1MmapSamples, smpls...) } require.NotEmpty(t, s1MmapSamples) diff --git a/tsdb/ooo_head_read_test.go b/tsdb/ooo_head_read_test.go index ed9a9f88c..938f9a7f7 100644 --- a/tsdb/ooo_head_read_test.go +++ b/tsdb/ooo_head_read_test.go @@ -847,7 +847,8 @@ func testOOOHeadChunkReader_Chunk(t *testing.T, scenario sampleTypeScenario) { require.Nil(t, c) it := iterable.Iterator(nil) - resultSamples := samplesFromIterator(t, it) + resultSamples, err := storage.ExpandSamples(it, nil) + require.NoError(t, err) requireEqualSamples(t, s1.String(), tc.expChunksSamples[i], resultSamples, true) } }) @@ -1041,7 +1042,8 @@ func testOOOHeadChunkReader_Chunk_ConsistentQueryResponseDespiteOfHeadExpanding( require.Nil(t, c) it := iterable.Iterator(nil) - resultSamples := samplesFromIterator(t, it) + resultSamples, err := storage.ExpandSamples(it, nil) + require.NoError(t, err) requireEqualSamples(t, s1.String(), tc.expChunksSamples[i], resultSamples, true) } }) diff --git a/tsdb/testutil.go b/tsdb/testutil.go index 3f7df2d3a..71c54761e 100644 --- a/tsdb/testutil.go +++ b/tsdb/testutil.go @@ -18,8 +18,6 @@ import ( prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" - "github.com/prometheus/prometheus/tsdb/chunkenc" - "github.com/stretchr/testify/require" "github.com/prometheus/prometheus/model/histogram" @@ -156,7 +154,9 @@ func requireEqualSamples(t *testing.T, name string, expected, actual []chunks.Sa require.Equal(t, expectedHist, actualHist, "Sample doesn't match for %s[%d] at ts %d", name, i, expectedSample.T()) } default: - require.Equal(t, expectedSample, actualSample, "Sample doesn't match for %s[%d] at ts %d", name, i, expectedSample.T()) + expectedFloat := expectedSample.F() + actualFloat := actualSample.F() + require.Equal(t, expectedFloat, actualFloat, "Sample doesn't match for %s[%d] at ts %d", name, i, expectedSample.T()) } } } @@ -174,23 +174,3 @@ func counterResetAsString(h histogram.CounterResetHint) string { } panic("Unexpected counter reset type") } - -func samplesFromIterator(t testing.TB, it chunkenc.Iterator) []chunks.Sample { - var samples []chunks.Sample - for typ := it.Next(); typ != chunkenc.ValNone; typ = it.Next() { - switch typ { - case chunkenc.ValFloat: - ts, val := it.At() - samples = append(samples, sample{t: ts, f: val}) - case chunkenc.ValHistogram: - ts, val := it.AtHistogram(nil) - samples = append(samples, sample{t: ts, h: val}) - case chunkenc.ValFloatHistogram: - ts, val := it.AtFloatHistogram(nil) - samples = append(samples, sample{t: ts, fh: val}) - default: - t.Fatalf("unknown sample value type %s", typ) - } - } - return samples -}