Use storage.ExpandSamples instead of samplesFromIterator

Co-authored by: Fiona Liao <fiona.liao@grafana.com>:

Signed-off-by: Carrie Edwards <edwrdscarrie@gmail.com>
This commit is contained in:
Carrie Edwards 2024-06-25 11:01:50 -07:00
parent 06550883c1
commit 55f53330b2
3 changed files with 10 additions and 26 deletions

View file

@ -5469,7 +5469,9 @@ func testWBLAndMmapReplay(t *testing.T, scenario sampleTypeScenario) {
chk, err := db.head.chunkDiskMapper.Chunk(mc.ref) chk, err := db.head.chunkDiskMapper.Chunk(mc.ref)
require.NoError(t, err) require.NoError(t, err)
it := chk.Iterator(nil) 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) require.NotEmpty(t, s1MmapSamples)

View file

@ -847,7 +847,8 @@ func testOOOHeadChunkReader_Chunk(t *testing.T, scenario sampleTypeScenario) {
require.Nil(t, c) require.Nil(t, c)
it := iterable.Iterator(nil) 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) requireEqualSamples(t, s1.String(), tc.expChunksSamples[i], resultSamples, true)
} }
}) })
@ -1041,7 +1042,8 @@ func testOOOHeadChunkReader_Chunk_ConsistentQueryResponseDespiteOfHeadExpanding(
require.Nil(t, c) require.Nil(t, c)
it := iterable.Iterator(nil) 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) requireEqualSamples(t, s1.String(), tc.expChunksSamples[i], resultSamples, true)
} }
}) })

View file

@ -18,8 +18,6 @@ import (
prom_testutil "github.com/prometheus/client_golang/prometheus/testutil" prom_testutil "github.com/prometheus/client_golang/prometheus/testutil"
"github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/prometheus/prometheus/model/histogram" "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()) require.Equal(t, expectedHist, actualHist, "Sample doesn't match for %s[%d] at ts %d", name, i, expectedSample.T())
} }
default: 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") 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
}