app/vmselect/promql: do not take into account values outside the current window in rollup_candlestick

Updates https://github.com/VictoriaMetrics/VictoriaMetrics/issues/309
This commit is contained in:
Aliaksandr Valialkin 2020-02-23 18:03:52 +02:00
parent c69d4b01f0
commit b58e3fc8a9
2 changed files with 13 additions and 6 deletions

View File

@ -4750,7 +4750,7 @@ func TestExecSuccess(t *testing.T) {
}}
r2 := netstorage.Result{
MetricName: metricNameExpected,
Values: []float64{0.9, 0.32, 0.82, 0.13, 0.28, 0.86},
Values: []float64{0.85, 0.15, 0.43, 0.76, 0.47, 0.21},
Timestamps: timestampsExpected,
}
r2.MetricName.Tags = []storage.Tag{{
@ -4768,7 +4768,7 @@ func TestExecSuccess(t *testing.T) {
}}
r4 := netstorage.Result{
MetricName: metricNameExpected,
Values: []float64{0.9, 0.94, 0.97, 0.93, 0.98, 0.92},
Values: []float64{0.85, 0.94, 0.97, 0.93, 0.98, 0.92},
Timestamps: timestampsExpected,
}
r4.MetricName.Tags = []storage.Tag{{

View File

@ -1434,10 +1434,17 @@ func getCandlestickValues(rfa *rollupFuncArg) []float64 {
return rfa.values[:len(timestamps)]
}
func getPrevValueForCandlestick(rfa *rollupFuncArg) float64 {
if rfa.prevTimestamp+rfa.step == rfa.currTimestamp {
return rfa.prevValue
}
return nan
}
func rollupOpen(rfa *rollupFuncArg) float64 {
values := getCandlestickValues(rfa)
if len(values) == 0 {
return rfa.prevValue
return getPrevValueForCandlestick(rfa)
}
return values[0]
}
@ -1445,7 +1452,7 @@ func rollupOpen(rfa *rollupFuncArg) float64 {
func rollupClose(rfa *rollupFuncArg) float64 {
values := getCandlestickValues(rfa)
if len(values) == 0 {
return rfa.prevValue
return getPrevValueForCandlestick(rfa)
}
return values[len(values)-1]
}
@ -1453,7 +1460,7 @@ func rollupClose(rfa *rollupFuncArg) float64 {
func rollupHigh(rfa *rollupFuncArg) float64 {
values := getCandlestickValues(rfa)
if len(values) == 0 {
return rfa.prevValue
return getPrevValueForCandlestick(rfa)
}
max := values[0]
for _, v := range values[1:] {
@ -1467,7 +1474,7 @@ func rollupHigh(rfa *rollupFuncArg) float64 {
func rollupLow(rfa *rollupFuncArg) float64 {
values := getCandlestickValues(rfa)
if len(values) == 0 {
return rfa.prevValue
return getPrevValueForCandlestick(rfa)
}
min := values[0]
for _, v := range values[1:] {