diff --git a/pkg/logql/range_vector.go b/pkg/logql/range_vector.go index dc6ad42d80246..6357365d3f31a 100644 --- a/pkg/logql/range_vector.go +++ b/pkg/logql/range_vector.go @@ -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 diff --git a/pkg/logql/range_vector_test.go b/pkg/logql/range_vector_test.go index 24f29b796d2c6..bfa23680812eb 100644 --- a/pkg/logql/range_vector_test.go +++ b/pkg/logql/range_vector_test.go @@ -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{ @@ -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(): + } +}