From ce38b176bc70e6112a8e45cc054660161a68bd60 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 4 Feb 2020 23:23:37 +0200 Subject: [PATCH] app/vmselect/promql: automatically apply `offset -step` to `rollup_candlestick` function in order to obtain the expected OHLC results See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/309 --- app/vmselect/promql/eval.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/vmselect/promql/eval.go b/app/vmselect/promql/eval.go index b58c8fdb07..dd32bf28f1 100644 --- a/app/vmselect/promql/eval.go +++ b/app/vmselect/promql/eval.go @@ -425,7 +425,7 @@ func evalRollupFunc(ec *EvalConfig, name string, rf rollupFunc, expr metricsql.E if err != nil { return nil, err } - ecNew = newEvalConfig(ec) + ecNew = newEvalConfig(ecNew) ecNew.Start -= offset ecNew.End -= offset if ecNew.MayCache { @@ -435,6 +435,16 @@ func evalRollupFunc(ec *EvalConfig, name string, rf rollupFunc, expr metricsql.E ecNew.End = end } } + if name == "rollup_candlestick" && len(re.Window) == 0 { + // Automatically apply `offset -step` to `rollup_candlestick` function + // in order to obtain expected OHLC results. + // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/309#issuecomment-582113462 + step := ecNew.Step + ecNew = newEvalConfig(ecNew) + ecNew.Start += step + ecNew.End += step + offset -= step + } var rvs []*timeseries var err error if me, ok := re.Expr.(*metricsql.MetricExpr); ok {