feat(collector): use FlowSummary to reduce conntrack peak memory#30
Open
sichenzhao wants to merge 2 commits intomainfrom
Open
feat(collector): use FlowSummary to reduce conntrack peak memory#30sichenzhao wants to merge 2 commits intomainfrom
sichenzhao wants to merge 2 commits intomainfrom
Conversation
Introduce a lightweight FlowSummary struct that holds only the fields kubenetmon actually uses (tuples and counters) from conntrack.Flow. After each conntrack dump the full []conntrack.Flow is immediately converted to []FlowSummary and released, allowing the GC to reclaim the heavier Flow objects (which carry unused fields like Status, Timeout, ProtoInfo, Labels, SeqAdj, SynProxy, etc.) before the send loop begins. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The `rawFlows = nil` assignment was flagged by golangci-lint (ineffassign) since the variable is not read after that point. The local variable becomes unreachable after toFlowSummaries returns, allowing the GC to collect it without the explicit nil assignment. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
andreev-io
requested changes
Mar 20, 2026
|
|
||
| now := collector.clock.Now() | ||
| flows, err := collector.conntrack.Dump(&conntrack.DumpOptions{ZeroCounters: true}) | ||
| rawFlows, err := collector.conntrack.Dump(&conntrack.DumpOptions{ZeroCounters: true}) |
Member
There was a problem hiding this comment.
Thank you for putting this up. I think we should swap in conntrack for a fork like we do internally and replace the Flow struct at that level during conversion from netlink messages. Otherwise this change may do more harm than good, since it will be allocating 3 times for each flow.
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.
Summary
FlowSummarystruct containing only the fields kubenetmon uses fromconntrack.Flow(tuples and counters), dropping unused fields likeStatus,Timeout,ProtoInfo,Labels,SeqAdj,SynProxy, etc.[]conntrack.Flowto[]FlowSummaryimmediately after each conntrack dump and nils the original slice, allowing the GC to reclaim the heavier objects before the gRPC send loop begins.shouldIgnoreFlowto operate on*FlowSummaryinstead of*conntrack.Flow.ConntrackInterfaceand its mock remain unchanged; the conversion is internal to the collector.Inspired by ClickHouse/data-plane-application#31052, adapted for the OSS codebase which uses
github.com/ti-mo/conntrackinstead of the internal fork.Test plan
TestToFlowSummarieswith sub-tests for empty input, field extraction (verifying dropped fields), and multi-flow conversionTestShouldIgnoreFlowsub-tests to useFlowSummaryTestCollectintegration test passes (exercises the full dump → convert → send path)toFlowSummariesandshouldIgnoreFlowboth at 100% coveragego test ./...)🤖 Generated with Claude Code