Fix bug parsing default timestamps with modified precision (#2949)

(cherry picked from commit 9276318faf)
This commit is contained in:
Daniel Nelson 2017-06-23 10:59:04 -07:00 committed by Daniel Nelson
parent 0231b3ea0a
commit 1e7750c502
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
2 changed files with 16 additions and 2 deletions

View File

@ -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

View File

@ -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 {