From 716754fae6a9bd2effa2e357e52e5655f8516df5 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 7 Aug 2020 07:38:18 +0300 Subject: [PATCH] app/vmselect/promql: properly handle `-n^m` like Prometheus does `-n^m` must be handled as `-(n^m)` instead of `(-n)^m`. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/675 --- app/vmselect/promql/exec_test.go | 15 +++++++++++++-- go.mod | 2 +- go.sum | 4 ++-- .../VictoriaMetrics/metricsql/parser.go | 5 ++--- vendor/modules.txt | 2 +- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 086e7de5a..8fab6461b 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -858,12 +858,23 @@ func TestExecSuccess(t *testing.T) { resultExpected := []netstorage.Result{r} f(q, resultExpected) }) - t.Run("time()*-1^0.5", func(t *testing.T) { + t.Run("time()*(-4)^0.5", func(t *testing.T) { t.Parallel() - q := `time()*-1^0.5` + q := `time()*(-4)^0.5` resultExpected := []netstorage.Result{} f(q, resultExpected) }) + t.Run("time()*-4^0.5", func(t *testing.T) { + t.Parallel() + q := `time()*-4^0.5` + r := netstorage.Result{ + MetricName: metricNameExpected, + Values: []float64{-2000, -2400, -2800, -3200, -3600, -4000}, + Timestamps: timestampsExpected, + } + resultExpected := []netstorage.Result{r} + f(q, resultExpected) + }) t.Run(`alias()`, func(t *testing.T) { t.Parallel() q := `alias(time(), "foobar")` diff --git a/go.mod b/go.mod index 6f44e4ad0..a9c0fc1db 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( // like https://github.com/valyala/fasthttp/commit/996610f021ff45fdc98c2ce7884d5fa4e7f9199b github.com/VictoriaMetrics/fasthttp v1.0.4 github.com/VictoriaMetrics/metrics v1.12.2 - github.com/VictoriaMetrics/metricsql v0.4.0 + github.com/VictoriaMetrics/metricsql v0.4.1 github.com/aws/aws-sdk-go v1.33.19 github.com/cespare/xxhash/v2 v2.1.1 github.com/golang/snappy v0.0.1 diff --git a/go.sum b/go.sum index a9720332d..278a26a8e 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,8 @@ github.com/VictoriaMetrics/fasthttp v1.0.4 h1:Aw6UqmPc0v5PunYOpiiyf4hk5B9PTMswdT github.com/VictoriaMetrics/fasthttp v1.0.4/go.mod h1:m5wCmg1dJN6s1B/lp8/dcKrnnM2l3DWB2eAGZGCTK3g= github.com/VictoriaMetrics/metrics v1.12.2 h1:SG8iAmqavDNuh7GIdHPoGHUhDL23KeKfvSZSozucNeA= github.com/VictoriaMetrics/metrics v1.12.2/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE= -github.com/VictoriaMetrics/metricsql v0.4.0 h1:1CMGiUzOgR83Y+hVS83/DaHYLaR6PFw1XWcvQnHn2V8= -github.com/VictoriaMetrics/metricsql v0.4.0/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8= +github.com/VictoriaMetrics/metricsql v0.4.1 h1:WbVIfRNCK7HjrzayrpAl07mkh4kiDFZuECsh57rly2Q= +github.com/VictoriaMetrics/metricsql v0.4.1/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8= github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM= github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= diff --git a/vendor/github.com/VictoriaMetrics/metricsql/parser.go b/vendor/github.com/VictoriaMetrics/metricsql/parser.go index 309f5fb04..315186469 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/parser.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/parser.go @@ -399,7 +399,7 @@ func (p *parser) parseSingleExprWithoutRollupSuffix() (Expr, error) { case "{": return p.parseMetricExpr() case "-": - // Unary minus. Substitute -expr with (0 - expr) + // Unary minus. Substitute `-expr` with `0 - expr` if err := p.lex.Next(); err != nil { return nil, err } @@ -414,8 +414,7 @@ func (p *parser) parseSingleExprWithoutRollupSuffix() (Expr, error) { }, Right: e, } - pe := parensExpr{be} - return &pe, nil + return be, nil case "+": // Unary plus if err := p.lex.Next(); err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 053156603..dd9da1081 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -16,7 +16,7 @@ github.com/VictoriaMetrics/fasthttp/fasthttputil github.com/VictoriaMetrics/fasthttp/stackless # github.com/VictoriaMetrics/metrics v1.12.2 github.com/VictoriaMetrics/metrics -# github.com/VictoriaMetrics/metricsql v0.4.0 +# github.com/VictoriaMetrics/metricsql v0.4.1 github.com/VictoriaMetrics/metricsql github.com/VictoriaMetrics/metricsql/binaryop # github.com/aws/aws-sdk-go v1.33.19