diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 139e123ec..ab63d5faa 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -21,6 +21,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): allow configuring the default number of stored rule's update states in memory via global `-rule.updateEntriesLimit` command-line flag or per-rule via rule's `update_entries_limit` configuration param. * BUGFIX: [vmui](https://docs.victoriametrics.com/#vmui): properly update the `step` value in url after the `step` input field has been manually changed. This allows preserving the proper `step` when copy-n-pasting the url to another instance of web browser. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3513). +* BUGFIX: properly parse floating-point numbers without integer or fractional parts such as `.123` and `20.` during [data import](https://docs.victoriametrics.com/#how-to-import-time-series-data). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3544). ## [v1.85.3](https://github.com/VictoriaMetrics/VictoriaMetrics/releases/tag/v1.85.3) diff --git a/go.mod b/go.mod index 0bfa4d145..c9f3de7ae 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/klauspost/compress v1.15.13 github.com/prometheus/prometheus v0.41.0 github.com/urfave/cli/v2 v2.23.7 - github.com/valyala/fastjson v1.6.3 + github.com/valyala/fastjson v1.6.4 github.com/valyala/fastrand v1.1.0 github.com/valyala/fasttemplate v1.2.2 github.com/valyala/gozstd v1.17.0 diff --git a/go.sum b/go.sum index de9090ece..bb1c3b761 100644 --- a/go.sum +++ b/go.sum @@ -425,8 +425,8 @@ github.com/urfave/cli/v2 v2.23.7/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6f github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus= -github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc= -github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= +github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ= +github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8= github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= diff --git a/vendor/github.com/valyala/fastjson/fastfloat/parse.go b/vendor/github.com/valyala/fastjson/fastfloat/parse.go index 5d4a7c7a7..b37838da6 100644 --- a/vendor/github.com/valyala/fastjson/fastfloat/parse.go +++ b/vendor/github.com/valyala/fastjson/fastfloat/parse.go @@ -213,6 +213,12 @@ func ParseBestEffort(s string) float64 { } } + // the integer part might be elided to remain compliant + // with https://go.dev/ref/spec#Floating-point_literals + if s[i] == '.' && (i+1 >= uint(len(s)) || s[i+1] < '0' || s[i+1] > '9') { + return 0 + } + d := uint64(0) j := i for i < uint(len(s)) { @@ -232,7 +238,7 @@ func ParseBestEffort(s string) float64 { } break } - if i <= j { + if i <= j && s[i] != '.' { s = s[i:] if strings.HasPrefix(s, "+") { s = s[1:] @@ -263,7 +269,9 @@ func ParseBestEffort(s string) float64 { // Parse fractional part. i++ if i >= uint(len(s)) { - return 0 + // the fractional part may be elided to remain compliant + // with https://go.dev/ref/spec#Floating-point_literals + return f } k := i for i < uint(len(s)) { @@ -363,6 +371,12 @@ func Parse(s string) (float64, error) { } } + // the integer part might be elided to remain compliant + // with https://go.dev/ref/spec#Floating-point_literals + if s[i] == '.' && (i+1 >= uint(len(s)) || s[i+1] < '0' || s[i+1] > '9') { + return 0, fmt.Errorf("missing integer and fractional part in %q", s) + } + d := uint64(0) j := i for i < uint(len(s)) { @@ -382,7 +396,7 @@ func Parse(s string) (float64, error) { } break } - if i <= j { + if i <= j && s[i] != '.' { ss := s[i:] if strings.HasPrefix(ss, "+") { ss = ss[1:] @@ -413,7 +427,9 @@ func Parse(s string) (float64, error) { // Parse fractional part. i++ if i >= uint(len(s)) { - return 0, fmt.Errorf("cannot parse fractional part in %q", s) + // the fractional part might be elided to remain compliant + // with https://go.dev/ref/spec#Floating-point_literals + return f, nil } k := i for i < uint(len(s)) { diff --git a/vendor/modules.txt b/vendor/modules.txt index 2b5468a98..ffc54c938 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -447,7 +447,7 @@ github.com/urfave/cli/v2 # github.com/valyala/bytebufferpool v1.0.0 ## explicit github.com/valyala/bytebufferpool -# github.com/valyala/fastjson v1.6.3 +# github.com/valyala/fastjson v1.6.4 ## explicit; go 1.12 github.com/valyala/fastjson github.com/valyala/fastjson/fastfloat