From 87f2b44566204efc521162c94e13a0999646a782 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 23 Jun 2017 10:59:04 -0700 Subject: [PATCH] Fix bug parsing default timestamps with modified precision (#2949) --- metric/parse.go | 2 +- metric/parse_test.go | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/metric/parse.go b/metric/parse.go index 92dc4918b..72057fb39 100644 --- a/metric/parse.go +++ b/metric/parse.go @@ -129,7 +129,7 @@ func parseMetric(buf []byte, // apply precision multiplier var nsec int64 multiplier := getPrecisionMultiplier(precision) - if multiplier > 1 { + if len(ts) > 0 && multiplier > 1 { tsint, err := parseIntBytes(ts, 10, 64) if err != nil { return nil, err diff --git a/metric/parse_test.go b/metric/parse_test.go index 89ade9f56..27185224a 100644 --- a/metric/parse_test.go +++ b/metric/parse_test.go @@ -380,11 +380,25 @@ func TestParsePrecision(t *testing.T) { } { metrics, err := ParseWithDefaultTimePrecision( []byte(tt.line+"\n"), time.Now(), tt.precision) - assert.NoError(t, err, tt) + assert.NoError(t, err) assert.Equal(t, tt.expected, metrics[0].UnixNano()) } } +func TestParsePrecisionUnsetTime(t *testing.T) { + for _, tt := range []struct { + line string + precision string + }{ + {"test v=42", "s"}, + {"test v=42", "ns"}, + } { + _, err := ParseWithDefaultTimePrecision( + []byte(tt.line+"\n"), time.Now(), tt.precision) + assert.NoError(t, err) + } +} + func TestParseMaxKeyLength(t *testing.T) { key := "" for {