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

Support antctl in the flow aggregator #2878

Merged
merged 1 commit into from
Nov 9, 2021

Conversation

yanjunz97
Copy link
Contributor

@yanjunz97 yanjunz97 commented Oct 8, 2021

This commit supports antctl in the flow aggregator pod. It supports three commands only running locally inside the flow-aggregator container.

  1. Showing or changing log verbosity level: The antctl get log-level command works the same as the one in antrea-agent or antrea-controller.
  2. Dumping flow records: The antctl get flowrecords [-o json] command can dump all matched flow records. The command provides a compact display of the flow records in the default table output format. Using the json or yaml antctl output format can print more information of the flow records. The command supports the 5-tuple flow key or a subset of 5-tuples as a filter. A 5-tuple flow key contains Source IP, Destination IP, Source Port, Destination Port and Transport Protocol. If the filter is empty, all flow records will be dumped.
    Example outputs of dumping flow records:
$ antctl get flowrecords --srcip 10.10.0.1 --srcport 50497 -o json
[
  {
    "destinationClusterIPv4": "0.0.0.0",
    "destinationIPv4Address": "10.10.1.2",
    "destinationNodeName": "k8s-node-worker-1",
    "destinationPodName": "coredns-78fcd69978-x2twv",
    "destinationPodNamespace": "kube-system",
    "destinationServicePort": 0,
    "destinationServicePortName": "",
    "destinationTransportPort": 53,
    "egressNetworkPolicyName": "",
    "egressNetworkPolicyNamespace": "",
    "egressNetworkPolicyRuleAction": 0,
    "egressNetworkPolicyRuleName": "",
    "egressNetworkPolicyType": 0,
    "flowEndReason": 3,
    "flowEndSeconds": 1635546893,
    "flowStartSeconds": 1635546867,
    "flowType": 2,
    "ingressNetworkPolicyName": "",
    "ingressNetworkPolicyNamespace": "",
    "ingressNetworkPolicyRuleAction": 0,
    "ingressNetworkPolicyRuleName": "",
    "ingressNetworkPolicyType": 0,
    "octetDeltaCount": 99,
    "octetDeltaCountFromDestinationNode": 99,
    "octetDeltaCountFromSourceNode": 0,
    "octetTotalCount": 99,
    "octetTotalCountFromDestinationNode": 99,
    "octetTotalCountFromSourceNode": 0,
    "packetDeltaCount": 1,
    "packetDeltaCountFromDestinationNode": 1,
    "packetDeltaCountFromSourceNode": 0,
    "packetTotalCount": 1,
    "packetTotalCountFromDestinationNode": 1,
    "packetTotalCountFromSourceNode": 0,
    "protocolIdentifier": 17,
    "reverseOctetDeltaCount": 192,
    "reverseOctetDeltaCountFromDestinationNode": 192,
    "reverseOctetDeltaCountFromSourceNode": 0,
    "reverseOctetTotalCount": 192,
    "reverseOctetTotalCountFromDestinationNode": 192,
    "reverseOctetTotalCountFromSourceNode": 0,
    "reversePacketDeltaCount": 1,
    "reversePacketDeltaCountFromDestinationNode": 1,
    "reversePacketDeltaCountFromSourceNode": 0,
    "reversePacketTotalCount": 1,
    "reversePacketTotalCountFromDestinationNode": 1,
    "reversePacketTotalCountFromSourceNode": 0,
    "sourceIPv4Address": "10.10.0.1",
    "sourceNodeName": "",
    "sourcePodName": "",
    "sourcePodNamespace": "",
    "sourceTransportPort": 50497,
    "tcpState": ""
  }
]
  1. Flow records metrics: The antctl get recordmetrics command can print all metrics related to the Flow Aggregator. The metrics include number of records received by the collector process in the Flow Aggregator, number of records exported by the Flow Aggregator, number of active flows that are being tracked, number of exporters connected to the Flow Aggregator

Fixes: #1966

@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from 387ef70 to fac4249 Compare October 8, 2021 23:06
@yanjunz97 yanjunz97 marked this pull request as draft October 8, 2021 23:14
@codecov-commenter
Copy link

codecov-commenter commented Oct 8, 2021

Codecov Report

Merging #2878 (7c797d5) into main (ca264d3) will decrease coverage by 0.15%.
The diff coverage is 39.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2878      +/-   ##
==========================================
- Coverage   61.06%   60.91%   -0.16%     
==========================================
  Files         289      292       +3     
  Lines       24548    24698     +150     
==========================================
+ Hits        14991    15045      +54     
- Misses       7938     8015      +77     
- Partials     1619     1638      +19     
Flag Coverage Δ
kind-e2e-tests 48.16% <45.66%> (-0.03%) ⬇️
unit-tests 40.14% <6.25%> (-0.07%) ⬇️

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

