mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 22:19:40 -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()
|
t, v := it.Values()
|
||||||
|
|
||||||
if !ok || t > refTime {
|
if !ok || t > refTime {
|
||||||
t, v, ok = it.PeekBack()
|
t, v, ok = it.PeekBack(1)
|
||||||
if !ok || t < refTime-durationMilliseconds(StalenessDelta) {
|
if !ok || t < refTime-durationMilliseconds(StalenessDelta) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,10 +36,10 @@ func NewBuffer(it SeriesIterator, delta int64) *BufferedSeriesIterator {
|
||||||
return bit
|
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.
|
// ok is false.
|
||||||
func (b *BufferedSeriesIterator) PeekBack() (t int64, v float64, ok bool) {
|
func (b *BufferedSeriesIterator) PeekBack(n int) (t int64, v float64, ok bool) {
|
||||||
return b.buf.last()
|
return b.buf.nthLast(n)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffer returns an iterator over the buffered data.
|
// 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.
|
// nthLast returns the nth most recent element added to the ring.
|
||||||
func (r *sampleRing) last() (int64, float64, bool) {
|
func (r *sampleRing) nthLast(n int) (int64, float64, bool) {
|
||||||
if r.l == 0 {
|
if n > r.l {
|
||||||
return 0, 0, false
|
return 0, 0, false
|
||||||
}
|
}
|
||||||
s := r.buf[r.i]
|
t, v := r.at(r.l - n)
|
||||||
return s.t, s.v, true
|
return t, v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *sampleRing) samples() []sample {
|
func (r *sampleRing) samples() []sample {
|
||||||
|
|
|
@ -94,7 +94,7 @@ func (h *Handler) federation(w http.ResponseWriter, req *http.Request) {
|
||||||
if ok {
|
if ok {
|
||||||
t, v = it.Values()
|
t, v = it.Values()
|
||||||
} else {
|
} else {
|
||||||
t, v, ok = it.PeekBack()
|
t, v, ok = it.PeekBack(0)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue