-
Notifications
You must be signed in to change notification settings - Fork 490
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
fix: influx gzip writes #2479
fix: influx gzip writes #2479
Conversation
@@ -571,6 +568,33 @@ func (p Point) Bytes(precision string) []byte { | |||
return bytes | |||
} | |||
|
|||
func (p Point) BytesWithLineFeed(precision string) []byte { | |||
key := imodels.MakeKey([]byte(p.Name), imodels.NewTags(p.Tags)) |
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 is a copy of the func (p Point) Bytes
method, only it adds a line feed to the end of the line to avoid the allocation of doing it afterwards.
@@ -196,6 +197,59 @@ func TestClient_Write(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestClient_WriteLarge(t *testing.T) { | |||
expected := &bytes.Buffer{} |
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 writes a million points to an httptest server and checks to make sure that it is delivered properly. The million points are gzipped.
@@ -78,5 +78,10 @@ func TestPoint_Bytes(t *testing.T) { | |||
t.Errorf("%s: Bytes() mismatch:\n actual: %v\n exp: %v", | |||
test.name, got, exp) | |||
} | |||
if got, exp := string(p.BytesWithLineFeed(test.precision)), test.exp+"\n"; got != exp { | |||
t.Errorf("%s: Bytes() mismatch:\n actual: %v\n exp: %v", |
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.
We want to test not just the Point.Bytes() but also Point.BytesWithLineFeed()
return err | ||
} | ||
|
||
if err := b.WriteByte('\n'); err != nil { |
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.
It's very surprising to me that this would be allocating - what is the allocation caused by?
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.
That line doesn't allocate, but the gzip writer doesn't have a WriteByte, it only has Write, which means allocating a single element byte slice.
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.
Makes sense to me. I prefer the synchronous copy to the go proc pattern unless you are using a channel to handle the EOF.
This is a fix for a data race in kapacitor 1.5.8 where large batch writes were not completely writing to influxdb.