Skip to content
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

[Flow Aggregator] Fix throughput calculation in Logstash #2432

Merged
merged 1 commit into from Jul 22, 2021

Conversation

zyiou
Copy link
Contributor

@zyiou zyiou commented Jul 19, 2021

This PR fixes throughput divided by 0 issue happened in Logstash.
Since we introduce conn.StartTime.IsZero() check and update StartTime to time.Now() in previous fix #2308, there are chances that StartTime will be equal or later than StopTime, which may cause incorrect throughput calculation or exception (divided by 0) in Logstash. And we will miss some flow records on Kibana due to this exception when the flow duration is quite short (less than 1 second)

@zyiou zyiou added area/flow-visibility/elk Issues or PRs related to the reference ELK configuration for flow visualization area/flow-visibility/exporter Issues or PRs related to the Flow Exporter functions in the Agent labels Jul 19, 2021
Comment on lines 166 to 168
if newConn.StartTime.IsZero() {
newConn.StartTime = time.Now()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time we poll, we change the start time. This is not correct. We should set it the first time we see the connection. It is different from StopTime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Then there is possibility that startTime is later than stopTime?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes if the connection is only polled once.
To resolve this, let's re-update the stopTime again after updating startTime when the connection is added to the map for the first time.
This should be done only for cases when there is zero startTime.

@@ -278,7 +278,8 @@ func flowStringToAntreaConnection(flow string, zoneFilter uint16) (*flowexporter
return nil, nil
}

// Add current time as stop time.
// Add current time as start and stop time.
conn.StartTime = time.Now()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@codecov-commenter
Copy link

codecov-commenter commented Jul 20, 2021

Codecov Report

Merging #2432 (69d04e7) into main (7469d7e) will increase coverage by 0.18%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2432      +/-   ##
==========================================
+ Coverage   59.63%   59.82%   +0.18%     
==========================================
  Files         284      284              
  Lines       22178    22171       -7     
==========================================
+ Hits        13226    13263      +37     
+ Misses       7527     7486      -41     
+ Partials     1425     1422       -3     
Flag Coverage Δ
kind-e2e-tests 47.01% <100.00%> (+0.14%) ⬆️
unit-tests 41.99% <0.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
.../flowexporter/connections/conntrack_connections.go 80.17% <100.00%> (+1.48%) ⬆️
pkg/apiserver/handlers/endpoint/handler.go 58.82% <0.00%> (-11.77%) ⬇️
pkg/agent/flowexporter/utils.go 60.00% <0.00%> (-6.67%) ⬇️
pkg/agent/agent.go 50.34% <0.00%> (+0.22%) ⬆️
pkg/agent/openflow/client.go 57.88% <0.00%> (+0.73%) ⬆️
pkg/agent/flowexporter/exporter/exporter.go 80.46% <0.00%> (+1.25%) ⬆️
pkg/agent/openflow/pipeline.go 72.97% <0.00%> (+2.59%) ⬆️
pkg/agent/flowexporter/flowrecords/flow_records.go 83.01% <0.00%> (+4.58%) ⬆️
pkg/ipfix/ipfix_process.go 100.00% <0.00%> (+18.18%) ⬆️

Signed-off-by: zyiou <zyiou@vmware.com>
Copy link
Member

@srikartati srikartati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Please mention in the description what is the effect of this bug, i.e., we are missing some flow records on Kibana.

@antoninbas
Copy link
Contributor

You may want to cherry-pick this to release-1.2 as well

@antoninbas
Copy link
Contributor

/skip-all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flow-visibility/elk Issues or PRs related to the reference ELK configuration for flow visualization area/flow-visibility/exporter Issues or PRs related to the Flow Exporter functions in the Agent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants