diff --git a/app/vmselect/promql/binary_op.go b/app/vmselect/promql/binary_op.go index 48b682cfe..b720573d5 100644 --- a/app/vmselect/promql/binary_op.go +++ b/app/vmselect/promql/binary_op.go @@ -19,6 +19,9 @@ var binaryOpFuncs = map[string]binaryOpFunc{ "%": newBinaryOpArithFunc(binaryop.Mod), "^": newBinaryOpArithFunc(binaryop.Pow), + // See https://github.com/prometheus/prometheus/pull/9248 + "atan2": newBinaryOpArithFunc(binaryop.Atan2), + // cmp ops "==": newBinaryOpCmpFunc(binaryop.Eq), "!=": newBinaryOpCmpFunc(binaryop.Neq), diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go index 1cbbe03d6..1c033b926 100644 --- a/app/vmselect/promql/exec_test.go +++ b/app/vmselect/promql/exec_test.go @@ -1072,6 +1072,17 @@ func TestExecSuccess(t *testing.T) { resultExpected := []netstorage.Result{r} f(q, resultExpected) }) + t.Run("atan2()", func(t *testing.T) { + t.Parallel() + q := `time() atan2 time()/10` + r := netstorage.Result{ + MetricName: metricNameExpected, + Values: []float64{0.07853981633974483, 0.07853981633974483, 0.07853981633974483, 0.07853981633974483, 0.07853981633974483, 0.07853981633974483}, + Timestamps: timestampsExpected, + } + resultExpected := []netstorage.Result{r} + f(q, resultExpected) + }) t.Run("atan()", func(t *testing.T) { t.Parallel() q := `atan((2000-time())/1000)` diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8956f7a23..8c114af2a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,7 +6,7 @@ sort: 15 ## tip -* FEATURE: add missing trigonometric functions, which are going to be added in [Prometheus 2.31](https://github.com/prometheus/prometheus/pull/9239): [acosh](https://docs.victoriametrics.com/MetricsQL.html#acosh), [asinh](https://docs.victoriametrics.com/MetricsQL.html#asinh), [atan](https://docs.victoriametrics.com/MetricsQL.html#atan), [atanh](https://docs.victoriametrics.com/MetricsQL.html#atanh), [cosh](https://docs.victoriametrics.com/MetricsQL.html#cosh), [deg](https://docs.victoriametrics.com/MetricsQL.html#deg), [rad](https://docs.victoriametrics.com/MetricsQL.html#rad), [sinh](https://docs.victoriametrics.com/MetricsQL.html#sinh), [tan](https://docs.victoriametrics.com/MetricsQL.html#tan), [tanh](https://docs.victoriametrics.com/MetricsQL.html#tanh). +* FEATURE: add trigonometric functions, which are going to be added in [Prometheus 2.31](https://github.com/prometheus/prometheus/pull/9239): [acosh](https://docs.victoriametrics.com/MetricsQL.html#acosh), [asinh](https://docs.victoriametrics.com/MetricsQL.html#asinh), [atan](https://docs.victoriametrics.com/MetricsQL.html#atan), [atanh](https://docs.victoriametrics.com/MetricsQL.html#atanh), [cosh](https://docs.victoriametrics.com/MetricsQL.html#cosh), [deg](https://docs.victoriametrics.com/MetricsQL.html#deg), [rad](https://docs.victoriametrics.com/MetricsQL.html#rad), [sinh](https://docs.victoriametrics.com/MetricsQL.html#sinh), [tan](https://docs.victoriametrics.com/MetricsQL.html#tan), [tanh](https://docs.victoriametrics.com/MetricsQL.html#tanh). Also add `atan2` binary operator. See [this pull request](https://github.com/prometheus/prometheus/pull/9248). * FEATURE: consistently return the same set of time series from [limitk](https://docs.victoriametrics.com/MetricsQL.html#limitk) function. This improves the usability of periodically refreshed graphs. * BUGFIX: vmstorage: fix `unaligned 64-bit atomic operation` panic on 32-bit architectures (arm and 386). The panic has been introduced in v1.67.0 diff --git a/go.mod b/go.mod index 3e6688cf1..ab8cdc0f7 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( // like https://github.com/valyala/fasthttp/commit/996610f021ff45fdc98c2ce7884d5fa4e7f9199b github.com/VictoriaMetrics/fasthttp v1.1.0 github.com/VictoriaMetrics/metrics v1.18.0 - github.com/VictoriaMetrics/metricsql v0.26.0 + github.com/VictoriaMetrics/metricsql v0.27.0 github.com/VividCortex/ewma v1.2.0 // indirect github.com/aws/aws-sdk-go v1.40.58 github.com/cespare/xxhash/v2 v2.1.2 diff --git a/go.sum b/go.sum index c0855e756..eecd4e46d 100644 --- a/go.sum +++ b/go.sum @@ -107,8 +107,8 @@ github.com/VictoriaMetrics/fasthttp v1.1.0/go.mod h1:/7DMcogqd+aaD3G3Hg5kFgoFwlR github.com/VictoriaMetrics/metrics v1.12.2/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE= github.com/VictoriaMetrics/metrics v1.18.0 h1:vov5NxDHRSXFbdiH4dYLYEjKLoAXXSQ7hcnG8TSD9JQ= github.com/VictoriaMetrics/metrics v1.18.0/go.mod h1:ArjwVz7WpgpegX/JpB0zpNF2h2232kErkEnzH1sxMmA= -github.com/VictoriaMetrics/metricsql v0.26.0 h1:lJBRn9vn9kst7hfNzSsQorulzNYQtX7JxWWWxh/udfI= -github.com/VictoriaMetrics/metricsql v0.26.0/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8= +github.com/VictoriaMetrics/metricsql v0.27.0 h1:S6xWFKEyu+EbPS3tYr1cWeRza61L3e4tYcbBqMakuX0= +github.com/VictoriaMetrics/metricsql v0.27.0/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8= github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= diff --git a/vendor/github.com/VictoriaMetrics/metricsql/binary_op.go b/vendor/github.com/VictoriaMetrics/metricsql/binary_op.go index a265af00b..5005089ec 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/binary_op.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/binary_op.go @@ -16,6 +16,9 @@ var binaryOps = map[string]bool{ "%": true, "^": true, + // See https://github.com/prometheus/prometheus/pull/9248 + "atan2": true, + // cmp ops "==": true, "!=": true, @@ -57,9 +60,10 @@ var binaryOpPriorities = map[string]int{ "+": 4, "-": 4, - "*": 5, - "/": 5, - "%": 5, + "*": 5, + "/": 5, + "%": 5, + "atan2": 5, "^": 6, } @@ -140,6 +144,7 @@ func isBinaryOpLogicalSet(op string) bool { } func binaryOpEvalNumber(op string, left, right float64, isBool bool) float64 { + op = strings.ToLower(op) if IsBinaryOpCmp(op) { evalCmp := func(cf func(left, right float64) bool) float64 { if isBool { @@ -181,6 +186,8 @@ func binaryOpEvalNumber(op string, left, right float64, isBool bool) float64 { left = binaryop.Div(left, right) case "%": left = binaryop.Mod(left, right) + case "atan2": + left = binaryop.Atan2(left, right) case "^": left = binaryop.Pow(left, right) case "and": diff --git a/vendor/github.com/VictoriaMetrics/metricsql/binaryop/funcs.go b/vendor/github.com/VictoriaMetrics/metricsql/binaryop/funcs.go index 9a123e24d..1cce8cba4 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/binaryop/funcs.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/binaryop/funcs.go @@ -79,6 +79,11 @@ func Pow(left, right float64) float64 { return math.Pow(left, right) } +// Atan2 returns atan2(left, right) +func Atan2(left, right float64) float64 { + return math.Atan2(left, right) +} + // Default returns left or right if left is NaN. func Default(left, right float64) float64 { if math.IsNaN(left) { diff --git a/vendor/github.com/VictoriaMetrics/metricsql/transform.go b/vendor/github.com/VictoriaMetrics/metricsql/transform.go index 131e5a6a4..d8e3c9c85 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/transform.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/transform.go @@ -9,13 +9,22 @@ var transformFuncs = map[string]bool{ // See funcs accepting instant-vector on https://prometheus.io/docs/prometheus/latest/querying/functions/ . "abs": true, "absent": true, + "acos": true, + "acosh": true, + "asin": true, + "asinh": true, + "atan": true, + "atanh": true, "ceil": true, "clamp": true, "clamp_max": true, "clamp_min": true, + "cos": true, + "cosh": true, "day_of_month": true, "day_of_week": true, "days_in_month": true, + "deg": true, "exp": true, "floor": true, "histogram_quantile": true, @@ -27,12 +36,18 @@ var transformFuncs = map[string]bool{ "log10": true, "minute": true, "month": true, + "pi": true, + "rad": true, "round": true, "scalar": true, "sgn": true, + "sin": true, + "sinh": true, "sort": true, "sort_desc": true, "sqrt": true, + "tan": true, + "tanh": true, "time": true, // "timestamp" has been moved to rollup funcs. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/415 "vector": true, @@ -75,11 +90,6 @@ var transformFuncs = map[string]bool{ "rand": true, "rand_normal": true, "rand_exponential": true, - "pi": true, - "sin": true, - "cos": true, - "asin": true, - "acos": true, "prometheus_buckets": true, "buckets_limit": true, "histogram_share": true, diff --git a/vendor/modules.txt b/vendor/modules.txt index 5b2d63381..5921149cb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -22,7 +22,7 @@ github.com/VictoriaMetrics/fasthttp/stackless # github.com/VictoriaMetrics/metrics v1.18.0 ## explicit github.com/VictoriaMetrics/metrics -# github.com/VictoriaMetrics/metricsql v0.26.0 +# github.com/VictoriaMetrics/metricsql v0.27.0 ## explicit github.com/VictoriaMetrics/metricsql github.com/VictoriaMetrics/metricsql/binaryop