Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
  • Loading branch information
fpetkovski committed Feb 23, 2024
1 parent 02ebe6a commit 7491896
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 70 deletions.
8 changes: 4 additions & 4 deletions pkg/query/iter.go
Expand Up @@ -355,17 +355,17 @@ func (it *histogramResetDetector) Next() chunkenc.ValueType {
return it.lastValType
}

func (it *histogramResetDetector) AtHistogram() (int64, *histogram.Histogram) {
t, h := it.Iterator.AtHistogram()
func (it *histogramResetDetector) AtHistogram(h *histogram.Histogram) (int64, *histogram.Histogram) {
t, h := it.Iterator.AtHistogram(h)
if !it.histogramRead && it.i != 0 {
h.CounterResetHint = histogram.UnknownCounterReset
}
it.histogramRead = true
return t, h
}

func (it *histogramResetDetector) AtFloatHistogram() (int64, *histogram.FloatHistogram) {
t, fh := it.Iterator.AtFloatHistogram()
func (it *histogramResetDetector) AtFloatHistogram(fh *histogram.FloatHistogram) (int64, *histogram.FloatHistogram) {
t, fh := it.Iterator.AtFloatHistogram(fh)
if !it.histogramRead && it.i != 0 {
fh.CounterResetHint = histogram.UnknownCounterReset
}
Expand Down
74 changes: 74 additions & 0 deletions pkg/query/iter_test.go
@@ -0,0 +1,74 @@
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

package query

import (
"testing"

"github.com/efficientgo/core/testutil"
"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/tsdb/tsdbutil"
)

func TestNativeHistogramDedup(t *testing.T) {
cases := []struct {
samples []sample
tcase string
}{
{
tcase: "unknown counter reset chunk",
samples: []sample{
{t: 10000, h: makeHistWithHint(1, histogram.UnknownCounterReset)},
{t: 20000, h: makeHistWithHint(2, histogram.UnknownCounterReset)},
},
},
{
tcase: "not counter reset chunk",
samples: []sample{
{t: 10000, h: makeHistWithHint(1, histogram.NotCounterReset)},
{t: 20000, h: makeHistWithHint(2, histogram.NotCounterReset)},
},
},
{
tcase: "counter reset chunk",
samples: []sample{
{t: 10000, h: makeHistWithHint(1, histogram.CounterReset)},
{t: 20000, h: makeHistWithHint(2, histogram.NotCounterReset)},
},
},
}

for _, c := range cases {
t.Run(c.tcase, func(t *testing.T) {
// When the first sample is read, the counter reset hint for the second sample
// does not need to be reset.
t.Run("read_first_sample", func(t *testing.T) {
it := newHistogramResetDetector(newMockedSeriesIterator(c.samples))
it.Next()
_, h := it.AtHistogram()

Check failure on line 49 in pkg/query/iter_test.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

not enough arguments in call to it.AtHistogram

Check failure on line 49 in pkg/query/iter_test.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

not enough arguments in call to it.AtHistogram
testutil.Equals(t, c.samples[0].h.CounterResetHint, h.CounterResetHint)

it.Next()
_, h = it.AtHistogram()

Check failure on line 53 in pkg/query/iter_test.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

not enough arguments in call to it.AtHistogram

Check failure on line 53 in pkg/query/iter_test.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

not enough arguments in call to it.AtHistogram
testutil.Equals(t, c.samples[1].h.CounterResetHint, h.CounterResetHint)
})

// When the first sample is not read, the counter reset hint for the second
// sample should be reset.
t.Run("skip_first_sample", func(t *testing.T) {
it := newHistogramResetDetector(newMockedSeriesIterator(c.samples))
it.Next()
it.Next()
_, h := it.AtHistogram()

Check failure on line 63 in pkg/query/iter_test.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

not enough arguments in call to it.AtHistogram

Check failure on line 63 in pkg/query/iter_test.go

View workflow job for this annotation

GitHub Actions / Linters (Static Analysis) for Go

not enough arguments in call to it.AtHistogram
testutil.Equals(t, h.CounterResetHint, histogram.UnknownCounterReset)
})
})
}
}

func makeHistWithHint(i int, hint histogram.CounterResetHint) *histogram.Histogram {
h := tsdbutil.GenerateTestHistogram(i)
h.CounterResetHint = hint
return h
}
144 changes: 78 additions & 66 deletions pkg/query/querier_test.go
Expand Up @@ -41,6 +41,7 @@ import (
type sample struct {
t int64
v float64
h *histogram.Histogram
}

func TestQueryableCreator_MaxResolution(t *testing.T) {
Expand Down Expand Up @@ -74,12 +75,12 @@ func TestQueryableCreator_MaxResolution(t *testing.T) {
func TestQuerier_DownsampledData(t *testing.T) {
testProxy := &testStoreServer{
resps: []*storepb.SeriesResponse{
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "a", "aaa", "bbb"), []sample{{99, 1}, {199, 5}}), // Downsampled chunk from Store.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "b", "bbbb", "eee"), []sample{{99, 3}, {199, 8}}), // Downsampled chunk from Store.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "c", "qwe", "wqeqw"), []sample{{99, 5}, {199, 15}}), // Downsampled chunk from Store.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "c", "htgtreytr", "vbnbv"), []sample{{99, 123}, {199, 15}}), // Downsampled chunk from Store.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "d", "asdsad", "qweqwewq"), []sample{{22, 5}, {44, 8}, {199, 15}}), // Raw chunk from Sidecar.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "d", "asdsad", "qweqwebb"), []sample{{22, 5}, {44, 8}, {199, 15}}), // Raw chunk from Sidecar.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "a", "aaa", "bbb"), []sample{{t: 99, v: 1}, {t: 199, v: 5}}), // Downsampled chunk from Store.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "b", "bbbb", "eee"), []sample{{t: 99, v: 3}, {t: 199, v: 8}}), // Downsampled chunk from Store.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "c", "qwe", "wqeqw"), []sample{{t: 99, v: 5}, {t: 199, v: 15}}), // Downsampled chunk from Store.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "c", "htgtreytr", "vbnbv"), []sample{{t: 99, v: 123}, {t: 199, v: 15}}), // Downsampled chunk from Store.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "d", "asdsad", "qweqwewq"), []sample{{t: 22, v: 5}, {t: 44, v: 8}, {t: 199, v: 15}}), // Raw chunk from Sidecar.
storeSeriesResponse(t, labels.FromStrings("__name__", "a", "zzz", "d", "asdsad", "qweqwebb"), []sample{{t: 22, v: 5}, {t: 44, v: 8}, {t: 199, v: 15}}), // Raw chunk from Sidecar.
},
}

Expand Down Expand Up @@ -444,12 +445,12 @@ func TestQuerier_Select(t *testing.T) {
storeEndpoints: []storepb.StoreServer{
&testStoreServer{
resps: []*storepb.SeriesResponse{
storeSeriesResponse(t, labels.FromStrings("a", "a"), []sample{{0, 0}, {2, 1}, {3, 2}}),
storeSeriesResponse(t, labels.FromStrings("a", "a"), []sample{{t: 0, v: 0}, {t: 2, v: 1}, {t: 3, v: 2}}),
storepb.NewWarnSeriesResponse(errors.New("partial error")),
storeSeriesResponse(t, labels.FromStrings("a", "a"), []sample{{5, 5}, {6, 6}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "a"), []sample{{5, 5}, {6, 66}}),
storeSeriesResponse(t, labels.FromStrings("a", "b"), []sample{{2, 2}, {3, 3}, {4, 4}}, []sample{{1, 1}, {2, 2}, {3, 3}}),
storeSeriesResponse(t, labels.FromStrings("a", "c"), []sample{{100, 1}, {300, 3}, {400, 4}}),
storeSeriesResponse(t, labels.FromStrings("a", "a"), []sample{{t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "a"), []sample{{t: 5, v: 5}, {t: 6, v: 66}}),
storeSeriesResponse(t, labels.FromStrings("a", "b"), []sample{{t: 2, v: 2}, {t: 3, v: 3}, {t: 4, v: 4}}, []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}}),
storeSeriesResponse(t, labels.FromStrings("a", "c"), []sample{{t: 100, v: 1}, {t: 300, v: 3}, {t: 400, v: 4}}),
},
},
},
Expand All @@ -464,21 +465,21 @@ func TestQuerier_Select(t *testing.T) {
expected: []series{
{
lset: labels.FromStrings("a", "a"),
samples: []sample{{2, 1}, {3, 2}, {5, 5}, {6, 66}, {7, 7}},
samples: []sample{{t: 2, v: 1}, {t: 3, v: 2}, {t: 5, v: 5}, {t: 6, v: 66}, {t: 7, v: 7}},
},
{
lset: labels.FromStrings("a", "b"),
samples: []sample{{1, 1}, {2, 2}, {3, 3}, {4, 4}},
samples: []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}, {t: 4, v: 4}},
},
{
lset: labels.FromStrings("a", "c"),
samples: []sample{{100, 1}, {300, 3}},
samples: []sample{{t: 100, v: 1}, {t: 300, v: 3}},
},
},
expectedAfterDedup: []series{{
lset: nil,
// We don't expect correctness here, it's just random non-replica data.
samples: []sample{{1, 1}, {2, 2}, {3, 3}, {5, 5}, {6, 6}, {7, 7}},
samples: []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}, {t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}},
}},
expectedWarning: "partial error",
},
Expand Down Expand Up @@ -632,18 +633,18 @@ func TestQuerier_Select(t *testing.T) {
storeEndpoints: []storepb.StoreServer{
&testStoreServer{
resps: []*storepb.SeriesResponse{
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "w", "1"), []sample{{0, 0}, {2, 1}, {3, 2}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "w", "1"), []sample{{5, 5}, {6, 6}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "x", "1"), []sample{{2, 2}, {3, 3}, {4, 4}}, []sample{{1, 1}, {2, 2}, {3, 3}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "x", "1"), []sample{{100, 1}, {300, 3}, {400, 4}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{5, 5}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "w", "1"), []sample{{t: 0, v: 0}, {t: 2, v: 1}, {t: 3, v: 2}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "w", "1"), []sample{{t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "x", "1"), []sample{{t: 2, v: 2}, {t: 3, v: 3}, {t: 4, v: 4}}, []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "x", "1"), []sample{{t: 100, v: 1}, {t: 300, v: 3}, {t: 400, v: 4}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{t: 5, v: 5}, {t: 7, v: 7}}),
},
},
&testStoreServer{
resps: []*storepb.SeriesResponse{
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{2, 1}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{5, 5}, {6, 6}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "x", "2"), []sample{{10, 10}, {30, 30}, {40, 40}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{t: 2, v: 1}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "x", "2"), []sample{{t: 10, v: 10}, {t: 30, v: 30}, {t: 40, v: 40}}),
},
},
},
Expand All @@ -654,36 +655,36 @@ func TestQuerier_Select(t *testing.T) {
expected: []series{
{
lset: labels.FromStrings("a", "1", "r", "1", "w", "1"),
samples: []sample{{2, 1}, {3, 2}, {5, 5}, {6, 6}, {7, 7}},
samples: []sample{{t: 2, v: 1}, {t: 3, v: 2}, {t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}},
},
{
lset: labels.FromStrings("a", "1", "r", "1", "x", "1"),
samples: []sample{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {100, 1}, {300, 3}},
samples: []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}, {t: 4, v: 4}, {t: 100, v: 1}, {t: 300, v: 3}},
},
{
lset: labels.FromStrings("a", "1", "r", "2", "w", "1"),
samples: []sample{{2, 1}, {5, 5}, {6, 6}, {7, 7}},
samples: []sample{{t: 2, v: 1}, {t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}},
},
{
lset: labels.FromStrings("a", "1", "r", "2", "x", "2"),
samples: []sample{{10, 10}, {30, 30}, {40, 40}},
samples: []sample{{t: 10, v: 10}, {t: 30, v: 30}, {t: 40, v: 40}},
},
},
expectedAfterDedup: []series{
{
lset: labels.FromStrings("a", "1", "w", "1"),
// We don't expect correctness here, it's just random non-replica data.
samples: []sample{{2, 1}, {3, 2}, {5, 5}, {6, 6}, {7, 7}},
samples: []sample{{t: 2, v: 1}, {t: 3, v: 2}, {t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}},
},
{
lset: labels.FromStrings("a", "1", "x", "1"),
// We don't expect correctness here, it's just random non-replica data.
samples: []sample{{1, 1}, {2, 2}, {3, 3}, {100, 1}, {300, 3}},
samples: []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}, {t: 100, v: 1}, {t: 300, v: 3}},
},
{
lset: labels.FromStrings("a", "1", "x", "2"),
// We don't expect correctness here, it's just random non-replica data.
samples: []sample{{10, 10}, {30, 30}, {40, 40}},
samples: []sample{{t: 10, v: 10}, {t: 30, v: 30}, {t: 40, v: 40}},
},
},
},
Expand All @@ -692,25 +693,25 @@ func TestQuerier_Select(t *testing.T) {
storeEndpoints: []storepb.StoreServer{
&testStoreServer{
resps: []*storepb.SeriesResponse{
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "w", "1"), []sample{{0, 0}, {2, 1}, {3, 2}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "w", "1"), []sample{{5, 5}, {6, 6}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "x", "1"), []sample{{2, 2}, {3, 3}, {4, 4}}, []sample{{1, 1}, {2, 2}, {3, 3}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "x", "1"), []sample{{100, 1}, {300, 3}, {400, 4}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{5, 5}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "w", "1"), []sample{{t: 0, v: 0}, {t: 2, v: 1}, {t: 3, v: 2}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "w", "1"), []sample{{t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "x", "1"), []sample{{t: 2, v: 2}, {t: 3, v: 3}, {t: 4, v: 4}}, []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "1", "x", "1"), []sample{{t: 100, v: 1}, {t: 300, v: 3}, {t: 400, v: 4}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{t: 5, v: 5}, {t: 7, v: 7}}),
},
respsWithoutReplicaLabels: []*storepb.SeriesResponse{
storeSeriesResponse(t, labels.FromStrings("a", "1", "w", "1"), []sample{{5, 5}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "w", "1"), []sample{{0, 0}, {2, 1}, {3, 2}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "w", "1"), []sample{{5, 5}, {6, 6}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "x", "1"), []sample{{2, 2}, {3, 3}, {4, 4}}, []sample{{1, 1}, {2, 2}, {3, 3}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "x", "1"), []sample{{100, 1}, {300, 3}, {400, 4}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "w", "1"), []sample{{t: 5, v: 5}, {t: 7, v: 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "w", "1"), []sample{{t: 0, v: 0}, {t: 2, v: 1}, {t: 3, v: 2}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "w", "1"), []sample{{t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "x", "1"), []sample{{t: 2, v: 2}, {t: 3, v: 3}, {t: 4, v: 4}}, []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "x", "1"), []sample{{t: 100, v: 1}, {t: 300, v: 3}, {t: 400, v: 4}}),
},
},
&testStoreServer{
resps: []*storepb.SeriesResponse{
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{2, 1}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{5, 5}, {6, 6}, {7, 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "x", "2"), []sample{{10, 10}, {30, 30}, {40, 40}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{t: 2, v: 1}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "w", "1"), []sample{{t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}}),
storeSeriesResponse(t, labels.FromStrings("a", "1", "r", "2", "x", "2"), []sample{{t: 10, v: 10}, {t: 30, v: 30}, {t: 40, v: 40}}),
},
},
},
Expand All @@ -721,36 +722,36 @@ func TestQuerier_Select(t *testing.T) {
expected: []series{
{
lset: labels.FromStrings("a", "1", "r", "1", "w", "1"),
samples: []sample{{2, 1}, {3, 2}, {5, 5}, {6, 6}, {7, 7}},
samples: []sample{{t: 2, v: 1}, {t: 3, v: 2}, {t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}},
},
{
lset: labels.FromStrings("a", "1", "r", "1", "x", "1"),
samples: []sample{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {100, 1}, {300, 3}},
samples: []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}, {t: 4, v: 4}, {t: 100, v: 1}, {t: 300, v: 3}},
},
{
lset: labels.FromStrings("a", "1", "r", "2", "w", "1"),
samples: []sample{{2, 1}, {5, 5}, {6, 6}, {7, 7}},
samples: []sample{{t: 2, v: 1}, {t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}},
},
{
lset: labels.FromStrings("a", "1", "r", "2", "x", "2"),
samples: []sample{{10, 10}, {30, 30}, {40, 40}},
samples: []sample{{t: 10, v: 10}, {t: 30, v: 30}, {t: 40, v: 40}},
},
},
expectedAfterDedup: []series{
{
lset: labels.FromStrings("a", "1", "w", "1"),
// We don't expect correctness here, it's just random non-replica data.
samples: []sample{{2, 1}, {3, 2}, {5, 5}, {6, 6}, {7, 7}},
samples: []sample{{t: 2, v: 1}, {t: 3, v: 2}, {t: 5, v: 5}, {t: 6, v: 6}, {t: 7, v: 7}},
},
{
lset: labels.FromStrings("a", "1", "x", "1"),
// We don't expect correctness here, it's just random non-replica data.
samples: []sample{{1, 1}, {2, 2}, {3, 3}, {100, 1}, {300, 3}},
samples: []sample{{t: 1, v: 1}, {t: 2, v: 2}, {t: 3, v: 3}, {t: 100, v: 1}, {t: 300, v: 3}},
},
{
lset: labels.FromStrings("a", "1", "x", "2"),
// We don't expect correctness here, it's just random non-replica data.
samples: []sample{{10, 10}, {30, 30}, {40, 40}},
samples: []sample{{t: 10, v: 10}, {t: 30, v: 30}, {t: 40, v: 40}},
},
},
},
Expand Down Expand Up @@ -1019,11 +1020,13 @@ func (s *mockedSeriesIterator) Seek(t int64) chunkenc.ValueType {
return s.samples[n].t >= t
})

if s.cur < len(s.samples) {
return chunkenc.ValFloat
if s.cur >= len(s.samples) {
return chunkenc.ValNone
}

return chunkenc.ValNone
if s.samples[s.cur].h != nil {
return chunkenc.ValHistogram
}
return chunkenc.ValFloat
}

func (s *mockedSeriesIterator) At() (t int64, v float64) {
Expand All @@ -1033,7 +1036,8 @@ func (s *mockedSeriesIterator) At() (t int64, v float64) {

// TODO(rabenhorst): Needs to be implemented for native histogram support.
func (s *mockedSeriesIterator) AtHistogram(*histogram.Histogram) (int64, *histogram.Histogram) {
panic("not implemented")
sample := s.samples[s.cur]
return sample.t, sample.h
}

func (s *mockedSeriesIterator) AtFloatHistogram(*histogram.FloatHistogram) (int64, *histogram.FloatHistogram) {
Expand All @@ -1046,11 +1050,13 @@ func (s *mockedSeriesIterator) AtT() int64 {

func (s *mockedSeriesIterator) Next() chunkenc.ValueType {
s.cur++
if s.cur < len(s.samples) {
return chunkenc.ValFloat
if s.cur >= len(s.samples) {
return chunkenc.ValNone
}

return chunkenc.ValNone
if s.samples[s.cur].h != nil {
return chunkenc.ValHistogram
}
return chunkenc.ValFloat
}

func (s *mockedSeriesIterator) Err() error { return nil }
Expand Down Expand Up @@ -1204,14 +1210,20 @@ func TestQuerierWithDedupUnderstoodByPromQL_Rate(t *testing.T) {
const hackyStaleMarker = float64(-99999999)

func expandSeries(t testing.TB, it chunkenc.Iterator) (res []sample) {
for it.Next() != chunkenc.ValNone {
t, v := it.At()
// Nan != Nan, so substitute for another value.
// This is required for testutil.Equals to work deterministically.
if math.IsNaN(v) {
v = hackyStaleMarker
for valType := it.Next(); valType != chunkenc.ValNone; valType = it.Next() {
switch valType {
case chunkenc.ValFloat:
t, v := it.At()
// Nan != Nan, so substitute for another value.
// This is required for testutil.Equals to work deterministically.
if math.IsNaN(v) {
v = hackyStaleMarker
}
res = append(res, sample{t: t, v: v})
case chunkenc.ValHistogram:
t, h := it.AtHistogram(nil)
res = append(res, sample{t: t, h: h})
}
res = append(res, sample{t, v})
}
testutil.Ok(t, it.Err())
return res
Expand Down

0 comments on commit 7491896

Please sign in to comment.