Skip to content

Commit 6b76d76

Browse files
storage: make metrics appared ts a value (#638)
We always create this pointer, even if only ext-functions care about it. Having it in the Eval() interface is bad enough but other range vector functions should not have to pay for it at least. Signed-off-by: Michael Hoffmann <mhoffmann@cloudflare.com>
1 parent 6f6040b commit 6b76d76

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

execution/scan/subquery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func (o *subqueryOperator) Next(ctx context.Context) ([]model.StepVector, error)
189189

190190
sv := o.pool.GetStepVector(o.currentStep)
191191
for sampleId, rangeSamples := range o.buffers {
192-
f, h, ok, err := rangeSamples.Eval(ctx, o.params[i], o.params2[i], nil)
192+
f, h, ok, err := rangeSamples.Eval(ctx, o.params[i], o.params2[i], math.MinInt64)
193193
if err != nil {
194194
return nil, err
195195
}

ringbuffer/functions.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type FunctionArgs struct {
2727
StepTime int64
2828
SelectRange int64
2929
Offset int64
30-
MetricAppearedTs *int64
30+
MetricAppearedTs int64
3131

3232
// quantile_over_time and predict_linear use one, so we only use one here.
3333
ScalarPoint float64
@@ -346,10 +346,10 @@ var rangeVectorFuncs = map[string]FunctionCall{
346346
if len(f.Samples) == 0 {
347347
return 0., nil, false, nil
348348
}
349-
if f.MetricAppearedTs == nil {
349+
if f.MetricAppearedTs == math.MinInt64 {
350350
panic("BUG: we got some Samples but metric still hasn't appeared")
351351
}
352-
v, h, err := extendedRate(f.ctx, f.Samples, true, true, f.StepTime, f.SelectRange, f.Offset, *f.MetricAppearedTs)
352+
v, h, err := extendedRate(f.ctx, f.Samples, true, true, f.StepTime, f.SelectRange, f.Offset, f.MetricAppearedTs)
353353
if err != nil {
354354
return 0, nil, false, err
355355
}
@@ -359,10 +359,10 @@ var rangeVectorFuncs = map[string]FunctionCall{
359359
if len(f.Samples) == 0 {
360360
return 0., nil, false, nil
361361
}
362-
if f.MetricAppearedTs == nil {
362+
if f.MetricAppearedTs == math.MinInt64 {
363363
panic("BUG: we got some Samples but metric still hasn't appeared")
364364
}
365-
v, h, err := extendedRate(f.ctx, f.Samples, false, false, f.StepTime, f.SelectRange, f.Offset, *f.MetricAppearedTs)
365+
v, h, err := extendedRate(f.ctx, f.Samples, false, false, f.StepTime, f.SelectRange, f.Offset, f.MetricAppearedTs)
366366
if err != nil {
367367
return 0, nil, false, err
368368
}
@@ -372,10 +372,10 @@ var rangeVectorFuncs = map[string]FunctionCall{
372372
if len(f.Samples) == 0 {
373373
return 0., nil, false, nil
374374
}
375-
if f.MetricAppearedTs == nil {
375+
if f.MetricAppearedTs == math.MinInt64 {
376376
panic("BUG: we got some Samples but metric still hasn't appeared")
377377
}
378-
v, h, err := extendedRate(f.ctx, f.Samples, true, false, f.StepTime, f.SelectRange, f.Offset, *f.MetricAppearedTs)
378+
v, h, err := extendedRate(f.ctx, f.Samples, true, false, f.StepTime, f.SelectRange, f.Offset, f.MetricAppearedTs)
379379
if err != nil {
380380
return 0, nil, false, err
381381
}

ringbuffer/generic.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Buffer interface {
1616
MaxT() int64
1717
Push(t int64, v Value)
1818
Reset(mint int64, evalt int64)
19-
Eval(ctx context.Context, _, _ float64, _ *int64) (float64, *histogram.FloatHistogram, bool, error)
19+
Eval(ctx context.Context, _, _ float64, _ int64) (float64, *histogram.FloatHistogram, bool, error)
2020
SampleCount() int
2121
}
2222

@@ -124,7 +124,7 @@ func (r *GenericRingBuffer) Reset(mint int64, evalt int64) {
124124
r.items = r.items[:keep]
125125
}
126126

127-
func (r *GenericRingBuffer) Eval(ctx context.Context, scalarArg float64, scalarArg2 float64, metricAppearedTs *int64) (float64, *histogram.FloatHistogram, bool, error) {
127+
func (r *GenericRingBuffer) Eval(ctx context.Context, scalarArg float64, scalarArg2 float64, metricAppearedTs int64) (float64, *histogram.FloatHistogram, bool, error) {
128128
return r.call(FunctionArgs{
129129
ctx: ctx,
130130
Samples: r.items,

ringbuffer/rate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func (r *RateBuffer) Reset(mint int64, evalt int64) {
171171
r.firstSamples[last].T = math.MaxInt64
172172
}
173173

174-
func (r *RateBuffer) Eval(ctx context.Context, _, _ float64, _ *int64) (float64, *histogram.FloatHistogram, bool, error) {
174+
func (r *RateBuffer) Eval(ctx context.Context, _, _ float64, _ int64) (float64, *histogram.FloatHistogram, bool, error) {
175175
if r.firstSamples[0].T == math.MaxInt64 || r.firstSamples[0].T == r.last.T {
176176
return 0, nil, false, nil
177177
}

storage/prometheus/matrix_selector.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type matrixScanner struct {
3535
buffer ringbuffer.Buffer
3636
iterator chunkenc.Iterator
3737
lastSample ringbuffer.Sample
38-
metricAppearedTs *int64
38+
metricAppearedTs int64
3939
}
4040

4141
type matrixSelector struct {
@@ -238,11 +238,12 @@ func (o *matrixSelector) loadSeries(ctx context.Context) error {
238238
lbls, _ = extlabels.DropMetricName(lbls, b)
239239
}
240240
o.scanners[i] = matrixScanner{
241-
labels: lbls,
242-
signature: s.Signature,
243-
iterator: s.Iterator(nil),
244-
lastSample: ringbuffer.Sample{T: math.MinInt64},
245-
buffer: o.newBuffer(ctx),
241+
labels: lbls,
242+
signature: s.Signature,
243+
iterator: s.Iterator(nil),
244+
lastSample: ringbuffer.Sample{T: math.MinInt64},
245+
buffer: o.newBuffer(ctx),
246+
metricAppearedTs: math.MinInt64,
246247
}
247248
o.series[i] = lbls
248249
}
@@ -358,9 +359,8 @@ func (m *matrixScanner) selectPoints(
358359
if value.IsStaleNaN(v) {
359360
continue
360361
}
361-
if m.metricAppearedTs == nil {
362-
tCopy := t
363-
m.metricAppearedTs = &tCopy
362+
if m.metricAppearedTs == math.MinInt64 {
363+
m.metricAppearedTs = t
364364
}
365365
if t > maxt {
366366
m.lastSample.T, m.lastSample.V.F, m.lastSample.V.H = t, v, nil

0 commit comments

Comments
 (0)