mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Fix #59
Mutating the chunks can change their length. Hence referencing using previous indices can cause panics. Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
parent
6178de9acc
commit
6169c33fb8
|
@ -400,13 +400,14 @@ func (s *populatedChunkSeries) Next() bool {
|
|||
for s.set.Next() {
|
||||
lset, chks := s.set.At()
|
||||
|
||||
from := 0
|
||||
for i, c := range chks {
|
||||
if c.MaxTime < s.mint {
|
||||
chks = chks[1:]
|
||||
from = i
|
||||
continue
|
||||
}
|
||||
if c.MinTime > s.maxt {
|
||||
chks = chks[:i]
|
||||
chks = chks[from+1 : i]
|
||||
break
|
||||
}
|
||||
c.Chunk, s.err = s.chunks.Chunk(c.Ref)
|
||||
|
|
|
@ -838,3 +838,57 @@ func TestSeriesIterator(t *testing.T) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
func TestPopulatedCSReturnsValidChunkSlice(t *testing.T) {
|
||||
lbls := []labels.Labels{labels.New(labels.Label{"a", "b"})}
|
||||
chunkMetas := [][]*ChunkMeta{
|
||||
{
|
||||
{MinTime: 1, MaxTime: 2, Ref: 1},
|
||||
{MinTime: 3, MaxTime: 4, Ref: 2},
|
||||
{MinTime: 10, MaxTime: 12, Ref: 3},
|
||||
},
|
||||
}
|
||||
|
||||
cr := mockChunkReader(
|
||||
map[uint64]chunks.Chunk{
|
||||
1: chunks.NewXORChunk(),
|
||||
2: chunks.NewXORChunk(),
|
||||
3: chunks.NewXORChunk(),
|
||||
},
|
||||
)
|
||||
|
||||
m := &mockChunkSeriesSet{l: lbls, cm: chunkMetas, i: -1}
|
||||
p := &populatedChunkSeries{
|
||||
set: m,
|
||||
chunks: cr,
|
||||
|
||||
mint: 6,
|
||||
maxt: 9,
|
||||
}
|
||||
|
||||
require.False(t, p.Next())
|
||||
return
|
||||
}
|
||||
|
||||
type mockChunkSeriesSet struct {
|
||||
l []labels.Labels
|
||||
cm [][]*ChunkMeta
|
||||
|
||||
i int
|
||||
}
|
||||
|
||||
func (m *mockChunkSeriesSet) Next() bool {
|
||||
if len(m.l) != len(m.cm) {
|
||||
return false
|
||||
}
|
||||
m.i++
|
||||
return m.i < len(m.l)
|
||||
}
|
||||
|
||||
func (m *mockChunkSeriesSet) At() (labels.Labels, []*ChunkMeta) {
|
||||
return m.l[m.i], m.cm[m.i]
|
||||
}
|
||||
|
||||
func (m *mockChunkSeriesSet) Err() error {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue