[REFACTOR] PromQL: simplify rangeEvalTimestampFunctionOverVectorSelector (#14021)

The function `rangeEvalTimestampFunctionOverVectorSelector` appeared to be checking histogram size, however the value it used was always 0 due to subtle variable shadowing.
However we don't need to pass sample values to the `timestamp` function, since the latter only cares about timestamps. This also affects peak sample count in statistics, since we are no longer copying histogram samples.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2024-05-08 11:39:44 +02:00 committed by GitHub
parent 2524a91591
commit a25160e6a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 21 deletions

View File

@ -2024,25 +2024,21 @@ func (ev *evaluator) rangeEvalTimestampFunctionOverVectorSelector(vs *parser.Vec
vec := make(Vector, 0, len(vs.Series)) vec := make(Vector, 0, len(vs.Series))
for i, s := range vs.Series { for i, s := range vs.Series {
it := seriesIterators[i] it := seriesIterators[i]
t, f, h, ok := ev.vectorSelectorSingle(it, vs, enh.Ts) t, _, _, ok := ev.vectorSelectorSingle(it, vs, enh.Ts)
if ok { if !ok {
vec = append(vec, Sample{ continue
Metric: s.Labels(), }
T: t,
F: f,
H: h,
})
histSize := 0
if h != nil {
histSize := h.Size() / 16 // 16 bytes per sample.
ev.currentSamples += histSize
}
ev.currentSamples++
ev.samplesStats.IncrementSamplesAtTimestamp(enh.Ts, int64(1+histSize)) // Note that we ignore the sample values because call only cares about the timestamp.
if ev.currentSamples > ev.maxSamples { vec = append(vec, Sample{
ev.error(ErrTooManySamples(env)) Metric: s.Labels(),
} T: t,
})
ev.currentSamples++
ev.samplesStats.IncrementSamplesAtTimestamp(enh.Ts, 1)
if ev.currentSamples > ev.maxSamples {
ev.error(ErrTooManySamples(env))
} }
} }
ev.samplesStats.UpdatePeak(ev.currentSamples) ev.samplesStats.UpdatePeak(ev.currentSamples)

View File

@ -818,8 +818,8 @@ load 10s
{ {
Query: "timestamp(metricWith1HistogramEvery10Seconds)", Query: "timestamp(metricWith1HistogramEvery10Seconds)",
Start: time.Unix(21, 0), Start: time.Unix(21, 0),
PeakSamples: 13, // histogram size 12 + 1 extra because of timestamp PeakSamples: 2,
TotalSamples: 1, // 1 float sample (because of timestamp) / 10 seconds TotalSamples: 1, // 1 float sample (because of timestamp) / 10 seconds
TotalSamplesPerStep: stats.TotalSamplesPerStep{ TotalSamplesPerStep: stats.TotalSamplesPerStep{
21000: 1, 21000: 1,
}, },
@ -1116,7 +1116,7 @@ load 10s
Start: time.Unix(201, 0), Start: time.Unix(201, 0),
End: time.Unix(220, 0), End: time.Unix(220, 0),
Interval: 5 * time.Second, Interval: 5 * time.Second,
PeakSamples: 16, PeakSamples: 5,
TotalSamples: 4, // 1 sample per query * 4 steps TotalSamples: 4, // 1 sample per query * 4 steps
TotalSamplesPerStep: stats.TotalSamplesPerStep{ TotalSamplesPerStep: stats.TotalSamplesPerStep{
201000: 1, 201000: 1,