feat(line-protocol): add splitPoints for oversized write batches - #53
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #37.
What
Adds
splitPoints(points, { maxBytes, precision }), a generator that cuts a batch of points into Line Protocol payloads none larger thanmaxBytes.writePoints()still sends one request however many points it is given; this is the explicit escape hatch for batches large enough to hit a server limit.Why it is shaped this way
Sizing is by encoded UTF-8 bytes rather than point count. Points vary enormously in encoded length, and the limit a server enforces is measured in bytes, so a point-count cap would be a guess dressed up as a guarantee. The newlines between lines are counted too, so a payload that fits here fits on the wire.
There is no default
maxBytesand nothing splits unless a caller asks. A default would be this library guessing at a server limit it cannot see, and it would silently change what existing writes do.It is a generator, so points are serialized as they are consumed. A caller writing chunk by chunk never holds the whole batch in memory as one string.
Sending the chunks is left to the caller. If the seventh chunk fails, the first six are already written, and only the caller can decide what that means for their data. Hiding the loop inside a write would turn one call into many requests and make partial success invisible.
A single point larger than
maxBytesthrows aRangeErrornaming its index and encoded size, because no split can satisfy the request and emitting an oversized payload anyway would break the guarantee the caller asked for. A non-positive or non-integermaxBytesthrows aTypeError.Tests
Unit tests cover exact-fit boundaries, the newline accounting, multi-byte characters, empty input, precision pass-through, lazy evaluation, and both throw paths. An integration test writes a 60-point batch through a 400-byte limit against a live server and asserts all 60 rows land, so the chunking is proven to produce payloads the server actually accepts rather than only ones that satisfy the unit test's arithmetic.