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

Combine FlowExporter resources initialization in agent.go #2854

Merged
merged 1 commit into from
Nov 4, 2021

Conversation

heanlan
Copy link
Contributor

@heanlan heanlan commented Sep 28, 2021

  1. Include the initializations of priority queue and connection store into flowExporter
  2. Use setter to to inject the denyConnStore into the networkPolicyController

Fixed: #2829

Signed-off-by: heanlan hanlan@vmware.com

@heanlan heanlan force-pushed the flowexporter-initialization branch from eae1ae8 to e457340 Compare September 28, 2021 18:54
@codecov-commenter
Copy link

codecov-commenter commented Sep 28, 2021

Codecov Report

Merging #2854 (80cad1b) into main (fb7ed5c) will increase coverage by 21.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #2854       +/-   ##
===========================================
+ Coverage   40.61%   61.65%   +21.04%     
===========================================
  Files         158      283      +125     
  Lines       19906    23830     +3924     
===========================================
+ Hits         8084    14693     +6609     
+ Misses      11050     7567     -3483     
- Partials      772     1570      +798     
Flag Coverage Δ
kind-e2e-tests 49.24% <100.00%> (?)
unit-tests 40.53% <25.00%> (-0.08%) ⬇️

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

Impacted Files Coverage Δ
...ntroller/networkpolicy/networkpolicy_controller.go 71.25% <100.00%> (+16.81%) ⬆️
pkg/agent/flowexporter/connections/connections.go 77.27% <100.00%> (+33.33%) ⬆️
.../flowexporter/connections/conntrack_connections.go 83.21% <100.00%> (+24.38%) ⬆️
...agent/flowexporter/connections/deny_connections.go 86.15% <100.00%> (+35.38%) ⬆️
pkg/agent/flowexporter/exporter/exporter.go 81.46% <100.00%> (+28.68%) ⬆️
pkg/agent/controller/egress/egress_controller.go 38.32% <0.00%> (-1.47%) ⬇️
pkg/apiserver/handlers/webhook/convert_crd.go 2.56% <0.00%> (ø)
pkg/apiserver/handlers/webhook/mutation_labels.go 24.71% <0.00%> (ø)
...agent/controller/egress/local_ip_detector_linux.go 0.00% <0.00%> (ø)
pkg/agent/util/sysctl/sysctl_linux.go 0.00% <0.00%> (ø)
... and 239 more

@heanlan heanlan force-pushed the flowexporter-initialization branch from e457340 to 245c9d0 Compare September 28, 2021 19:28
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.
I think current function calls are similar to calls with other packages in agent.go.

cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
@srikartati srikartati requested a review from antoninbas October 1, 2021 17:53
@heanlan heanlan force-pushed the flowexporter-initialization branch from 245c9d0 to 84a410c Compare October 1, 2021 18:02
@srikartati srikartati added the area/flow-visibility Issues or PRs related to flow visibility support in Antrea label Oct 1, 2021
srikartati
srikartati previously approved these changes Oct 1, 2021
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

antoninbas
antoninbas previously approved these changes Oct 1, 2021
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

LGTM
I was hoping for more changes. Why don't we have a unique initialization function for the connection store and the flow exporter?

@heanlan heanlan dismissed stale reviews from antoninbas and srikartati via 271f814 October 1, 2021 22:40
@heanlan
Copy link
Contributor Author

heanlan commented Oct 1, 2021

LGTM I was hoping for more changes. Why don't we have a unique initialization function for the connection store and the flow exporter?

Thanks Antonin. denyConnStore cannot be created at the same place with conntrackConnStore and flowExporter. As denyConnStore is required by networkPolicyController, and networkPolicyController is required by flowExporter.
I created a unique function for only conntrackConnStore and flowExporter in the latest commit. If that's not desirable, probably we can still go back with the previous version.

@antoninbas
Copy link
Contributor

@heanlan No I don't think we want that last commit, we should keep things symmetric
However, I do think we could consider using a setter to do the dependency injection; we don't have to pass everything though the constructor. For example, maybe it would make sense to inject the denyConnStore into the networkPolicyController using a setter. This way you do not need to create the denyConnStore before the networkPolicyController. I'll let @srikartati comment on this as well.

@srikartati
Copy link
Member

@heanlan No I don't think we want that last commit, we should keep things symmetric However, I do think we could consider using a setter to do the dependency injection; we don't have to pass everything though the constructor. For example, maybe it would make sense to inject the denyConnStore into the networkPolicyController using a setter. This way you do not need to create the denyConnStore before the networkPolicyController. I'll let @srikartati comment on this as well.

Thanks @antoninbas. Looked into the code more closely. Having a setter in the network policy controller is definitely doable. However, it is better to break the initialization of connection stores and the exporter, and their Run functions. Add them separately like other packages. In this way, we can make sure denyConnStore is not nil when the network policy controller in the agent starts running.

@antoninbas
Copy link
Contributor

this way, we can make sure denyConnStore is not nil when the network policy controller in the agent starts running.

All goroutines are created at the end of the initialization function

@srikartati
Copy link
Member

All goroutines are created at the end of the initialization function

