mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
Modify tests to check for mint, maxt
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
parent
b60c2068bc
commit
239f8b9eb5
|
@ -582,10 +582,15 @@ func (it *chunkSeriesIterator) inBounds(t int64) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
|
func (it *chunkSeriesIterator) Seek(t int64) (ok bool) {
|
||||||
if t >= it.maxt || t <= it.mint {
|
if t > it.maxt {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Seek to the first valid value after t.
|
||||||
|
if t < it.mint {
|
||||||
|
t = it.mint
|
||||||
|
}
|
||||||
|
|
||||||
// Only do binary search forward to stay in line with other iterators
|
// Only do binary search forward to stay in line with other iterators
|
||||||
// that can only move forward.
|
// that can only move forward.
|
||||||
x := sort.Search(len(it.chunks[it.i:]), func(i int) bool { return it.chunks[i].MinTime >= t })
|
x := sort.Search(len(it.chunks[it.i:]), func(i int) bool { return it.chunks[i].MinTime >= t })
|
||||||
|
|
166
querier_test.go
166
querier_test.go
|
@ -532,6 +532,8 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
itcases := []struct {
|
itcases := []struct {
|
||||||
a, b, c []sample
|
a, b, c []sample
|
||||||
exp []sample
|
exp []sample
|
||||||
|
|
||||||
|
mint, maxt int64
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
a: []sample{},
|
a: []sample{},
|
||||||
|
@ -539,77 +541,56 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
c: []sample{},
|
c: []sample{},
|
||||||
|
|
||||||
exp: []sample{},
|
exp: []sample{},
|
||||||
|
|
||||||
|
mint: math.MinInt64,
|
||||||
|
maxt: math.MaxInt64,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
a: []sample{
|
a: []sample{
|
||||||
{1, 2},
|
{1, 2}, {2, 3}, {3, 5}, {6, 1},
|
||||||
{2, 3},
|
|
||||||
{3, 5},
|
|
||||||
{6, 1},
|
|
||||||
},
|
},
|
||||||
b: []sample{},
|
b: []sample{},
|
||||||
c: []sample{
|
c: []sample{
|
||||||
{7, 89},
|
{7, 89}, {9, 8},
|
||||||
{9, 8},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
exp: []sample{
|
exp: []sample{
|
||||||
{1, 2},
|
{1, 2}, {2, 3}, {3, 5}, {6, 1}, {7, 89}, {9, 8},
|
||||||
{2, 3},
|
|
||||||
{3, 5},
|
|
||||||
{6, 1},
|
|
||||||
{7, 89},
|
|
||||||
{9, 8},
|
|
||||||
},
|
},
|
||||||
|
mint: math.MinInt64,
|
||||||
|
maxt: math.MaxInt64,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
a: []sample{},
|
a: []sample{},
|
||||||
b: []sample{
|
b: []sample{
|
||||||
{1, 2},
|
{1, 2}, {2, 3}, {3, 5}, {6, 1},
|
||||||
{2, 3},
|
|
||||||
{3, 5},
|
|
||||||
{6, 1},
|
|
||||||
},
|
},
|
||||||
c: []sample{
|
c: []sample{
|
||||||
{7, 89},
|
{7, 89}, {9, 8},
|
||||||
{9, 8},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
exp: []sample{
|
exp: []sample{
|
||||||
{1, 2},
|
{1, 2}, {2, 3}, {3, 5}, {6, 1}, {7, 89}, {9, 8},
|
||||||
{2, 3},
|
|
||||||
{3, 5},
|
|
||||||
{6, 1},
|
|
||||||
{7, 89},
|
|
||||||
{9, 8},
|
|
||||||
},
|
},
|
||||||
|
mint: 2,
|
||||||
|
maxt: 8,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
a: []sample{
|
a: []sample{
|
||||||
{1, 2},
|
{1, 2}, {2, 3}, {3, 5}, {6, 1},
|
||||||
{2, 3},
|
|
||||||
{3, 5},
|
|
||||||
{6, 1},
|
|
||||||
},
|
},
|
||||||
b: []sample{
|
b: []sample{
|
||||||
{7, 89},
|
{7, 89}, {9, 8},
|
||||||
{9, 8},
|
|
||||||
},
|
},
|
||||||
c: []sample{
|
c: []sample{
|
||||||
{10, 22},
|
{10, 22}, {203, 3493},
|
||||||
{203, 3493},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
exp: []sample{
|
exp: []sample{
|
||||||
{1, 2},
|
{1, 2}, {2, 3}, {3, 5}, {6, 1}, {7, 89}, {9, 8}, {10, 22}, {203, 3493},
|
||||||
{2, 3},
|
|
||||||
{3, 5},
|
|
||||||
{6, 1},
|
|
||||||
{7, 89},
|
|
||||||
{9, 8},
|
|
||||||
{10, 22},
|
|
||||||
{203, 3493},
|
|
||||||
},
|
},
|
||||||
|
mint: 6,
|
||||||
|
maxt: 10,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,6 +600,8 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
seek int64
|
seek int64
|
||||||
success bool
|
success bool
|
||||||
exp []sample
|
exp []sample
|
||||||
|
|
||||||
|
mint, maxt int64
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
a: []sample{},
|
a: []sample{},
|
||||||
|
@ -635,34 +618,31 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
},
|
},
|
||||||
b: []sample{},
|
b: []sample{},
|
||||||
c: []sample{
|
c: []sample{
|
||||||
{7, 89},
|
{7, 89}, {9, 8},
|
||||||
{9, 8},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
seek: 10,
|
seek: 10,
|
||||||
success: false,
|
success: false,
|
||||||
exp: nil,
|
exp: nil,
|
||||||
|
mint: math.MinInt64,
|
||||||
|
maxt: math.MaxInt64,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
a: []sample{},
|
a: []sample{},
|
||||||
b: []sample{
|
b: []sample{
|
||||||
{1, 2},
|
{1, 2}, {3, 5}, {6, 1},
|
||||||
{3, 5},
|
|
||||||
{6, 1},
|
|
||||||
},
|
},
|
||||||
c: []sample{
|
c: []sample{
|
||||||
{7, 89},
|
{7, 89}, {9, 8},
|
||||||
{9, 8},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
seek: 2,
|
seek: 2,
|
||||||
success: true,
|
success: true,
|
||||||
exp: []sample{
|
exp: []sample{
|
||||||
{3, 5},
|
{3, 5}, {6, 1}, {7, 89}, {9, 8},
|
||||||
{6, 1},
|
|
||||||
{7, 89},
|
|
||||||
{9, 8},
|
|
||||||
},
|
},
|
||||||
|
mint: 5,
|
||||||
|
maxt: 8,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
a: []sample{
|
a: []sample{
|
||||||
|
@ -672,16 +652,16 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
{9, 8},
|
{9, 8},
|
||||||
},
|
},
|
||||||
c: []sample{
|
c: []sample{
|
||||||
{10, 22},
|
{10, 22}, {203, 3493},
|
||||||
{203, 3493},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
seek: 10,
|
seek: 10,
|
||||||
success: true,
|
success: true,
|
||||||
exp: []sample{
|
exp: []sample{
|
||||||
{10, 22},
|
{10, 22}, {203, 3493},
|
||||||
{203, 3493},
|
|
||||||
},
|
},
|
||||||
|
mint: 10,
|
||||||
|
maxt: 203,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
a: []sample{
|
a: []sample{
|
||||||
|
@ -691,8 +671,7 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
{9, 8},
|
{9, 8},
|
||||||
},
|
},
|
||||||
c: []sample{
|
c: []sample{
|
||||||
{10, 22},
|
{10, 22}, {203, 3493},
|
||||||
{203, 3493},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
seek: 203,
|
seek: 203,
|
||||||
|
@ -700,6 +679,8 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
exp: []sample{
|
exp: []sample{
|
||||||
{203, 3493},
|
{203, 3493},
|
||||||
},
|
},
|
||||||
|
mint: 7,
|
||||||
|
maxt: 203,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -710,8 +691,15 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
chunkFromSamples(tc.b),
|
chunkFromSamples(tc.b),
|
||||||
chunkFromSamples(tc.c),
|
chunkFromSamples(tc.c),
|
||||||
}
|
}
|
||||||
res := newChunkSeriesIterator(chkMetas, math.MinInt64, math.MaxInt64)
|
res := newChunkSeriesIterator(chkMetas, tc.mint, tc.maxt)
|
||||||
exp := newListSeriesIterator(tc.exp)
|
|
||||||
|
smplValid := make([]sample, 0)
|
||||||
|
for _, s := range tc.exp {
|
||||||
|
if s.t >= tc.mint && s.t <= tc.maxt {
|
||||||
|
smplValid = append(smplValid, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exp := newListSeriesIterator(smplValid)
|
||||||
|
|
||||||
smplExp, errExp := expandSeriesIterator(exp)
|
smplExp, errExp := expandSeriesIterator(exp)
|
||||||
smplRes, errRes := expandSeriesIterator(res)
|
smplRes, errRes := expandSeriesIterator(res)
|
||||||
|
@ -721,14 +709,68 @@ func TestSeriesIterator(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Seek", func(t *testing.T) {
|
t.Run("Seek", func(t *testing.T) {
|
||||||
for _, tc := range seekcases {
|
extra := []struct {
|
||||||
|
a, b, c []sample
|
||||||
|
|
||||||
|
seek int64
|
||||||
|
success bool
|
||||||
|
exp []sample
|
||||||
|
|
||||||
|
mint, maxt int64
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
a: []sample{
|
||||||
|
{6, 1},
|
||||||
|
},
|
||||||
|
b: []sample{
|
||||||
|
{9, 8},
|
||||||
|
},
|
||||||
|
c: []sample{
|
||||||
|
{10, 22}, {203, 3493},
|
||||||
|
},
|
||||||
|
|
||||||
|
seek: 203,
|
||||||
|
success: false,
|
||||||
|
exp: nil,
|
||||||
|
mint: 2,
|
||||||
|
maxt: 202,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
a: []sample{
|
||||||
|
{6, 1},
|
||||||
|
},
|
||||||
|
b: []sample{
|
||||||
|
{9, 8},
|
||||||
|
},
|
||||||
|
c: []sample{
|
||||||
|
{10, 22}, {203, 3493},
|
||||||
|
},
|
||||||
|
|
||||||
|
seek: 5,
|
||||||
|
success: true,
|
||||||
|
exp: []sample{{10, 22}},
|
||||||
|
mint: 10,
|
||||||
|
maxt: 202,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
seekcases2 := append(seekcases, extra...)
|
||||||
|
|
||||||
|
for _, tc := range seekcases2 {
|
||||||
chkMetas := []*ChunkMeta{
|
chkMetas := []*ChunkMeta{
|
||||||
chunkFromSamples(tc.a),
|
chunkFromSamples(tc.a),
|
||||||
chunkFromSamples(tc.b),
|
chunkFromSamples(tc.b),
|
||||||
chunkFromSamples(tc.c),
|
chunkFromSamples(tc.c),
|
||||||
}
|
}
|
||||||
res := newChunkSeriesIterator(chkMetas, math.MinInt64, math.MaxInt64)
|
res := newChunkSeriesIterator(chkMetas, tc.mint, tc.maxt)
|
||||||
exp := newListSeriesIterator(tc.exp)
|
|
||||||
|
smplValid := make([]sample, 0)
|
||||||
|
for _, s := range tc.exp {
|
||||||
|
if s.t >= tc.mint && s.t <= tc.maxt {
|
||||||
|
smplValid = append(smplValid, s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exp := newListSeriesIterator(smplValid)
|
||||||
|
|
||||||
require.Equal(t, tc.success, res.Seek(tc.seek))
|
require.Equal(t, tc.success, res.Seek(tc.seek))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue