graphite: log the field name when we encounter a value parse failure

The java metrics library will dump anything and everything to graphite leading to many error messages like:

[graphite] 2015/04/19 10:11:46 unable to parse data: strconv.ParseFloat: parsing "[J@4deff1ac": invalid syntax
[graphite] 2015/04/19 10:11:46 unable to parse data: strconv.ParseFloat: parsing "[J@5b8c4bb5": invalid syntax

It makes sense to include the name field given that the graphite parsing code has already validated the name and tags by the time the value is parsed.
The field name can then be used to filter the offending field from the stats publish.

The ParseFloat related error messages have been modified such they include the field name and the value that was being parsed (value|timestamp).
pull/2342/head
Mark Guzman 2015-04-19 10:17:35 -04:00
parent 6d6db1fb2b
commit b689231183
No known key found for this signature in database
GPG Key ID: 486EC6834A8383A2
2 changed files with 5 additions and 5 deletions

View File

@ -83,7 +83,7 @@ func (p *Parser) Parse(line string) (influxdb.Point, error) {
// Parse value.
v, err := strconv.ParseFloat(fields[1], 64)
if err != nil {
return influxdb.Point{}, err
return influxdb.Point{}, fmt.Errorf("field \"%s\" value: %s", fields[0], err)
}
fieldValues := make(map[string]interface{})
@ -92,7 +92,7 @@ func (p *Parser) Parse(line string) (influxdb.Point, error) {
// Parse timestamp.
unixTime, err := strconv.ParseFloat(fields[2], 64)
if err != nil {
return influxdb.Point{}, err
return influxdb.Point{}, fmt.Errorf("field \"%s\" timestamp: %s", fields[0], err)
}
// Check if we have fractional seconds

View File

@ -174,17 +174,17 @@ func Test_DecodeMetric(t *testing.T) {
{
test: "should fail parsing invalid float",
line: `cpu 50.554z 1419972457825`,
err: `strconv.ParseFloat: parsing "50.554z": invalid syntax`,
err: `field "cpu" value: strconv.ParseFloat: parsing "50.554z": invalid syntax`,
},
{
test: "should fail parsing invalid int",
line: `cpu 50z 1419972457825`,
err: `strconv.ParseFloat: parsing "50z": invalid syntax`,
err: `field "cpu" value: strconv.ParseFloat: parsing "50z": invalid syntax`,
},
{
test: "should fail parsing invalid time",
line: `cpu 50.554 14199724z57825`,
err: `strconv.ParseFloat: parsing "14199724z57825": invalid syntax`,
err: `field "cpu" timestamp: strconv.ParseFloat: parsing "14199724z57825": invalid syntax`,
},
}