-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add uint support into the write protocol #8835
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -523,6 +523,7 @@ func TestParsePointBadNumber(t *testing.T) { | |
"cpu v=-e-e-e ", | ||
"cpu v=42+3 ", | ||
"cpu v= ", | ||
"cpu v=-123u", | ||
} { | ||
_, err := models.ParsePointsString(tt) | ||
if err == nil { | ||
|
@@ -567,10 +568,17 @@ func TestParsePointMinInt64(t *testing.T) { | |
} | ||
|
||
// min int | ||
_, err = models.ParsePointsString(`cpu,host=serverA,region=us-west value=-9223372036854775808i`) | ||
p, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=-9223372036854775808i`) | ||
if err != nil { | ||
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=-9223372036854775808i`, err) | ||
} | ||
fields, err := p[0].Fields() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if exp, got := int64(-9223372036854775808), fields["value"].(int64); exp != got { | ||
t.Fatalf("ParsePoints Value mismatch. \nexp: %v\ngot: %v", exp, got) | ||
} | ||
|
||
// leading zeros | ||
_, err = models.ParsePointsString(`cpu,host=serverA,region=us-west value=-0009223372036854775808i`) | ||
|
@@ -587,10 +595,17 @@ func TestParsePointMaxFloat64(t *testing.T) { | |
} | ||
|
||
// max float | ||
_, err = models.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, string(maxFloat64))) | ||
p, err := models.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, string(maxFloat64))) | ||
if err != nil { | ||
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=9223372036854775807`, err) | ||
} | ||
fields, err := p[0].Fields() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if exp, got := math.MaxFloat64, fields["value"].(float64); exp != got { | ||
t.Fatalf("ParsePoints Value mismatch. \nexp: %v\ngot: %v", exp, got) | ||
} | ||
|
||
// leading zeros | ||
_, err = models.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, "0000"+string(maxFloat64))) | ||
|
@@ -607,10 +622,17 @@ func TestParsePointMinFloat64(t *testing.T) { | |
} | ||
|
||
// min float | ||
_, err = models.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, string(minFloat64))) | ||
p, err := models.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, string(minFloat64))) | ||
if err != nil { | ||
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=...`, err) | ||
} | ||
fields, err := p[0].Fields() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if exp, got := -math.MaxFloat64, fields["value"].(float64); exp != got { | ||
t.Fatalf("ParsePoints Value mismatch. \nexp: %v\ngot: %v", exp, got) | ||
} | ||
|
||
// leading zeros | ||
_, err = models.ParsePointsString(fmt.Sprintf(`cpu,host=serverA,region=us-west value=%s`, "-0000000"+string(minFloat64)[1:])) | ||
|
@@ -619,6 +641,61 @@ func TestParsePointMinFloat64(t *testing.T) { | |
} | ||
} | ||
|
||
func TestParsePointMaxUint64(t *testing.T) { | ||
// out of range | ||
_, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=18446744073709551616u`) | ||
exp := `unable to parse 'cpu,host=serverA,region=us-west value=18446744073709551616u': unable to parse unsigned 18446744073709551616: strconv.ParseUint: parsing "18446744073709551616": value out of range` | ||
if err == nil || (err != nil && err.Error() != exp) { | ||
t.Fatalf("Error mismatch:\nexp: %s\ngot: %v", exp, err) | ||
} | ||
|
||
// max int | ||
p, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=18446744073709551615u`) | ||
if err != nil { | ||
t.Fatalf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=18446744073709551615u`, err) | ||
} | ||
fields, err := p[0].Fields() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if exp, got := uint64(18446744073709551615), fields["value"].(uint64); exp != got { | ||
t.Fatalf("ParsePoints Value mismatch. \nexp: %v\ngot: %v", exp, got) | ||
} | ||
|
||
// leading zeros | ||
_, err = models.ParsePointsString(`cpu,host=serverA,region=us-west value=00018446744073709551615u`) | ||
if err != nil { | ||
t.Fatalf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=00018446744073709551615u`, err) | ||
} | ||
} | ||
|
||
func TestParsePointMinUint64(t *testing.T) { | ||
// out of range | ||
_, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=--1u`) | ||
if err == nil { | ||
t.Errorf(`ParsePoints("%s") mismatch. got nil, exp error`, `cpu,host=serverA,region=us-west value=-1u`) | ||
} | ||
|
||
// min int | ||
p, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=0u`) | ||
if err != nil { | ||
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=0u`, err) | ||
} | ||
fields, err := p[0].Fields() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if exp, got := uint64(0), fields["value"].(uint64); exp != got { | ||
t.Fatalf("ParsePoints Value mismatch. \nexp: %v\ngot: %v", exp, got) | ||
} | ||
|
||
// leading zeros | ||
_, err = models.ParsePointsString(`cpu,host=serverA,region=us-west value=0000u`) | ||
if err != nil { | ||
t.Errorf(`ParsePoints("%s") mismatch. got %v, exp nil`, `cpu,host=serverA,region=us-west value=0000u`, err) | ||
} | ||
} | ||
|
||
func TestParsePointNumberNonNumeric(t *testing.T) { | ||
_, err := models.ParsePointsString(`cpu,host=serverA,region=us-west value=.1a`) | ||
if err == nil { | ||
|
@@ -2148,6 +2225,8 @@ func toFields(fi models.FieldIterator) models.Fields { | |
v, err = fi.FloatValue() | ||
case models.Integer: | ||
v, err = fi.IntegerValue() | ||
case models.Unsigned: | ||
v, err = fi.UnsignedValue() | ||
case models.String: | ||
v = fi.StringValue() | ||
case models.Boolean: | ||
|
@@ -2173,7 +2252,7 @@ m v=42i | |
m v="string" | ||
m v=true | ||
m v="string\"with\"escapes" | ||
m v=42i,f=42,g=42.314 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I might be reading the test incompletely - but need to be sure we have tests for a negative unsigned int (error path), for max value, and for something greater than the max value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add those. |
||
m v=42i,f=42,g=42.314,u=123u | ||
m a=2i,b=3i,c=true,d="stuff",e=-0.23,f=123.456 | ||
`) | ||
|
||
|
@@ -2251,3 +2330,8 @@ func BenchmarkEscapeString_QuotesAndBackslashes(b *testing.B) { | |
sink = [...]string{models.EscapeStringField(s1), models.EscapeStringField(s2)} | ||
} | ||
} | ||
|
||
func init() { | ||
// Force uint support to be enabled for testing. | ||
models.EnableUintSupport() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build uint uint64 | ||
|
||
package models | ||
|
||
func init() { | ||
EnableUintSupport() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check is redundant with the initial check at line 833?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe so. The check at line 833 prevents a person from writing
m=-
. This checks to make sure a negative wasn't used while looking at an unsigned integer.