feat(collector): use FlowSummary to reduce conntrack peak memory#30
Merged
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.
Contributor
Author
There was a problem hiding this comment.
updated to depend on ClickHouse forked conntrack
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
andreev-io
approved these changes
Mar 23, 2026
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
github.com/ti-mo/conntrackto the ClickHouse fork (github.com/ClickHouse/conntrack) which provides a nativeFlowSummarystruct andDumpFlowSummaryFilterAPI.DumpFlowSummaryFilterto dump only the fields kubenetmon needs (tuples and counters) directly from the kernel, avoiding allocation of the heavierconntrack.Flowstruct with its unused fields (Status,Timeout,ProtoInfo,Labels,SeqAdj,SynProxy, etc.).shouldIgnoreFlowand all related code to operate onconntrack.FlowSummaryinstead ofconntrack.Flow.Mirrors ClickHouse/data-plane-application#31052 for the OSS codebase.
Test plan
TestShouldIgnoreFlowsub-tests to useFlowSummaryTestCollectintegration test passes (exercises the full dump → convert → send path)go test ./...)🤖 Generated with Claude Code