Impacted Files Coverage Δ
pkg/antctl/antctl.go 66.66% <ø> (ø)
pkg/antctl/client.go 1.29% <0.00%> (-0.10%) ⬇️
pkg/antctl/command_definition.go 51.97% <0.00%> (-2.01%) ⬇️
pkg/antctl/transform/common/transform.go 0.00% <0.00%> (ø)
...gregator/apiserver/handlers/flowrecords/handler.go 23.63% <23.63%> (ø)
...egator/apiserver/handlers/recordmetrics/handler.go 44.44% <44.44%> (ø)
pkg/antctl/command_list.go 47.69% <50.00%> (+0.07%) ⬆️
pkg/flowaggregator/apiserver/apiserver.go 65.21% <65.21%> (ø)
pkg/flowaggregator/flowaggregator.go 68.19% <100.00%> (+0.63%) ⬆️
pkg/ipfix/ipfix_intermediate.go 89.47% <100.00%> (+0.58%) ⬆️
... and 10 more

@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from fac4249 to 579433b Compare October 11, 2021 21:56
@lgtm-com
Copy link

lgtm-com bot commented Oct 11, 2021

This pull request introduces 2 alerts when merging 579433b into 4d0eea7 - view on LGTM.com

new alerts:

  • 2 for Incorrect conversion between integer types

@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from 579433b to a8900d4 Compare October 11, 2021 23:20
@antrea-io antrea-io deleted a comment from lgtm-com bot Oct 11, 2021
@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from a8900d4 to d40f7da Compare October 11, 2021 23:32
@yanjunz97 yanjunz97 marked this pull request as ready for review October 12, 2021 00:00
Copy link
Contributor

@dreamtalen dreamtalen left a comment

Choose a reason for hiding this comment

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

Thanks Yanjun working on this.

docs/antctl.md Outdated Show resolved Hide resolved
docs/antctl.md Outdated Show resolved Hide resolved
docs/antctl.md Show resolved Hide resolved
docs/antctl.md Outdated Show resolved Hide resolved
pkg/antctl/antctl.go Outdated Show resolved Hide resolved
pkg/flowaggregator/flowaggregator.go Outdated Show resolved Hide resolved
pkg/antctl/antctl.go Outdated Show resolved Hide resolved
@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from 1b3502a to ff5fed0 Compare October 12, 2021 17:58
@abhiraut abhiraut added area/flow-visibility/aggregator Issues or PRs related to Flow Aggregator review-manager-test labels Oct 12, 2021
@abhiraut abhiraut added the area/component/antctl Issues or PRs releated to the command line interface component label Oct 12, 2021
@github-actions github-actions bot requested review from jianjuns and tnqn October 12, 2021 19:20
@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch 2 times, most recently from 3c7598e to 2f7a180 Compare October 14, 2021 01:20
test/e2e/antctl_test.go Outdated Show resolved Hide resolved
@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from 2f7a180 to 2f13613 Compare October 14, 2021 22:42
@github-actions github-actions bot requested a review from dreamtalen October 14, 2021 22:43
@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from 2f13613 to 01f9374 Compare October 18, 2021 17:00
build/yamls/flow-aggregator.yml Outdated Show resolved Hide resolved
docs/antctl.md Show resolved Hide resolved
docs/antctl.md Outdated
verbosity level of Antrea Controller or Agent using the `antctl log-level`
command. The command can only run locally inside the `antrea-controller` or
`antrea-agent` container.
verbosity level of Antrea Controller, Antrea Agent or Flow Aggregator using the
Copy link
Member

Choose a reason for hiding this comment

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

Add this separately for Flow Aggregator, as the support version number is different

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Use 1.4 for now, if it does not catch up the release 1.4, will update to later version.

docs/troubleshooting.md Outdated Show resolved Hide resolved
pkg/apis/ports.go Outdated Show resolved Hide resolved
docs/antctl.md Show resolved Hide resolved
docs/antctl.md Outdated Show resolved Hide resolved
docs/antctl.md Outdated Show resolved Hide resolved
pkg/antctl/antctl.go Outdated Show resolved Hide resolved
pkg/antctl/antctl.go Outdated Show resolved Hide resolved
pkg/antctl/antctl.go Outdated Show resolved Hide resolved
@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from 01f9374 to 917c66d Compare October 18, 2021 23:32
@yanjunz97
Copy link
Contributor Author

@antoninbas @srikartati Would you like to take another look at this PR before I upgrade go-ipfix to a new version? Thanks a lot!

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.

It looks good to me @yanjunz97

