From feb6b203a4111b7aca446bc4e54bb5b331e2af4a Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sun, 26 May 2019 22:10:56 +0300 Subject: [PATCH] app/vminsert/influx: try converting string values to numeric values, since Influx agents may send numeric values as strings Fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/34 --- app/vminsert/influx/parser.go | 6 ++++-- app/vminsert/influx/parser_test.go | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/vminsert/influx/parser.go b/app/vminsert/influx/parser.go index a2379e8dd..890bf5b81 100644 --- a/app/vminsert/influx/parser.go +++ b/app/vminsert/influx/parser.go @@ -293,8 +293,10 @@ func parseFieldValue(s string, hasQuotedFields bool) (float64, error) { if len(s) < 2 || s[len(s)-1] != '"' { return 0, fmt.Errorf("missing closing quote for quoted field value %s", s) } - // Quoted string is translated to empty value. - return 0, nil + // Try converting quoted string to number, since sometimes Influx agents + // send numbers as strings. + s = s[1 : len(s)-1] + return fastfloat.ParseBestEffort(s), nil } ch := s[len(s)-1] if ch == 'i' { diff --git a/app/vminsert/influx/parser_test.go b/app/vminsert/influx/parser_test.go index 1f0c0d5b1..3668fd70f 100644 --- a/app/vminsert/influx/parser_test.go +++ b/app/vminsert/influx/parser_test.go @@ -241,17 +241,27 @@ func TestRowsUnmarshalSuccess(t *testing.T) { }) // Line with multiple tags, multiple fields and timestamp - f(`system,host=ip-172-16-10-144 uptime_format="3 days, 21:01" 1557761040000000000`, &Rows{ + f(`system,host=ip-172-16-10-144 uptime_format="3 days, 21:01",quoted_float="-1.23",quoted_int="123" 1557761040000000000`, &Rows{ Rows: []Row{{ Measurement: "system", Tags: []Tag{{ Key: "host", Value: "ip-172-16-10-144", }}, - Fields: []Field{{ - Key: "uptime_format", - Value: 0, - }}, + Fields: []Field{ + { + Key: "uptime_format", + Value: 0, + }, + { + Key: "quoted_float", + Value: -1.23, + }, + { + Key: "quoted_int", + Value: 123, + }, + }, Timestamp: 1557761040000000000, }}, })