From 3244d3f213fef84aef5a0388419f08ad0c363c6f Mon Sep 17 00:00:00 2001 From: gunnaraasen Date: Mon, 19 Oct 2015 10:40:18 -0700 Subject: [PATCH 1/3] Handle negative timestamps --- models/points.go | 7 ++++- models/points_test.go | 61 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/models/points.go b/models/points.go index 883960bdc45..277748679da 100644 --- a/models/points.go +++ b/models/points.go @@ -531,9 +531,14 @@ func scanTime(buf []byte, i int) (int, []byte, error) { break } - // Timestamps should integers, make sure they are so we don't need to actually + // Timestamps should be integers, make sure they are so we don't need to actually // parse the timestamp until needed if buf[i] < '0' || buf[i] > '9' { + // Handle negative timestamps + if i == start && buf[i] == '-' { + i += 1 + continue + } return i, buf[start:i], fmt.Errorf("bad timestamp") } diff --git a/models/points_test.go b/models/points_test.go index 37618998bc7..4bd8641ba46 100644 --- a/models/points_test.go +++ b/models/points_test.go @@ -975,6 +975,65 @@ func TestParsePointUnicodeString(t *testing.T) { ) } +func TestParsePointNegativeTimestamp(t *testing.T) { + test(t, `cpu value=1 -1`, + models.NewPoint( + "cpu", + models.Tags{}, + models.Fields{ + "value": 1.0, + }, + time.Unix(0, -1)), + ) +} + +func TestParsePointMaxTimestamp(t *testing.T) { + test(t, `cpu value=1 9223372036854775807`, + models.NewPoint( + "cpu", + models.Tags{}, + models.Fields{ + "value": 1.0, + }, + time.Unix(0, int64(1<<63-1))), + ) +} + +func TestParsePointMinTimestamp(t *testing.T) { + test(t, `cpu value=1 -9223372036854775807`, + models.NewPoint( + "cpu", + models.Tags{}, + models.Fields{ + "value": 1.0, + }, + time.Unix(0, -int64(1<<63-1))), + ) +} + +func TestParsePointInvalidTimestamp(t *testing.T) { + _, err := models.ParsePointsString("cpu value=1 9223372036854775808") + if err == nil { + t.Fatalf("ParsePoints failed: %v", err) + } + _, err = models.ParsePointsString("cpu value=1 -92233720368547758078") + if err == nil { + t.Fatalf("ParsePoints failed: %v", err) + } + _, err = models.ParsePointsString("cpu value=1 -") + if err == nil { + t.Fatalf("ParsePoints failed: %v", err) + } + _, err = models.ParsePointsString("cpu value=1 -/") + if err == nil { + t.Fatalf("ParsePoints failed: %v", err) + } + _, err = models.ParsePointsString("cpu value=1 -1?") + if err == nil { + t.Fatalf("ParsePoints failed: %v", err) + } +} + func TestNewPointFloatWithoutDecimal(t *testing.T) { test(t, `cpu value=1 1000000000`, models.NewPoint( @@ -1064,7 +1123,6 @@ func TestNewPointNaN(t *testing.T) { }, time.Unix(0, 0)), ) - } func TestNewPointLargeNumberOfTags(t *testing.T) { @@ -1105,7 +1163,6 @@ func TestParsePointIntsFloats(t *testing.T) { if _, ok := pt.Fields()["float2"].(float64); !ok { t.Errorf("ParsePoint() float field mismatch: got %T, exp %T", pt.Fields()["float64"], float64(12.1)) } - } func TestParsePointKeyUnsorted(t *testing.T) { From 44c5e33c2c102c54a22fa107d58ed6cbef0169a8 Mon Sep 17 00:00:00 2001 From: gunnaraasen Date: Mon, 19 Oct 2015 10:51:20 -0700 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7b9c14719d..161e2d9a2f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,7 @@ - [#4475](https://github.com/influxdb/influxdb/issues/4475): Fix SHOW TAG VALUES error message. - [#4486](https://github.com/influxdb/influxdb/pull/4486): Fix missing comments for runner package - [#4497](https://github.com/influxdb/influxdb/pull/4497): Fix sequence in meta proto +- [#3367](https://github.com/influxdb/influxdb/issues/3367): Negative timestamps are parsed correctly by the line protocol. ## v0.9.4 [2015-09-14] From 859d2a46e886e869d907fd277d627fd719a98dab Mon Sep 17 00:00:00 2001 From: gunnaraasen Date: Mon, 19 Oct 2015 13:06:13 -0700 Subject: [PATCH 3/3] Add test for 1- timestamp --- models/points_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/models/points_test.go b/models/points_test.go index 4bd8641ba46..c6b7f08d9ba 100644 --- a/models/points_test.go +++ b/models/points_test.go @@ -1032,6 +1032,10 @@ func TestParsePointInvalidTimestamp(t *testing.T) { if err == nil { t.Fatalf("ParsePoints failed: %v", err) } + _, err = models.ParsePointsString("cpu value=1 1-") + if err == nil { + t.Fatalf("ParsePoints failed: %v", err) + } } func TestNewPointFloatWithoutDecimal(t *testing.T) {