Skip to content

Commit 53debe8

Browse files
committed
no assimption
1 parent f1e0a13 commit 53debe8

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

pkg/querier/batch/batch.go

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package batch
22

33
import (
4-
"time"
5-
64
"github.com/cortexproject/cortex/pkg/chunk"
75
"github.com/cortexproject/cortex/pkg/chunk/encoding"
86
promchunk "github.com/cortexproject/cortex/pkg/chunk/encoding"
@@ -44,6 +42,7 @@ type iterator interface {
4442
// AtTime returns the start time of the next batch. Must only be called after
4543
// Seek or Next have returned true.
4644
AtTime() int64
45+
MaxTime() int64
4746

4847
// Batch returns the current batch. Must only be called after Seek or Next
4948
// have returned true.
@@ -100,31 +99,16 @@ func (a *iteratorAdapter) Seek(t int64) bool {
10099
a.curr.Index++
101100
}
102101
return true
103-
} else {
104-
// In this case, t is after the end of the current batch.
105-
// Here we assume that the scrape interval is 30s and try to calculate how many samples ahead we are trying to seek.
106-
// If the number of samples is < 60 (each chunk has 120 samples) we assume that the samples belongs to the current
107-
// chunk and forward the iterator to the right point - this is more efficient than the seek call.
108-
// See: https://github.com/prometheus/prometheus/blob/211ae4f1f0a2cdaae09c4c52735f75345c1817c6/tsdb/head_append.go#L1337
109-
scrapeInterval := 30 * time.Second
110-
111-
// We have 2 samples we can estimate the scrape interval
112-
if a.curr.Length > 1 {
113-
scrapeInterval = time.Duration(a.curr.Timestamps[1]-a.curr.Timestamps[0]) * time.Millisecond
114-
}
115-
116-
approxNumberOfSamples := model.Time(t).Sub(model.Time(a.curr.Timestamps[a.curr.Length-1])) / scrapeInterval
117-
if approxNumberOfSamples < 60 {
118-
for a.underlying.Next(promchunk.BatchSize) {
119-
a.curr = a.underlying.Batch()
120-
if t <= a.curr.Timestamps[a.curr.Length-1] {
121-
//In this case, some timestamp between current sample and end of batch can fulfill
122-
//the seek. Let's find it.
123-
for a.curr.Index < a.curr.Length && t > a.curr.Timestamps[a.curr.Index] {
124-
a.curr.Index++
125-
}
126-
return true
102+
} else if t <= a.underlying.MaxTime() {
103+
for a.underlying.Next(promchunk.BatchSize) {
104+
a.curr = a.underlying.Batch()
105+
if t <= a.curr.Timestamps[a.curr.Length-1] {
106+
//In this case, some timestamp between current sample and end of batch can fulfill
107+
//the seek. Let's find it.
108+
for a.curr.Index < a.curr.Length && t > a.curr.Timestamps[a.curr.Index] {
109+
a.curr.Index++
127110
}
111+
return true
128112
}
129113
}
130114
}

pkg/querier/batch/chunk.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ func (i *chunkIterator) reset(chunk GenericChunk) {
2121
i.batch.Index = 0
2222
}
2323

24+
func (i *chunkIterator) MaxTime() int64 {
25+
return i.chunk.MaxTime
26+
}
27+
2428
// Seek advances the iterator forward to the value at or after
2529
// the given timestamp.
2630
func (i *chunkIterator) Seek(t int64, size int) bool {

pkg/querier/batch/merge.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ type mergeIterator struct {
2121
currErr error
2222
}
2323

24+
func (c *mergeIterator) MaxTime() int64 {
25+
return c.h[0].MaxTime()
26+
}
27+
2428
func newMergeIterator(cs []GenericChunk) *mergeIterator {
2529
css := partitionChunks(cs)
2630
its := make([]*nonOverlappingIterator, 0, len(css))
@@ -128,6 +132,10 @@ func (c *mergeIterator) AtTime() int64 {
128132
return c.batches[0].Timestamps[0]
129133
}
130134

135+
func (c *mergeIterator) MaxTIme() int64 {
136+
return c.h[0].AtTime()
137+
}
138+
131139
func (c *mergeIterator) Batch() promchunk.Batch {
132140
return c.batches[0]
133141
}

pkg/querier/batch/non_overlapping.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func (it *nonOverlappingIterator) Seek(t int64, size int) bool {
3232
}
3333
}
3434

35+
func (it *nonOverlappingIterator) MaxTime() int64 {
36+
return it.iter.MaxTime()
37+
}
38+
3539
func (it *nonOverlappingIterator) Next(size int) bool {
3640
for {
3741
if it.iter.Next(size) {

0 commit comments

Comments
 (0)