From 2ca4d162360d9aae5f3ad56fef3fbb3b93ec4aa4 Mon Sep 17 00:00:00 2001 From: Charles Korn Date: Mon, 15 Jul 2024 14:09:02 +1000 Subject: [PATCH] storage: add `AtT` method to `MemoizedSeriesIterator` Signed-off-by: Charles Korn --- storage/memoized_iterator.go | 5 +++++ storage/memoized_iterator_test.go | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/storage/memoized_iterator.go b/storage/memoized_iterator.go index 4ab2aa5d7..273b3caa1 100644 --- a/storage/memoized_iterator.go +++ b/storage/memoized_iterator.go @@ -136,6 +136,11 @@ func (b *MemoizedSeriesIterator) AtFloatHistogram() (int64, *histogram.FloatHist return b.it.AtFloatHistogram(nil) } +// AtT returns the timestamp of the current element of the iterator. +func (b *MemoizedSeriesIterator) AtT() int64 { + return b.it.AtT() +} + // Err returns the last encountered error. func (b *MemoizedSeriesIterator) Err() error { return b.it.Err() diff --git a/storage/memoized_iterator_test.go b/storage/memoized_iterator_test.go index d1cd56517..81e517f96 100644 --- a/storage/memoized_iterator_test.go +++ b/storage/memoized_iterator_test.go @@ -29,13 +29,15 @@ func TestMemoizedSeriesIterator(t *testing.T) { sampleEq := func(ets int64, ev float64, efh *histogram.FloatHistogram) { if efh == nil { ts, v := it.At() - require.Equal(t, ets, ts, "timestamp mismatch") - require.Equal(t, ev, v, "value mismatch") + require.Equal(t, ets, ts, "At() timestamp mismatch") + require.Equal(t, ev, v, "At() value mismatch") } else { ts, fh := it.AtFloatHistogram() - require.Equal(t, ets, ts, "timestamp mismatch") - require.Equal(t, efh, fh, "histogram mismatch") + require.Equal(t, ets, ts, "AtFloatHistogram() timestamp mismatch") + require.Equal(t, efh, fh, "AtFloatHistogram() histogram mismatch") } + + require.Equal(t, ets, it.AtT(), "AtT() timestamp mismatch") } prevSampleEq := func(ets int64, ev float64, efh *histogram.FloatHistogram, eok bool) { ts, v, fh, ok := it.PeekPrev()