From 1c445bf7eb98c0ce8296a21c35e961b419b3044f Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 10 Jan 2020 23:12:47 +0200 Subject: [PATCH] vendor: update github.com/valyala/fastjson from v1.4.2 to v1.4.5 This should fix parsing Inf values in `/api/v1/import`. The previous attempt to fix this in VictoriaMetrics v1.32.1 was unsuccessful. --- app/vminsert/vmimport/parser_test.go | 13 +++++++++++++ go.mod | 2 +- go.sum | 4 ++-- vendor/github.com/valyala/fastjson/parser.go | 15 ++++++++++++++- vendor/modules.txt | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/app/vminsert/vmimport/parser_test.go b/app/vminsert/vmimport/parser_test.go index 7ed445af1..ee484c918 100644 --- a/app/vminsert/vmimport/parser_test.go +++ b/app/vminsert/vmimport/parser_test.go @@ -1,6 +1,7 @@ package vmimport import ( + "math" "reflect" "testing" ) @@ -101,6 +102,18 @@ func TestRowsUnmarshalSuccess(t *testing.T) { }}, }) + // Inf and nan values + f(`{"metric":{"foo":"bar"},"values":[Inf, -Inf],"timestamps":[456, 789]}`, &Rows{ + Rows: []Row{{ + Tags: []Tag{{ + Key: []byte("foo"), + Value: []byte("bar"), + }}, + Values: []float64{math.Inf(1), math.Inf(-1)}, + Timestamps: []int64{456, 789}, + }}, + }) + // Line with multiple tags f(`{"metric":{"foo":"bar","baz":"xx"},"values":[1.23, -3.21],"timestamps" : [456,789]}`, &Rows{ Rows: []Row{{ diff --git a/go.mod b/go.mod index 9c8193a49..52a027d92 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/jstemmer/go-junit-report v0.9.1 // indirect github.com/klauspost/compress v1.9.4 github.com/lithammer/go-jump-consistent-hash v1.0.1 - github.com/valyala/fastjson v1.4.2 + github.com/valyala/fastjson v1.4.5 github.com/valyala/fastrand v1.0.0 github.com/valyala/gozstd v1.6.4 github.com/valyala/histogram v1.0.1 diff --git a/go.sum b/go.sum index ef107cadc..58226d60e 100644 --- a/go.sum +++ b/go.sum @@ -99,8 +99,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P 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.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= -github.com/valyala/fastjson v1.4.2 h1:vJXOwCenHuSyEfxWBUtzZl9LqyfgN2YkaNQBPHHEYbk= -github.com/valyala/fastjson v1.4.2/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o= +github.com/valyala/fastjson v1.4.5 h1:uSuLfXk2LzRtzwd3Fy5zGRBe0Vs7zhs11vjdko32xb4= +github.com/valyala/fastjson v1.4.5/go.mod h1:nV6MsjxL2IMJQUoHDIrjEI7oLyeqK6aBD7EFWPsvP8o= github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI= github.com/valyala/fastrand v1.0.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ= github.com/valyala/gozstd v1.6.4 h1:nFLddjEf90SFl5cVWyElSHozQDsbvLljPK703/skBS0= diff --git a/vendor/github.com/valyala/fastjson/parser.go b/vendor/github.com/valyala/fastjson/parser.go index 478a866c0..c617835f0 100644 --- a/vendor/github.com/valyala/fastjson/parser.go +++ b/vendor/github.com/valyala/fastjson/parser.go @@ -138,6 +138,13 @@ func parseValue(s string, c *cache) (*Value, string, error) { } if s[0] == 'n' { if len(s) < len("null") || s[:len("null")] != "null" { + // Try parsing NaN + if len(s) >= 3 && strings.EqualFold(s[:3], "nan") { + v := c.getValue() + v.t = TypeNumber + v.s = s[:3] + return v, s[3:], nil + } return nil, s, fmt.Errorf("unexpected value found: %q", s) } return valueNull, s[len("null"):], nil @@ -415,7 +422,13 @@ func parseRawNumber(s string) (string, string, error) { if (ch >= '0' && ch <= '9') || ch == '.' || ch == '-' || ch == 'e' || ch == 'E' || ch == '+' { continue } - if i == 0 { + if i == 0 || i == 1 && (s[0] == '-' || s[0] == '+') { + if len(s[i:]) >= 3 { + xs := s[i : i+3] + if strings.EqualFold(xs, "inf") || strings.EqualFold(xs, "nan") { + return s[:i+3], s[i+3:], nil + } + } return "", s, fmt.Errorf("unexpected char: %q", s[:1]) } ns := s[:i] diff --git a/vendor/modules.txt b/vendor/modules.txt index a9a4fdd68..e7c0c91b2 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -92,7 +92,7 @@ github.com/klauspost/compress/zstd/internal/xxhash github.com/lithammer/go-jump-consistent-hash # github.com/valyala/bytebufferpool v1.0.0 github.com/valyala/bytebufferpool -# github.com/valyala/fastjson v1.4.2 +# github.com/valyala/fastjson v1.4.5 github.com/valyala/fastjson github.com/valyala/fastjson/fastfloat # github.com/valyala/fastrand v1.0.0