From 61524ad87ba922d8aa38e7b81d3dae590b852a72 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Tue, 6 Feb 2024 21:52:32 +0200 Subject: [PATCH] vendor: update github.com/VictoriaMetrics/metricsql from v0.70.0 to v0.70.1 This should help with the https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5604 --- docs/CHANGELOG.md | 2 + go.mod | 2 +- go.sum | 4 +- .../VictoriaMetrics/metricsql/optimizer.go | 37 +++++++++++++++++-- .../VictoriaMetrics/metricsql/transform.go | 2 +- vendor/modules.txt | 2 +- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 959cbc696..7165de256 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -33,6 +33,8 @@ The sandbox cluster installation is running under the constant load generated by * FEATURE: [dashboards/vmagent](https://grafana.com/grafana/dashboards/12683): add `Targets scraped/s` stat panel showing the number of targets scraped by the vmagent per-second. * FEATURE: [dashboards/all](https://grafana.com/orgs/victoriametrics): add new panel `CPU spent on GC`. It should help identifying cases when too much CPU is spent on garbage collection, and advice users on how this can be addressed. +* BUGFIX: [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html): properly propagate [label filters](https://docs.victoriametrics.com/keyconcepts/#filtering) from multiple arguments passed to [aggregate functions](https://docs.victoriametrics.com/metricsql/#aggregate-functions). For example, `sum({job="foo"}, {job="bar"}) by (job) + a` was improperly optimized to `sum({job="foo"}, {job="bar"}) by (job) + a{job="foo"}` before being executed. This could lead to unexpected results. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5604). + ## [v1.97.1](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.97.1) Released at 2024-02-01 diff --git a/go.mod b/go.mod index af050dd48..712de6a25 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/VictoriaMetrics/easyproto v0.1.4 github.com/VictoriaMetrics/fastcache v1.12.2 github.com/VictoriaMetrics/metrics v1.31.0 - github.com/VictoriaMetrics/metricsql v0.70.0 + github.com/VictoriaMetrics/metricsql v0.70.1 github.com/aws/aws-sdk-go-v2 v1.24.1 github.com/aws/aws-sdk-go-v2/config v1.26.6 github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.15.15 diff --git a/go.sum b/go.sum index d44b5d87b..9539d0ed6 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkT github.com/VictoriaMetrics/metrics v1.24.0/go.mod h1:eFT25kvsTidQFHb6U0oa0rTrDRdz4xTYjpL8+UPohys= github.com/VictoriaMetrics/metrics v1.31.0 h1:X6+nBvAP0UB+GjR0Ht9hhQ3pjL1AN4b8dt9zFfzTsUo= github.com/VictoriaMetrics/metrics v1.31.0/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8= -github.com/VictoriaMetrics/metricsql v0.70.0 h1:G0k/m1yAF6pmk0dM3VT9/XI5PZ8dL7EbcLhREf4bgeI= -github.com/VictoriaMetrics/metricsql v0.70.0/go.mod h1:k4UaP/+CjuZslIjd+kCigNG9TQmUqh5v0TP/nMEy90I= +github.com/VictoriaMetrics/metricsql v0.70.1 h1:9WneeSk9HAGf9E8qZmuPnE3KaflBpVkrLjpPtbAlzoU= +github.com/VictoriaMetrics/metricsql v0.70.1/go.mod h1:k4UaP/+CjuZslIjd+kCigNG9TQmUqh5v0TP/nMEy90I= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= diff --git a/vendor/github.com/VictoriaMetrics/metricsql/optimizer.go b/vendor/github.com/VictoriaMetrics/metricsql/optimizer.go index bd070be68..f1e04ab5b 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/optimizer.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/optimizer.go @@ -88,7 +88,16 @@ func getCommonLabelFilters(e Expr) []LabelFilter { } return getCommonLabelFilters(arg) case *AggrFuncExpr: - arg := getFuncArgForOptimization(t.Name, t.Args) + args := t.Args + if len(args) > 0 && canAcceptMultipleArgsForAggrFunc(t.Name) { + lfs := getCommonLabelFilters(args[0]) + for _, arg := range args[1:] { + lfsNext := getCommonLabelFilters(arg) + lfs = intersectLabelFilters(lfs, lfsNext) + } + return trimFiltersByAggrModifier(lfs, t) + } + arg := getFuncArgForOptimization(t.Name, args) if arg == nil { return nil } @@ -242,9 +251,16 @@ func pushdownBinaryOpFiltersInplace(e Expr, lfs []LabelFilter) { } case *AggrFuncExpr: lfs = trimFiltersByAggrModifier(lfs, t) - arg := getFuncArgForOptimization(t.Name, t.Args) - if arg != nil { - pushdownBinaryOpFiltersInplace(arg, lfs) + args := t.Args + if len(args) > 0 && canAcceptMultipleArgsForAggrFunc(t.Name) { + for _, arg := range args { + pushdownBinaryOpFiltersInplace(arg, lfs) + } + } else { + arg := getFuncArgForOptimization(t.Name, args) + if arg != nil { + pushdownBinaryOpFiltersInplace(arg, lfs) + } } case *BinaryOpExpr: lfs = TrimFiltersByGroupModifier(lfs, t) @@ -379,10 +395,23 @@ func getAggrArgIdxForOptimization(funcName string, args []Expr) int { case "quantiles": return len(args) - 1 default: + if len(args) > 1 && canAcceptMultipleArgsForAggrFunc(funcName) { + panic(fmt.Errorf("BUG: %d > 1 args passed to aggregate function %q; this case must be already handled", len(args), funcName)) + } return 0 } } +func canAcceptMultipleArgsForAggrFunc(funcName string) bool { + switch strings.ToLower(funcName) { + case "any", "avg", "count", "distinct", "geomean", "group", "histogram", "mad", "max", + "median", "min", "mode", "share", "stddev", "stdvar", "sum", "sum2", "zscore": + return true + default: + return false + } +} + func getRollupArgIdxForOptimization(funcName string, args []Expr) int { // This must be kept in sync with GetRollupArgIdx() switch strings.ToLower(funcName) { diff --git a/vendor/github.com/VictoriaMetrics/metricsql/transform.go b/vendor/github.com/VictoriaMetrics/metricsql/transform.go index e8d89aa8a..01dde4e55 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/transform.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/transform.go @@ -24,9 +24,9 @@ var transformFuncs = map[string]bool{ "clamp_min": true, "cos": true, "cosh": true, - "day_of_year": true, "day_of_month": true, "day_of_week": true, + "day_of_year": true, "days_in_month": true, "deg": true, "drop_common_labels": true, diff --git a/vendor/modules.txt b/vendor/modules.txt index 4c9d4cbe6..229018896 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -102,7 +102,7 @@ github.com/VictoriaMetrics/fastcache # github.com/VictoriaMetrics/metrics v1.31.0 ## explicit; go 1.17 github.com/VictoriaMetrics/metrics -# github.com/VictoriaMetrics/metricsql v0.70.0 +# github.com/VictoriaMetrics/metricsql v0.70.1 ## explicit; go 1.13 github.com/VictoriaMetrics/metricsql github.com/VictoriaMetrics/metricsql/binaryop