diff --git a/promql/engine.go b/promql/engine.go index be7913a813..f1c48f6101 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -1767,7 +1767,7 @@ func (ev *evaluator) matrixIterSlice(it *storage.BufferedSeriesIterator, mint, m } } } - // The seeked sample might also be in the range. + // The sought sample might also be in the range. if ok { if it.ChunkEncoding() == chunkenc.EncHistogram { t, h := it.HistogramValues() diff --git a/promql/value.go b/promql/value.go index 63590042b6..4f52b31990 100644 --- a/promql/value.go +++ b/promql/value.go @@ -87,6 +87,7 @@ type Point struct { } func (p Point) String() string { + // TODO(beorn7): Support Histogram. v := strconv.FormatFloat(p.V, 'f', -1, 64) return fmt.Sprintf("%v @[%v]", v, p.T) } @@ -299,11 +300,9 @@ func (ssi *storageSeriesIterator) At() (t int64, v float64) { return p.T, p.V } -// AtHistogram always returns (0, histogram.Histogram{}) because there is no -// support for histogram values yet. -// TODO(beorn7): Fix that for histogram support in PromQL. func (ssi *storageSeriesIterator) AtHistogram() (int64, histogram.Histogram) { - return 0, histogram.Histogram{} + p := ssi.points[ssi.curr] + return p.T, *p.H } func (ssi *storageSeriesIterator) ChunkEncoding() chunkenc.Encoding { diff --git a/storage/buffer.go b/storage/buffer.go index 45bfe0645c..93cd9da00e 100644 --- a/storage/buffer.go +++ b/storage/buffer.go @@ -230,8 +230,6 @@ func (it *sampleRingIterator) At() (int64, float64) { return it.r.at(it.i) } -// AtHistogram always returns (0, histogram.Histogram{}) because there is no -// support for histogram values yet. func (it *sampleRingIterator) AtHistogram() (int64, histogram.Histogram) { return it.r.atHistogram(it.i) } diff --git a/storage/buffer_test.go b/storage/buffer_test.go index 032c61f078..2d7b3f1e92 100644 --- a/storage/buffer_test.go +++ b/storage/buffer_test.go @@ -216,11 +216,11 @@ func newFakeSeriesIterator(nsamples, step int64) *fakeSeriesIterator { } func (it *fakeSeriesIterator) At() (int64, float64) { - return it.idx * it.step, 123 // value doesn't matter + return it.idx * it.step, 123 // Value doesn't matter. } func (it *fakeSeriesIterator) AtHistogram() (int64, histogram.Histogram) { - return it.idx * it.step, histogram.Histogram{} // value doesn't matter + return it.idx * it.step, histogram.Histogram{} // Value doesn't matter. } func (it *fakeSeriesIterator) ChunkEncoding() chunkenc.Encoding { diff --git a/storage/series.go b/storage/series.go index d597a3b90e..6e5b178df5 100644 --- a/storage/series.go +++ b/storage/series.go @@ -91,10 +91,9 @@ func (it *listSeriesIterator) At() (int64, float64) { return s.T(), s.V() } -// AtHistogram always returns (0, histogram.Histogram{}) because there is no -// support for histogram values yet. func (it *listSeriesIterator) AtHistogram() (int64, histogram.Histogram) { - return 0, histogram.Histogram{} + s := it.samples.Get(it.idx) + return s.T(), *s.H() } func (it *listSeriesIterator) ChunkEncoding() chunkenc.Encoding { diff --git a/tsdb/chunkenc/chunk.go b/tsdb/chunkenc/chunk.go index c5133dc59f..8069b0ecdc 100644 --- a/tsdb/chunkenc/chunk.go +++ b/tsdb/chunkenc/chunk.go @@ -89,6 +89,8 @@ type Appender interface { // Iterator iterates over the samples of a time series, in timestamp-increasing order. type Iterator interface { // Next advances the iterator by one. + // TODO(beorn7): Perhaps this should return if the next value is a float or a histogram + // to make it easier calling the right method (At vs AtHistogram)? Next() bool // Seek advances the iterator forward to the first sample with the timestamp equal or greater than t. // If current sample found by previous `Next` or `Seek` operation already has this property, Seek has no effect. @@ -100,6 +102,7 @@ type Iterator interface { At() (int64, float64) // AtHistogram returns the current timestamp/histogram pair. // Before the iterator has advanced AtHistogram behaviour is unspecified. + // TODO(beorn7): Maybe return *histogram.Histogram? It's a fairly large struct. AtHistogram() (int64, histogram.Histogram) // Err returns the current error. It should be used only after iterator is // exhausted, that is `Next` or `Seek` returns false. diff --git a/tsdb/tsdbutil/buffer.go b/tsdb/tsdbutil/buffer.go index 5dde74835d..5569c00474 100644 --- a/tsdb/tsdbutil/buffer.go +++ b/tsdb/tsdbutil/buffer.go @@ -166,6 +166,7 @@ func (it *sampleRingIterator) At() (int64, float64) { } func (it *sampleRingIterator) AtHistogram() (int64, histogram.Histogram) { + // TODO(beorn7): Add proper histogram support. return 0, histogram.Histogram{} } diff --git a/tsdb/tsdbutil/buffer_test.go b/tsdb/tsdbutil/buffer_test.go index 0401e6c879..8ff8fa0864 100644 --- a/tsdb/tsdbutil/buffer_test.go +++ b/tsdb/tsdbutil/buffer_test.go @@ -153,7 +153,11 @@ func (it *listSeriesIterator) At() (int64, float64) { } func (it *listSeriesIterator) AtHistogram() (int64, histogram.Histogram) { - return 0, histogram.Histogram{} + s := it.list[it.idx] + if s.h == nil { + return s.t, histogram.Histogram{} + } + return s.t, *s.h } func (it *listSeriesIterator) ChunkEncoding() chunkenc.Encoding {