mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/promql: add atan2
binary operator, which is going to be added in Prometheus 2.31
See https://github.com/prometheus/prometheus/pull/9248
This commit is contained in:
parent
81c6720392
commit
a5001b9c20
9 changed files with 49 additions and 13 deletions
|
@ -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),
|
||||
|
|
|
@ -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)`
|
||||
|
|
|
@ -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
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
13
vendor/github.com/VictoriaMetrics/metricsql/binary_op.go
generated
vendored
13
vendor/github.com/VictoriaMetrics/metricsql/binary_op.go
generated
vendored
|
@ -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":
|
||||
|
|
5
vendor/github.com/VictoriaMetrics/metricsql/binaryop/funcs.go
generated
vendored
5
vendor/github.com/VictoriaMetrics/metricsql/binaryop/funcs.go
generated
vendored
|
@ -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) {
|
||||
|
|
20
vendor/github.com/VictoriaMetrics/metricsql/transform.go
generated
vendored
20
vendor/github.com/VictoriaMetrics/metricsql/transform.go
generated
vendored
|
@ -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,
|
||||
|
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue