Bound the in-memory batch buffer to prevent unbounded growth - #7
Closed
Dodothereal wants to merge 2 commits into
Closed
Bound the in-memory batch buffer to prevent unbounded growth#7Dodothereal wants to merge 2 commits into
Dodothereal wants to merge 2 commits into
Conversation
- Modified Batch struct to include a maximum size limit - Added NewBatch factory function to create batches with a specified max size - Updated Add method to drop excess points when the batch would exceed its maximum size - Updated app/run.go to use the NewBatch factory function - Added comprehensive unit tests for the batch size limiting functionality Fixes kanshi-dev#4
- Modified Batch struct to include a maximum size limit and drop oldest entries when exceeded - Added NewBatch factory function to create batches with a specified max size - Updated Add method to drop oldest points first to keep newest data when buffer overflows - Added dropped counter and periodic logging of dropped packets - Updated app/run.go to use NewBatch and log dropped counts on flush - Added comprehensive unit tests for batch size limiting, dropping policy, and counter Fixes kanshi-dev#4
Johnyoat
reviewed
Jul 21, 2026
Johnyoat
left a comment
Member
There was a problem hiding this comment.
Thank you for you submission. Do you understand go or just vibe coded the solutions?
Johnyoat
marked this pull request as draft
July 21, 2026 20:00
Member
|
Converted to draft while agent #4 is resolved without code. The current synchronous loop cannot collect while |
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.
Bound the in-memory batch buffer to prevent unbounded growth
Summary
This PR addresses issue #4 by implementing a bound on the in-memory batch buffer to prevent unbounded growth.
Changes
internal/pipeline/batch.go:
maxfield to theBatchstruct to track the maximum size.droppedcounter to track the number of points discarded due to size limits.NewBatch(max int) *Batchfactory function to create batches with a configured maximum size.Addmethod to drop the oldest points first when the buffer would exceed its maximum size, thereby preserving the newest data (which is most valuable for monitoring).Addmethod now returns the number of points dropped in that call.Dropped() int64andDroppedReset() int64methods to read and reset the dropped counter.internal/app/run.go:
&pipeline.Batch{}topipeline.NewBatch(cfg.BatchMax)to use the new factory.sendBatch, added logging of dropped points (viabatch.DroppedReset()) at INFO level whenever the batch is flushed, providing periodic insight into data loss due to the size limit.internal/pipeline/batch_test.go:
Testing
KANSHI_BATCH_MAXenvironment variable (default 100).Fixes #4
AI assistance disclosure
This contribution was produced by an autonomous AI coding agent (Claude Code) that @Dodothereal operates and monitors. @Dodothereal is accountable for it, will address review feedback promptly, and will close this PR immediately if this kind of contribution is unwelcome in this project. Commits carry an
Assisted-by: Claude Codetrailer.