Skip to content

Commit

Permalink
Fixes tightloop that could happen in the engine with LogQL parser.
Browse files Browse the repository at this point in the history
I've also added a test to prove the issue was happening and now is fixed.

Fixes #3275
Fixes #3264
Fixes #3020

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
  • Loading branch information
cyriltovena committed Feb 17, 2021
1 parent 3ff0881 commit 2c1c491
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/logql/range_vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (r *rangeVectorIterator) load(start, end int64) {
var err error
metric, err = promql_parser.ParseMetric(lbs)
if err != nil {
_ = r.iter.Next()
continue
}
r.metrics[lbs] = metric
Expand Down
27 changes: 25 additions & 2 deletions pkg/logql/range_vector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ var samples = []logproto.Sample{
{Timestamp: time.Unix(100, 1).UnixNano(), Hash: 11, Value: 1.},
}

var labelFoo, _ = promql_parser.ParseMetric("{app=\"foo\"}")
var labelBar, _ = promql_parser.ParseMetric("{app=\"bar\"}")
var (
labelFoo, _ = promql_parser.ParseMetric("{app=\"foo\"}")
labelBar, _ = promql_parser.ParseMetric("{app=\"bar\"}")
)

func newSampleIterator() iter.SampleIterator {
return iter.NewHeapSampleIterator(context.Background(), []iter.SampleIterator{
Expand Down Expand Up @@ -163,3 +165,24 @@ func Test_RangeVectorIterator(t *testing.T) {
})
}
}

func Test_RangeVectorIteratorBadLabels(t *testing.T) {
badIterator := iter.NewPeekingSampleIterator(
iter.NewSeriesIterator(logproto.Series{
Labels: "{badlabels=}",
Samples: samples,
}))
it := newRangeVectorIterator(badIterator, (30 * time.Second).Nanoseconds(),
(30 * time.Second).Nanoseconds(), time.Unix(10, 0).UnixNano(), time.Unix(100, 0).UnixNano())
ctx, cancel := context.WithCancel(context.Background())
go func() {
defer cancel()
for it.Next() {
}
}()
select {
case <-time.After(1 * time.Second):
require.Fail(t, "goroutine took too long")
case <-ctx.Done():
}
}

0 comments on commit 2c1c491

Please sign in to comment.