Skip to content

Commit

Permalink
Fix a bug in range vector skipping data. (#2058)
Browse files Browse the repository at this point in the history
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena authored May 8, 2020
1 parent 918ba41 commit fcb4c76
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/logql/range_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ func (r *rangeVectorIterator) popBack(newStart int64) {
// possible improvement: if there is no overlap we can just remove all.
for fp := range r.window {
lastPoint := 0
remove := false
for i, p := range r.window[fp].Points {
if p.T <= newStart {
lastPoint = i
remove = true
continue
}
break
}
r.window[fp].Points = r.window[fp].Points[lastPoint+1:]
if remove {
r.window[fp].Points = r.window[fp].Points[lastPoint+1:]
}
if len(r.window[fp].Points) == 0 {
s := r.window[fp]
delete(r.window, fp)
Expand Down
22 changes: 21 additions & 1 deletion pkg/logql/range_vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func Test_RangeVectorIterator(t *testing.T) {
step int64
expectedVectors []promql.Vector
expectedTs []time.Time
start, end time.Time
}{
{
(5 * time.Second).Nanoseconds(), // no overlap
Expand All @@ -73,6 +74,7 @@ func Test_RangeVectorIterator(t *testing.T) {
},
},
[]time.Time{time.Unix(10, 0), time.Unix(40, 0), time.Unix(70, 0), time.Unix(100, 0)},
time.Unix(10, 0), time.Unix(100, 0),
},
{
(35 * time.Second).Nanoseconds(), // will overlap by 5 sec
Expand All @@ -96,6 +98,7 @@ func Test_RangeVectorIterator(t *testing.T) {
},
},
[]time.Time{time.Unix(10, 0), time.Unix(40, 0), time.Unix(70, 0), time.Unix(100, 0)},
time.Unix(10, 0), time.Unix(100, 0),
},
{
(30 * time.Second).Nanoseconds(), // same range
Expand All @@ -116,6 +119,23 @@ func Test_RangeVectorIterator(t *testing.T) {
},
},
[]time.Time{time.Unix(10, 0), time.Unix(40, 0), time.Unix(70, 0), time.Unix(100, 0)},
time.Unix(10, 0), time.Unix(100, 0),
},
{
(50 * time.Second).Nanoseconds(), // all step are overlaping
(10 * time.Second).Nanoseconds(),
[]promql.Vector{
[]promql.Sample{
{Point: newPoint(time.Unix(110, 0), 2), Metric: labelBar},
{Point: newPoint(time.Unix(110, 0), 2), Metric: labelFoo},
},
[]promql.Sample{
{Point: newPoint(time.Unix(120, 0), 2), Metric: labelBar},
{Point: newPoint(time.Unix(120, 0), 2), Metric: labelFoo},
},
},
[]time.Time{time.Unix(110, 0), time.Unix(120, 0)},
time.Unix(110, 0), time.Unix(120, 0),
},
}

Expand All @@ -124,7 +144,7 @@ func Test_RangeVectorIterator(t *testing.T) {
fmt.Sprintf("logs[%s] - step: %s", time.Duration(tt.selRange), time.Duration(tt.step)),
func(t *testing.T) {
it := newRangeVectorIterator(newEntryIterator(), tt.selRange,
tt.step, time.Unix(10, 0).UnixNano(), time.Unix(100, 0).UnixNano())
tt.step, tt.start.UnixNano(), tt.end.UnixNano())

i := 0
for it.Next() {
Expand Down

0 comments on commit fcb4c76

Please sign in to comment.