-
Notifications
You must be signed in to change notification settings - Fork 380
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 FlowExporter memory bloat when export process is dead #3994
Conversation
Codecov Report
@@ Coverage Diff @@
## main #3994 +/- ##
==========================================
+ Coverage 64.39% 65.06% +0.67%
==========================================
Files 295 295
Lines 43781 44037 +256
==========================================
+ Hits 28191 28654 +463
+ Misses 13304 13113 -191
+ Partials 2286 2270 -16
|
/test-e2e |
/test-networkpolicy |
/test-conformance |
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.
only small comments, LGTM
func (pq *ExpirePriorityQueue) AddItemToQueue(connKey flowexporter.ConnectionKey, conn *flowexporter.Connection) { | ||
// AddOrOverwriteItemToQueue adds conn with connKey into the queue. If an existing item | ||
// has the same connKey, it will be overwritten by the new item. | ||
func (pq *ExpirePriorityQueue) AddOrOverwriteItemToQueue(connKey flowexporter.ConnectionKey, conn *flowexporter.Connection) { |
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.
I think we could just call this WriteItemToQueue
.
267842d
to
9f011e5
Compare
/test-conformance |
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.
Thanks Shawn. LGTM
@@ -74,6 +74,7 @@ func TestDenyConnectionStore_AddOrUpdateConn(t *testing.T) { | |||
denyConnStore.AddOrUpdateConn(&testFlow, refTime.Add(-(time.Second * 20)), uint64(60)) | |||
expConn := testFlow | |||
expConn.DestinationServicePortName = servicePortName.String() | |||
expConn.LastExportTime = refTime.Add(-(time.Second * 20)) |
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.
I think denyConnStore.AddOrUpdateConn
has already taken care of assigning value to LastExportTime
?
Signed-off-by: Shawn Wang <[email protected]>
/test-conformance |
@wsquan171 I assume that this should be backported? Could you take care of it? |
When flow exporter is enabled, but failed to connect to downstream IPFIX collector, connections added to the priority queue inside flow exporter won't be expired and removed from queue, causing memory to bloat. Furthermore, connection store polling will remove conn from its
connections
map when the flow is no longer in conntrack, but not the related items in priority queue. When a new flow with same flow key is reestablished, a duplicated item with same key will be added to the queue, while the reference to the old one is lost, essentially causing memory leak.This change addresses above issue in the following aspects:
connections
map and the priority queue. Since CS polling is independent of exporting process liveness, this allows clean up to be done without connection to collector.Connection.LastExportTime
to be connection start time to make sure CS polling logic works properly when the exporting process is dead. Previously LastExportTime will only be filled by exporting process at the time of export, causing zero value to be compare in certain cases.Benchmark test
BenchmarkExportConntrackConns
did not show observable difference before and after change.Fixes item 1 and 2 in #3972. Severity of item 3 is lower, which will be addressed in a later change.