From ae1b09e953ec4b1038857af273434c22199bef74 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 6a60305f8..762d6d9b8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,6 +11,8 @@ The following `tip` changes can be tested by building VictoriaMetrics components ## v1.93.x long-time support release (LTS) +* 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.93.11](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.93.11) Released at 2024-02-01 diff --git a/go.mod b/go.mod index 36b5cf2db..a17e6e4db 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( // like https://github.com/valyala/fasthttp/commit/996610f021ff45fdc98c2ce7884d5fa4e7f9199b github.com/VictoriaMetrics/fasthttp v1.2.0 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 17c404271..43d34718c 100644 --- a/go.sum +++ b/go.sum @@ -66,8 +66,8 @@ github.com/VictoriaMetrics/fasthttp v1.2.0/go.mod h1:zv5YSmasAoSyv8sBVexfArzFDIG 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 31c1497fa..22712ff45 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -104,7 +104,7 @@ github.com/VictoriaMetrics/fasthttp/stackless # 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