mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
Allow peeking back further in buffer.
This commit is contained in:
parent
10d8b6b633
commit
c02c25d5ba
|
@ -752,7 +752,7 @@ func (ev *evaluator) vectorSelector(node *VectorSelector) Vector {
|
|||
t, v := it.Values()
|
||||
|
||||
if !ok || t > refTime {
|
||||
t, v, ok = it.PeekBack()
|
||||
t, v, ok = it.PeekBack(1)
|
||||
if !ok || t < refTime-durationMilliseconds(StalenessDelta) {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -36,10 +36,10 @@ func NewBuffer(it SeriesIterator, delta int64) *BufferedSeriesIterator {
|
|||
return bit
|
||||
}
|
||||
|
||||
// PeekBack returns the previous element of the iterator. If there is none buffered,
|
||||
// PeekBack returns the nth previous element of the iterator. If there is none buffered,
|
||||
// ok is false.
|
||||
func (b *BufferedSeriesIterator) PeekBack() (t int64, v float64, ok bool) {
|
||||
return b.buf.last()
|
||||
func (b *BufferedSeriesIterator) PeekBack(n int) (t int64, v float64, ok bool) {
|
||||
return b.buf.nthLast(n)
|
||||
}
|
||||
|
||||
// Buffer returns an iterator over the buffered data.
|
||||
|
@ -189,13 +189,13 @@ func (r *sampleRing) add(t int64, v float64) {
|
|||
}
|
||||
}
|
||||
|
||||
// last returns the most recent element added to the ring.
|
||||
func (r *sampleRing) last() (int64, float64, bool) {
|
||||
if r.l == 0 {
|
||||
// nthLast returns the nth most recent element added to the ring.
|
||||
func (r *sampleRing) nthLast(n int) (int64, float64, bool) {
|
||||
if n > r.l {
|
||||
return 0, 0, false
|
||||
}
|
||||
s := r.buf[r.i]
|
||||
return s.t, s.v, true
|
||||
t, v := r.at(r.l - n)
|
||||
return t, v, true
|
||||
}
|
||||
|
||||
func (r *sampleRing) samples() []sample {
|
||||
|
|
|
@ -94,7 +94,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
|
|||
if ok {
|
||||
t, v = it.Values()
|
||||
} else {
|
||||
t, v, ok = it.PeekBack()
|
||||
t, v, ok = it.PeekBack(0)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue