Skip to content

Commit 9ef278a

Browse files
harry671003GiedriusS
authored andcommitted
Try fix acceptance test failures
Signed-off-by: Giedrius Statkevičius <[email protected]>
1 parent e23dde7 commit 9ef278a

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

engine/engine_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,13 @@ avg by (storage_info) (
22382238
start: time.UnixMilli(170000),
22392239
end: time.UnixMilli(170000),
22402240
},
2241+
{
2242+
name: "predict_linear",
2243+
load: `load 1m
2244+
native_histogram {{sum:100 count:100}} {{sum:103 count:103}} {{sum:106 count:106}} {{sum:109 count:109}} {{sum:112 count:112}} {{sum:3 count:3 counter_reset_hint:reset}} {{sum:6 count:6}}+{{sum:3 count:3}}x5`,
2245+
query: `increase(native_histogram[10m:3m])`,
2246+
start: time.UnixMilli(10 * 60 * 1000),
2247+
},
22412248
}
22422249

22432250
disableOptimizerOpts := []bool{true, false}

execution/aggregate/count_values.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import (
1111
"sync"
1212
"time"
1313

14-
"github.com/efficientgo/core/errors"
15-
prommodel "github.com/prometheus/common/model"
16-
"github.com/prometheus/prometheus/model/labels"
17-
1814
"github.com/thanos-io/promql-engine/execution/model"
1915
"github.com/thanos-io/promql-engine/execution/telemetry"
2016
"github.com/thanos-io/promql-engine/query"
17+
18+
"github.com/efficientgo/core/errors"
19+
prommodel "github.com/prometheus/common/model"
20+
"github.com/prometheus/prometheus/model/labels"
2121
)
2222

2323
type countValuesOperator struct {

execution/scan/subquery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func (o *subqueryOperator) initSeries(ctx context.Context) error {
257257
o.series = make([]labels.Labels, len(series))
258258
o.buffers = make([]*ringbuffer.GenericRingBuffer, len(series))
259259
for i := range o.buffers {
260-
o.buffers[i] = ringbuffer.New(ctx, 8, o.subQuery.Range.Milliseconds(), o.subQuery.Offset.Milliseconds(), o.call)
260+
o.buffers[i] = ringbuffer.New(ctx, 8, o.subQuery.Range.Milliseconds(), o.subQuery.Offset.Milliseconds(), o.call, true)
261261
}
262262
var b labels.ScratchBuilder
263263
for i, s := range series {

ringbuffer/generic.go

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ type Sample struct {
2121
}
2222

2323
type GenericRingBuffer struct {
24-
ctx context.Context
25-
items []Sample
26-
tail []Sample
24+
ctx context.Context
25+
items []Sample
26+
tail []Sample
27+
subquery bool
2728

2829
currentStep int64
2930
offset int64
@@ -32,18 +33,19 @@ type GenericRingBuffer struct {
3233
call FunctionCall
3334
}
3435

35-
func New(ctx context.Context, size int, selectRange, offset int64, call FunctionCall) *GenericRingBuffer {
36-
return NewWithExtLookback(ctx, size, selectRange, offset, 0, call)
36+
func New(ctx context.Context, size int, selectRange, offset int64, call FunctionCall, subquery bool) *GenericRingBuffer {
37+
return NewWithExtLookback(ctx, size, selectRange, offset, 0, call, subquery)
3738
}
3839

39-
func NewWithExtLookback(ctx context.Context, size int, selectRange, offset, extLookback int64, call FunctionCall) *GenericRingBuffer {
40+
func NewWithExtLookback(ctx context.Context, size int, selectRange, offset, extLookback int64, call FunctionCall, subquery bool) *GenericRingBuffer {
4041
return &GenericRingBuffer{
4142
ctx: ctx,
4243
items: make([]Sample, 0, size),
4344
selectRange: selectRange,
4445
offset: offset,
4546
extLookback: extLookback,
4647
call: call,
48+
subquery: subquery,
4749
}
4850
}
4951

@@ -76,7 +78,29 @@ func (r *GenericRingBuffer) Push(t int64, v Value) {
7678
r.items[n].V.F = v.F
7779
if v.H != nil {
7880
if r.items[n].V.H == nil {
79-
r.items[n].V.H = v.H.Copy()
81+
h := v.H.Copy()
82+
if r.subquery {
83+
// Set any "NotCounterReset" and "CounterReset" hints in native
84+
// histograms to "UnknownCounterReset" because we might
85+
// otherwise miss a counter reset happening in samples not
86+
// returned by the subquery, or we might over-detect counter
87+
// resets if the sample with a counter reset is returned
88+
// multiple times by a high-res subquery. This intentionally
89+
// does not attempt to be clever (like detecting if we are
90+
// really missing underlying samples or returning underlying
91+
// samples multiple times) because subqueries on counters are
92+
// inherently problematic WRT counter reset handling, so we
93+
// cannot really solve the problem for good. We only want to
94+
// avoid problems that happen due to the explicitly set counter
95+
// reset hints and go back to the behavior we already know from
96+
// float samples.
97+
switch h.CounterResetHint {
98+
case histogram.NotCounterReset, histogram.CounterReset:
99+
h.CounterResetHint = histogram.UnknownCounterReset
100+
}
101+
}
102+
r.items[n].V.H = h
103+
80104
} else {
81105
v.H.CopyTo(r.items[n].V.H)
82106
}

storage/prometheus/matrix_selector.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ func (o *matrixSelector) newBuffer(ctx context.Context) ringbuffer.Buffer {
287287
}
288288

289289
if o.isExtFunction {
290-
return ringbuffer.NewWithExtLookback(ctx, 8, o.selectRange, o.offset, o.opts.ExtLookbackDelta.Milliseconds()-1, o.call)
290+
return ringbuffer.NewWithExtLookback(ctx, 8, o.selectRange, o.offset, o.opts.ExtLookbackDelta.Milliseconds()-1, o.call, false)
291291
}
292-
return ringbuffer.New(ctx, 8, o.selectRange, o.offset, o.call)
292+
return ringbuffer.New(ctx, 8, o.selectRange, o.offset, o.call, false)
293293

294294
}
295295

0 commit comments

Comments
 (0)