docs/antctl.md Outdated Show resolved Hide resolved
docs/antctl.md Outdated Show resolved Hide resolved
docs/antctl.md Outdated Show resolved Hide resolved
docs/antctl.md Outdated Show resolved Hide resolved
docs/antctl.md Outdated Show resolved Hide resolved
docs/network-flow-visibility.md Outdated Show resolved Hide resolved
docs/network-flow-visibility.md Outdated Show resolved Hide resolved
pkg/antctl/antctl.go Outdated Show resolved Hide resolved
test/e2e/antctl_test.go Outdated Show resolved Hide resolved
Comment on lines 65 to 60
func TestAntctlFlowAggregator(t *testing.T) {
skipIfHasWindowsNodes(t)
skipIfNotRequired(t, "mode-irrelevant")

data, _, _, err := setupTestWithIPFIXCollector(t)
if err != nil {
t.Fatalf("Error when setting up test: %v", err)
}
defer teardownFlowAggregator(t, data)
defer teardownTest(t, data)

t.Run("testAntctlFlowAggregatorLocalAccess", func(t *testing.T) {
testAntctlFlowAggregatorLocalAccess(t, data)
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is unfortunate that we have to setup everything just for this small test, then tear it down. Can we merge this test with the other FlowAggregator e2e tests instead, so we only do the set up once?

Copy link
Contributor Author

@yanjunz97 yanjunz97 Nov 3, 2021

Choose a reason for hiding this comment

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

I have tried to merge the tests by using setupTestWithIPFIXCollector for all antctl test, but noticed some of the testAntctlControllerRemoteAccess may fail when using coverage on CI. Still looking for the reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

solved

Copy link
Contributor

Choose a reason for hiding this comment

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

it's not really what I had in mind. We are still calling setupTestWithIPFIXCollector twice (once for antctl tests and once for the Flow Aggregator tests). We should try to call it once IMO, and move the antctl tests for the Flow Aggregator to test/e2e/flowaggregator_test.go.

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, thanks. Updated.

@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch 4 times, most recently from 5c507aa to 647965c Compare November 4, 2021 23:08
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.

2 small comments, otherwise LGTM

Suggestions for follow-up PRs:

  • ability to filter based on K8s names instead of network header fields
  • use Prometheus to export FlowAggregator metrics and leverage that instead in the CLI if possible
  • for the FlowAggregator antctl e2e tests, write some "real" tests instead of just calling the commands without arguments. In particular we can call antctl get flowrecords -o json and check that the contents are as expected.

@@ -1326,6 +1326,21 @@ func (data *TestData) getAntreaPodOnNode(nodeName string) (podName string, err e
return pods.Items[0].Name, nil
}

// getFlowAggregator retrieves the name of the Flow-Aggregator Pod (flow-aggregator-*) running on a specific Node.
func (data *TestData) getFlowAggregator(nodeName string) (podName string, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

please use this function in the implementation of gracefulExitFlowAggregator to avoid code duplication

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 191 to 192
// testAntctlLocalAccess ensures antctl is accessible in a Flow Aggregator Pod.
func testAntctlLocalAccess(t *testing.T, data *TestData) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe call it something more specific to avoid potential name collisions in the future

for example testFlowAggregatorAntctl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@yanjunz97 yanjunz97 force-pushed the flow-aggregator-antctl branch from 647965c to e99815a Compare November 5, 2021 22:14
@github-actions github-actions bot requested a review from antoninbas November 5, 2021 22:15
antoninbas
antoninbas previously approved these changes Nov 5, 2021
@antoninbas
Copy link
Contributor

/test-all

@yanjunz97
Copy link
Contributor Author

/test-all-features-conformance
/test-integration

@yanjunz97
Copy link
Contributor Author

All tests passed. This PR can be merged together with #2909 if no other comment.

@antoninbas
Copy link
Contributor

@yanjunz97 I merged #2909 but looks like you have to rebase now

@yanjunz97
Copy link
Contributor Author

/test-all
/test-integration

@yanjunz97
Copy link
Contributor Author

/test-integration

1 similar comment
@yanjunz97
Copy link
Contributor Author

/test-integration

@yanjunz97
Copy link
Contributor Author

@yanjunz97 I merged #2909 but looks like you have to rebase now

Thanks! Rebased and passed the tests

@antoninbas antoninbas merged commit 617ce25 into antrea-io:main Nov 9, 2021
qiyueyao added a commit to Dyanngg/antrea that referenced this pull request Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/component/antctl Issues or PRs releated to the command line interface component area/flow-visibility/aggregator Issues or PRs related to Flow Aggregator review-manager-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add generic APIserver in Flow Aggregator
7 participants