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
This commit is contained in:
Aliaksandr Valialkin 2019-05-26 22:10:56 +03:00
parent 51ee990902
commit feb6b203a4
2 changed files with 19 additions and 7 deletions

View file

@ -293,8 +293,10 @@ func parseFieldValue(s string, hasQuotedFields bool) (float64, error) {
if len(s) < 2 || s[len(s)-1] != '"' { if len(s) < 2 || s[len(s)-1] != '"' {
return 0, fmt.Errorf("missing closing quote for quoted field value %s", s) return 0, fmt.Errorf("missing closing quote for quoted field value %s", s)
} }
// Quoted string is translated to empty value. // Try converting quoted string to number, since sometimes Influx agents
return 0, nil // send numbers as strings.
s = s[1 : len(s)-1]
return fastfloat.ParseBestEffort(s), nil
} }
ch := s[len(s)-1] ch := s[len(s)-1]
if ch == 'i' { if ch == 'i' {

View file

@ -241,17 +241,27 @@ func TestRowsUnmarshalSuccess(t *testing.T) {
}) })
// Line with multiple tags, multiple fields and timestamp // 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{{ Rows: []Row{{
Measurement: "system", Measurement: "system",
Tags: []Tag{{ Tags: []Tag{{
Key: "host", Key: "host",
Value: "ip-172-16-10-144", Value: "ip-172-16-10-144",
}}, }},
Fields: []Field{{ Fields: []Field{
Key: "uptime_format", {
Value: 0, Key: "uptime_format",
}}, Value: 0,
},
{
Key: "quoted_float",
Value: -1.23,
},
{
Key: "quoted_int",
Value: 123,
},
},
Timestamp: 1557761040000000000, Timestamp: 1557761040000000000,
}}, }},
}) })