mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
tsdb/compact_test.go: test mixed typed series with PopulateBlock
Add testcase and update test so that it can test native histograms as well. Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
This commit is contained in:
parent
27abf09e7f
commit
4296ecbd14
|
@ -38,6 +38,7 @@ import (
|
|||
"github.com/prometheus/prometheus/tsdb/chunks"
|
||||
"github.com/prometheus/prometheus/tsdb/fileutil"
|
||||
"github.com/prometheus/prometheus/tsdb/tombstones"
|
||||
"github.com/prometheus/prometheus/tsdb/tsdbutil"
|
||||
"github.com/prometheus/prometheus/tsdb/wlog"
|
||||
)
|
||||
|
||||
|
@ -933,6 +934,31 @@ func TestCompaction_populateBlock(t *testing.T) {
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Populate from mixed type series and expect sample inside the interval only", // regression test for populateWithDelChunkSeriesIterator failing to set minTime on chunks
|
||||
compactMinTime: 1,
|
||||
compactMaxTime: 11,
|
||||
inputSeriesSamples: [][]seriesSamples{
|
||||
{
|
||||
{
|
||||
lset: map[string]string{"a": "1"},
|
||||
chunks: [][]sample{
|
||||
{{t: 0, h: tsdbutil.GenerateTestHistogram(0)}, {t: 1, h: tsdbutil.GenerateTestHistogram(1)}},
|
||||
{{t: 10, f: 1}, {t: 11, f: 2}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expSeriesSamples: []seriesSamples{
|
||||
{
|
||||
lset: map[string]string{"a": "1"},
|
||||
chunks: [][]sample{
|
||||
{{t: 1, h: tsdbutil.GenerateTestHistogram(1)}},
|
||||
{{t: 10, f: 1}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.title, func(t *testing.T) {
|
||||
blocks := make([]BlockReader, 0, len(tc.inputSeriesSamples))
|
||||
|
@ -974,12 +1000,23 @@ func TestCompaction_populateBlock(t *testing.T) {
|
|||
firstTs int64 = math.MaxInt64
|
||||
s sample
|
||||
)
|
||||
for iter.Next() == chunkenc.ValFloat {
|
||||
for vt := iter.Next(); vt != chunkenc.ValNone; vt = iter.Next() {
|
||||
switch vt {
|
||||
case chunkenc.ValFloat:
|
||||
s.t, s.f = iter.At()
|
||||
samples = append(samples, s)
|
||||
case chunkenc.ValHistogram:
|
||||
s.t, s.h = iter.AtHistogram()
|
||||
samples = append(samples, s)
|
||||
case chunkenc.ValFloatHistogram:
|
||||
s.t, s.fh = iter.AtFloatHistogram()
|
||||
samples = append(samples, s)
|
||||
default:
|
||||
require.Fail(t, "unexpected value type")
|
||||
}
|
||||
if firstTs == math.MaxInt64 {
|
||||
firstTs = s.t
|
||||
}
|
||||
samples = append(samples, s)
|
||||
}
|
||||
|
||||
// Check if chunk has correct min, max times.
|
||||
|
|
|
@ -133,12 +133,35 @@ func createIdxChkReaders(t *testing.T, tc []seriesSamples) (IndexReader, ChunkRe
|
|||
Ref: chunkRef,
|
||||
})
|
||||
|
||||
switch {
|
||||
case chk[0].fh != nil:
|
||||
chunk := chunkenc.NewFloatHistogramChunk()
|
||||
app, _ := chunk.Appender()
|
||||
for _, smpl := range chk {
|
||||
require.NotNil(t, smpl.fh, "chunk can only contain one type of sample")
|
||||
_, _, _, err := app.AppendFloatHistogram(nil, smpl.t, smpl.fh, true)
|
||||
require.NoError(t, err, "chunk should be appendable")
|
||||
}
|
||||
chkReader[chunkRef] = chunk
|
||||
case chk[0].h != nil:
|
||||
chunk := chunkenc.NewHistogramChunk()
|
||||
app, _ := chunk.Appender()
|
||||
for _, smpl := range chk {
|
||||
require.NotNil(t, smpl.h, "chunk can only contain one type of sample")
|
||||
_, _, _, err := app.AppendHistogram(nil, smpl.t, smpl.h, true)
|
||||
require.NoError(t, err, "chunk should be appendable")
|
||||
}
|
||||
chkReader[chunkRef] = chunk
|
||||
default:
|
||||
chunk := chunkenc.NewXORChunk()
|
||||
app, _ := chunk.Appender()
|
||||
for _, smpl := range chk {
|
||||
require.Nil(t, smpl.h, "chunk can only contain one type of sample")
|
||||
require.Nil(t, smpl.fh, "chunk can only contain one type of sample")
|
||||
app.Append(smpl.t, smpl.f)
|
||||
}
|
||||
chkReader[chunkRef] = chunk
|
||||
}
|
||||
chunkRef++
|
||||
}
|
||||
ls := labels.FromMap(s.lset)
|
||||
|
|
Loading…
Reference in a new issue