From eacd3c11ff7b3ffc69994dea4be6c0696119fd99 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 24 Feb 2025 15:01:05 +0100 Subject: [PATCH] vendor: update github.com/VictoriaMetrics/metricsql from v0.83.1 to v0.84.0 The new version of github.com/VictoriaMetrics/metricsql handles $__interval and $__rate_interval inside rollup functions in more correct way - it drops square brakets, so VictoriaMetrics could automatically detect the needed lookbehind window depending on the time distance between real samples. For example, rate(m[$__rate_interval]) is parsed and processed as rate(m) now. --- docs/changelog/CHANGELOG.md | 1 + go.mod | 2 +- go.sum | 6 ++---- .../VictoriaMetrics/metricsql/lexer.go | 18 ++++++++++++------ .../VictoriaMetrics/metricsql/parser.go | 13 ++++++++++++- vendor/modules.txt | 2 +- 6 files changed, 29 insertions(+), 13 deletions(-) diff --git a/docs/changelog/CHANGELOG.md b/docs/changelog/CHANGELOG.md index 6c8011ed05..41b1ebd29e 100644 --- a/docs/changelog/CHANGELOG.md +++ b/docs/changelog/CHANGELOG.md @@ -33,6 +33,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). * FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): print full error messages for failed queries on the `Explore Cardinality` page. Before, only response status code was printed. * FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): move values representing changes relative to the previous day to a separate column for easier sorting on the `Explore Cardinality` page. * FEATURE: [MetricsQL](https://docs.victoriametrics.com/metricsql/): support auto-format (prettify) for expressions that use quoted metric or label names. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7703) for details. +* FEATURE: [MetricsQL](https://docs.victoriametrics.com/metricsql/): parse `$__interval` and `$__rate_interval` inside square brackets as missing square brackets. For example, `rate(m[$__interval])` is parsed as `rate(m)` instead of `rate(m[1i])`. This enables automatic detection of the lookbehind window for [rollup functions](https://docs.victoriametrics.com/metricsql/#rollup-functions) by VictoriaMetrics, which usually returns the most expected result. * BUGFIX: all the VictoriaMetrics components: properly override basic authorization for API endpoints protected with `authKey`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/7345#issuecomment-2662595807) for details. * BUGFIX: [vmalert](https://docs.victoriametrics.com/vmalert/): fix polluted alert messages when multiple Alertmanager instances are configured with `alert_relabel_configs`. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/8040), and thanks to @evkuzin for [the pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8258). diff --git a/go.mod b/go.mod index 6afd266e9c..baeea7eeae 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/VictoriaMetrics/easyproto v0.1.4 github.com/VictoriaMetrics/fastcache v1.12.2 github.com/VictoriaMetrics/metrics v1.35.2 - github.com/VictoriaMetrics/metricsql v0.83.1 + github.com/VictoriaMetrics/metricsql v0.84.0 github.com/aws/aws-sdk-go-v2 v1.36.1 github.com/aws/aws-sdk-go-v2/config v1.29.6 github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.17.61 diff --git a/go.sum b/go.sum index 3b709fdcee..c866c432d4 100644 --- a/go.sum +++ b/go.sum @@ -43,10 +43,8 @@ github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkT github.com/VictoriaMetrics/metrics v1.34.0/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8= github.com/VictoriaMetrics/metrics v1.35.2 h1:Bj6L6ExfnakZKYPpi7mGUnkJP4NGQz2v5wiChhXNyWQ= github.com/VictoriaMetrics/metrics v1.35.2/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8= -github.com/VictoriaMetrics/metricsql v0.83.0 h1:3460jZ97XWD+595jpPdtVTVoKJflbxqBgeCbzPCiSgU= -github.com/VictoriaMetrics/metricsql v0.83.0/go.mod h1:1g4hdCwlbJZ851PU9VN65xy9Rdlzupo6fx3SNZ8Z64U= -github.com/VictoriaMetrics/metricsql v0.83.1 h1:+eHBVsYJvOPw8oy25gh1VT7OnT+jtfHb31eGvfYNEkY= -github.com/VictoriaMetrics/metricsql v0.83.1/go.mod h1:1g4hdCwlbJZ851PU9VN65xy9Rdlzupo6fx3SNZ8Z64U= +github.com/VictoriaMetrics/metricsql v0.84.0 h1:rVZapkXHiM4dR979La3tk8u2equ57Insbr1+Hm6yUew= +github.com/VictoriaMetrics/metricsql v0.84.0/go.mod h1:1g4hdCwlbJZ851PU9VN65xy9Rdlzupo6fx3SNZ8Z64U= github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow= github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4= github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b h1:mimo19zliBX/vSQ6PWWSL9lK8qwHozUj03+zLoEB8O0= diff --git a/vendor/github.com/VictoriaMetrics/metricsql/lexer.go b/vendor/github.com/VictoriaMetrics/metricsql/lexer.go index 9b564776fd..b7ebca52a2 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/lexer.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/lexer.go @@ -123,16 +123,12 @@ again: goto tokenFoundLabel } if strings.HasPrefix(s, "$__interval") { - // Automatically replace $__interval with 1i. - // This allows running copy-n-pasted queries from Grafana. lex.sTail = s[len("$__interval"):] - return "1i", nil + return "$__interval", nil } if strings.HasPrefix(s, "$__rate_interval") { - // Automatically replace $__rate_interval with 1i. - // This allows running copy-n-pasted queries from Grafana. lex.sTail = s[len("$__rate_interval"):] - return "1i", nil + return "$__interval", nil } return "", fmt.Errorf("cannot recognize %q", s) @@ -538,6 +534,9 @@ func scanSpecialIntegerPrefix(s string) (skipChars int, isHex bool) { } func isPositiveDuration(s string) bool { + if s == "$__interval" { + return true + } n := scanDuration(s) return n == len(s) } @@ -606,6 +605,10 @@ func DurationValue(s string, step int64) (int64, error) { } func parseSingleDuration(s string, step int64) (float64, error) { + if s == "$__interval" { + return float64(step), nil + } + s = strings.ToLower(s) numPart := s[:len(s)-1] // Strip trailing m if the duration is in ms @@ -668,6 +671,9 @@ func scanSingleDuration(s string, canBeNegative bool) int { if s[0] == '-' && canBeNegative { i++ } + if s[i:] == "$__interval" { + return i + len("$__interval") + } for i < len(s) && isDecimalChar(s[i]) { i++ } diff --git a/vendor/github.com/VictoriaMetrics/metricsql/parser.go b/vendor/github.com/VictoriaMetrics/metricsql/parser.go index 45d02a7d6b..0e6ef398ec 100644 --- a/vendor/github.com/VictoriaMetrics/metricsql/parser.go +++ b/vendor/github.com/VictoriaMetrics/metricsql/parser.go @@ -1512,7 +1512,15 @@ func (p *parser) parseWindowAndStep() (*DurationExpr, *DurationExpr, bool, error } var window *DurationExpr if !strings.HasPrefix(p.lex.Token, ":") { - window, err = p.parsePositiveDuration() + if p.lex.Token == "$__interval" { + // Skip $__interval, since it must be treated as missing lookbehind window, + // e.g. rate(m[$__interval]) must be equivalent to rate(m). + // In this case VictoriaMetrics automatically adjusts the lookbehind window + // to the interval between samples. + err = p.lex.Next() + } else { + window, err = p.parsePositiveDuration() + } if err != nil { return nil, nil, false, err } @@ -1626,6 +1634,9 @@ func (p *parser) parsePositiveDuration() (*DurationExpr, error) { if _, err := DurationValue(s, 0); err != nil { return nil, fmt.Errorf(`duration: parse value error: %q: %w`, s, err) } + if s == "$__interval" { + s = "1i" + } de := &DurationExpr{ s: s, } diff --git a/vendor/modules.txt b/vendor/modules.txt index c8c42d71ff..2ad9405c7c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -119,7 +119,7 @@ github.com/VictoriaMetrics/fastcache # github.com/VictoriaMetrics/metrics v1.35.2 ## explicit; go 1.17 github.com/VictoriaMetrics/metrics -# github.com/VictoriaMetrics/metricsql v0.83.1 +# github.com/VictoriaMetrics/metricsql v0.84.0 ## explicit; go 1.13 github.com/VictoriaMetrics/metricsql github.com/VictoriaMetrics/metricsql/binaryop