Skip to content

Commit

Permalink
fix nil pointer in merge iter Err()
Browse files Browse the repository at this point in the history
Signed-off-by: Yi Jin <[email protected]>
  • Loading branch information
jnyi committed Jun 3, 2024
1 parent 36d6109 commit 359cd32
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 11 additions & 6 deletions pkg/dedup/merge_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,23 @@ func (m *mergedSeriesIterator) At() (t int64, v float64) {
return m.lastIter.At()
}

func (it *mergedSeriesIterator) AtHistogram(h *histogram.Histogram) (int64, *histogram.Histogram) {
return it.lastIter.AtHistogram(h)
func (m *mergedSeriesIterator) AtHistogram(h *histogram.Histogram) (int64, *histogram.Histogram) {
return m.lastIter.AtHistogram(h)
}

func (it *mergedSeriesIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram) {
return it.lastIter.AtFloatHistogram(fh)
func (m *mergedSeriesIterator) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram) {
return m.lastIter.AtFloatHistogram(fh)
}

func (it *mergedSeriesIterator) AtT() int64 {
return it.lastT
func (m *mergedSeriesIterator) AtT() int64 {
return m.lastT
}

// Err All At() funcs should panic if called after Next() or Seek() return ValNone
// Only Err() should return nil even after Next() or Seek() return ValNone

Check failure on line 108 in pkg/dedup/merge_iter.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

Comment should end in a period (godot)
func (m *mergedSeriesIterator) Err() error {
if m.lastIter == nil {
return nil
}
return m.lastIter.Err()
}
11 changes: 11 additions & 0 deletions pkg/dedup/merge_iter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,24 @@
package dedup

import (
"math"
"testing"

"github.com/efficientgo/core/testutil"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb/chunkenc"
)

func TestIteratorEdgeCases(t *testing.T) {
ms := NewMergedSeries(labels.Labels{}, []storage.Series{})
it := ms.Iterator(nil)
testutil.Ok(t, it.Err())
testutil.Equals(t, int64(math.MinInt64), it.AtT())
testutil.Equals(t, chunkenc.ValNone, it.Next())
testutil.Ok(t, it.Err())
}

func TestMergedSeriesIterator(t *testing.T) {
for _, tcase := range []struct {
name string
Expand Down

0 comments on commit 359cd32

Please sign in to comment.