Yes, Flow Exporter pkg structures are being initialized along with the creation of goroutines right now. I just meant that we can modify and follow the similar style as other packages. Then we will have two groups: initialization of structures along with the setter and goroutines creation.

@heanlan heanlan force-pushed the flowexporter-initialization branch from 271f814 to 49a812a Compare October 5, 2021 03:02
@heanlan
Copy link
Contributor Author

heanlan commented Oct 5, 2021

Thanks Antonin and Srikar. In the latest commit, I have

  1. used setter for setting denyConnStore of networkPolicyController
  2. separate connection stores & flowExporter initialization and go routines creation

To make the separation more consistent, shall I move the initialization of NPLAgent - line 362, agentQuerier, apiServer, packetInReasons - line 405-444 above the creation of all go routines?

@srikartati
Copy link
Member

To make the separation more consistent, shall I move the initialization of NPLAgent - line 362, agentQuerier, apiServer, packetInReasons - line 405-444 above the creation of all go routines?

I think it is a small change and ok to do in this PR--you may have to change the title and description. Another option is doing it in a separate PR so that it can be reviewed by others. I am ok with either way and do not have a strong opinion.

@heanlan heanlan force-pushed the flowexporter-initialization branch from b7c2691 to 938c319 Compare October 6, 2021 20:14
@heanlan heanlan changed the title Combine priority queue and connection store initialization Separate initializing resource with creating Goroutine in agent.go Oct 6, 2021
@heanlan heanlan changed the title Separate initializing resource with creating Goroutine in agent.go Separate initializing resources with creating goroutines in agent.go Oct 6, 2021
@heanlan heanlan marked this pull request as draft October 6, 2021 20:24
@heanlan heanlan marked this pull request as ready for review October 6, 2021 22:01
@heanlan
Copy link
Contributor Author

heanlan commented Oct 6, 2021

I think it is a small change and ok to do in this PR--you may have to change the title and description. Another option is doing it in a separate PR so that it can be reviewed by others. I am ok with either way and do not have a strong opinion.

Thanks Srikar. I tried to do the changes in the latest commit. It seems involved in a lot of windows CI failures... I've already been blocked by the go import error for hours https://github.com/antrea-io/antrea/runs/3819830137?check_suite_focus=true
,haven't got chance to look at other failures. I'm thinking I'd probably keep those part unchanged for this PR...

cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
@heanlan heanlan force-pushed the flowexporter-initialization branch from 938c319 to 0f18b58 Compare October 7, 2021 05:26
@heanlan heanlan changed the title Separate initializing resources with creating goroutines in agent.go Combine FlowExporter resources initialization in agent.go Oct 7, 2021
@heanlan heanlan force-pushed the flowexporter-initialization branch from 0f18b58 to a9b8309 Compare October 7, 2021 05:32
@heanlan heanlan added this to the Antrea v1.4 release milestone Oct 29, 2021
@heanlan
Copy link
Contributor Author

heanlan commented Oct 29, 2021

Could you please take another look on this PR @antoninbas @srikartati ? Thanks a lot!

srikartati
srikartati previously approved these changes Oct 29, 2021
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

@heanlan
Copy link
Contributor Author

heanlan commented Oct 29, 2021

squashed the commits

@heanlan
Copy link
Contributor Author

heanlan commented Oct 29, 2021

/test-all

cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
cmd/antrea-agent/agent.go Outdated Show resolved Hide resolved
@heanlan heanlan force-pushed the flowexporter-initialization branch from ee57e6f to eb4c248 Compare November 1, 2021 22:36
antoninbas
antoninbas previously approved these changes Nov 1, 2021
Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

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

one nit, otherwise LGTM

pkg/agent/flowexporter/exporter/exporter.go Outdated Show resolved Hide resolved
@tnqn
Copy link
Member

tnqn commented Nov 3, 2021

@heanlan @antoninbas @srikartati do we plan to include it in v1.4?

@heanlan heanlan force-pushed the flowexporter-initialization branch from 80cad1b to ffa2c55 Compare November 3, 2021 16:37
@heanlan
Copy link
Contributor Author

heanlan commented Nov 3, 2021

I have resolved the conflicts. It's not urgent to be included in 1.4. But if there's no more comments, I think it's ready to be merged.

@heanlan
Copy link
Contributor Author

heanlan commented Nov 3, 2021

/test-all

@heanlan heanlan requested a review from antoninbas November 3, 2021 16:42
@heanlan
Copy link
Contributor Author

heanlan commented Nov 3, 2021

the test failures will be fixed by #2968

antoninbas
antoninbas previously approved these changes Nov 3, 2021
@antoninbas
Copy link
Contributor

@heanlan should you rebase and run the tests again, now that #2968 has been merged?

Signed-off-by: heanlan <hanlan@vmware.com>
@heanlan
Copy link
Contributor Author

heanlan commented Nov 3, 2021

/test-all
/test-integration

@antoninbas antoninbas merged commit c05f30f into antrea-io:main Nov 4, 2021
@heanlan heanlan deleted the flowexporter-initialization branch November 9, 2021 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flow-visibility Issues or PRs related to flow visibility support in Antrea
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create all FlowExporter resources in a function
5 participants