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 Pod-to-Service flows with Flow Exporter when Antrea Proxy enabled #984

Merged
merged 2 commits into from
Aug 12, 2020

Conversation

srikartati
Copy link
Member

@srikartati srikartati commented Jul 27, 2020

This is based on PR #825. The actual commit for this PR is 714eb8f.

Flow exporter can send flow records of Pod-To-Service flows
with the service name, when Antrea proxy is enabled. Flow records from
the source host (local to the pod) contain the service name.
For this purpose, added a map in proxier:
ServicePort(clusterIP:Port/Proto) to ServicePortName

@antrea-bot
Copy link
Collaborator

Thanks for your PR.
Unit tests and code linters are run automatically every time the PR is updated.
E2e, conformance and network policy tests can only be triggered by a member of the vmware-tanzu organization. Regular contributors to the project should join the org.

The following commands are available:

  • /test-e2e: to trigger e2e tests.
  • /skip-e2e: to skip e2e tests.
  • /test-conformance: to trigger conformance tests.
  • /skip-conformance: to skip conformance tests.
  • /test-whole-conformance: to trigger all conformance tests on linux.
  • /skip-whole-conformance: to skip all conformance tests on linux.
  • /test-networkpolicy: to trigger networkpolicy tests.
  • /skip-networkpolicy: to skip networkpolicy tests.
  • /test-windows-conformance: to trigger windows conformance tests.
  • /skip-windows-conformance: to skip windows conformance tests.
  • /test-windows-networkpolicy: to trigger windows networkpolicy tests.
  • /skip-windows-networkpolicy: to skip windows networkpolicy tests.
  • /test-all: to trigger all tests (except whole conformance).
  • /skip-all: to skip all tests (except whole conformance).

These commands can only be run by members of the vmware-tanzu organization.

@srikartati srikartati changed the title WIP: Support Pod-to-Service flows with Flow Exporter with Antrea Proxy WIP: Support Pod-to-Service flows with Flow Exporter when Antrea Proxy enabled Jul 28, 2020
@antrea-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@antrea-bot
Copy link
Collaborator

Thanks for your PR.
Unit tests and code linters are run automatically every time the PR is updated.
E2e, conformance and network policy tests can only be triggered by a member of the vmware-tanzu organization. Regular contributors to the project should join the org.

The following commands are available:

  • /test-e2e: to trigger e2e tests.
  • /skip-e2e: to skip e2e tests.
  • /test-conformance: to trigger conformance tests.
  • /skip-conformance: to skip conformance tests.
  • /test-whole-conformance: to trigger all conformance tests on linux.
  • /skip-whole-conformance: to skip all conformance tests on linux.
  • /test-networkpolicy: to trigger networkpolicy tests.
  • /skip-networkpolicy: to skip networkpolicy tests.
  • /test-windows-conformance: to trigger windows conformance tests.
  • /skip-windows-conformance: to skip windows conformance tests.
  • /test-windows-networkpolicy: to trigger windows networkpolicy tests.
  • /skip-windows-networkpolicy: to skip windows networkpolicy tests.
  • /test-hw-offload: to trigger ovs hardware offload test.
  • /skip-hw-offload: to skip ovs hardware offload test.
  • /test-all: to trigger all tests (except whole conformance).
  • /skip-all: to skip all tests (except whole conformance).

These commands can only be run by members of the vmware-tanzu organization.

@srikartati srikartati force-pushed the service_info branch 3 times, most recently from 519a36b to 714eb8f Compare August 5, 2020 05:48
@srikartati srikartati changed the title WIP: Support Pod-to-Service flows with Flow Exporter when Antrea Proxy enabled Support Pod-to-Service flows with Flow Exporter when Antrea Proxy enabled Aug 7, 2020
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.

Reviewed the latest commit. LGTM, only some minor comments.

@@ -124,6 +130,26 @@ func (cs *ConnectionStore) addOrUpdateConn(conn *flowexporter.Connection) {
if !srcFound && dstFound {
conn.DoExport = false
}

// Pod-to-Service flows w/ antrea-proxy:Antrea proxy is enabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Pod-to-Service flows w/ antrea-proxy:Antrea proxy is enabled.
// Process Pod-to-Service flows when Antrea proxy is enabled

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -167,3 +175,12 @@ func LookupProtocolMap(name string) (uint8, error) {
}
return proto, nil
}

// LookupServiceProtocol return service protocol string given protocol identifier
func LookupServiceProtocol(protoID uint8) (corev1.Protocol, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is much value in having this function in this package, especially with the dependency on K8s. It is clear that you also only support protocols supported by K8s Services. I think you can just move it to pkg/agent/flowexporter/connections/connections.go

Copy link
Member Author

Choose a reason for hiding this comment

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

Only one file is using right now. Ok to move there and acknowledge the point on k8s dependency.

svcPort := conn.TupleOrig.DestinationPort
protocol, err := ip.LookupServiceProtocol(conn.TupleOrig.Protocol)
if err != nil {
klog.Warningf("Could not retrieve service protocol: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

s/service/Service in log messages

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this was addressed actually?

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed in the other line. Missed this. Done.

func (p *proxier) addServiceByIP(serviceStr string, servicePortName k8sproxy.ServicePortName) {
p.serviceStringMapMutex.Lock()
defer p.serviceStringMapMutex.Unlock()
klog.V(2).Infof("Added service with key: %v value: %v", serviceStr, servicePortName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not convinced we need a log message just for updating this map? At least, maybe you can reduce the verbosity and add a symmetric log message for service deletion.

Copy link
Member Author

@srikartati srikartati Aug 8, 2020

Choose a reason for hiding this comment

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

Used it for initial debugging. Function is straightforward; do not see much use as well.

@@ -140,6 +141,7 @@ func TestFlowExporter_sendDataRecord(t *testing.T) {
for i, ie := range AntreaInfoElements {
elemList[i+len(IANAInfoElements)+len(IANAReverseInfoElements)] = ipfixentities.NewInfoElement(ie, 0, 0, 0, 0)
}
// Define mocks and flowExporter
Copy link
Contributor

Choose a reason for hiding this comment

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

not a very useful comment I think

Copy link
Member Author

Choose a reason for hiding this comment

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

removed it.

@@ -61,6 +61,8 @@ var (
"destinationPodName",
"destinationPodNamespace",
"destinationNodeName",
"destinationClusterIP",
"destinationServiceName",
Copy link
Contributor

Choose a reason for hiding this comment

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

this includes the port as well right? should the name be destinationServicePortName?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Changed the name here and in Antrea IPFIX registry

@srikartati srikartati force-pushed the service_info branch 4 times, most recently from 15db4fc to 5039410 Compare August 11, 2020 14:27
@antrea-bot
Copy link
Collaborator

Thanks for your PR.
Unit tests and code linters are run automatically every time the PR is updated.
E2e, conformance and network policy tests can only be triggered by a member of the vmware-tanzu organization. Regular contributors to the project should join the org.

The following commands are available:

  • /test-e2e: to trigger e2e tests.
  • /skip-e2e: to skip e2e tests.
  • /test-conformance: to trigger conformance tests.
  • /skip-conformance: to skip conformance tests.
  • /test-whole-conformance: to trigger all conformance tests on linux.
  • /skip-whole-conformance: to skip all conformance tests on linux.
  • /test-networkpolicy: to trigger networkpolicy tests.
  • /skip-networkpolicy: to skip networkpolicy tests.
  • /test-windows-conformance: to trigger windows conformance tests.
  • /skip-windows-conformance: to skip windows conformance tests.
  • /test-windows-networkpolicy: to trigger windows networkpolicy tests.
  • /skip-windows-networkpolicy: to skip windows networkpolicy tests.
  • /test-hw-offload: to trigger ovs hardware offload test.
  • /skip-hw-offload: to skip ovs hardware offload test.
  • /test-all: to trigger all tests (except whole conformance).
  • /skip-all: to skip all tests (except whole conformance).

@srikartati
Copy link
Member Author

/test-all

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.

a couple of nits, otherwise LGTM

Comment on lines 89 to 90
TupleOrig: *tuple3,
TupleReply: *revTuple3,
Copy link
Contributor

Choose a reason for hiding this comment

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

If you always end up dereferencing the tuples, I think it may make more sense to just return values (and not pointers) in makeTuple.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.. Any insight on the copy of return value from a function VS copy from dereferencing? I believe the first one is little efficient because of return registers.

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 performance is not an issue here, since the struct is small, the function is not called many times, and this is test code. It's also not always faster to return a pointer. So I would favor readability. If you were embedding a point in flowexporter.Connection, I would recommend using a pointer instead.

You are also using the tuple as an immutable value in a way, so I think passing it around by value works well.

Comment on lines +331 to +334
// Sending dummy IP as IPFIX collector expects constant length of data for IP field.
// We should probably think of better approach as this involves customization of IPFIX collector to ignore
// this dummy IP address.
_, err = dataRec.AddInfoElement(ie, net.IP{0, 0, 0, 0})
Copy link
Contributor

Choose a reason for hiding this comment

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

newbie question: is it not possible to simply omit the information element in this case? Or will the collector complain if some elements are missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes collector checks that if number of elements in a data record matches to originally sent template record or not.

@@ -184,3 +218,12 @@ func (cs *ConnectionStore) DeleteConnectionByKey(connKey flowexporter.Connection

return nil
}

// LookupServiceProtocol return service protocol string given protocol identifier
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// LookupServiceProtocol return service protocol string given protocol identifier
// LookupServiceProtocol returns the corresponding Service protocol string given a protocol identifier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@srikartati srikartati force-pushed the service_info branch 2 times, most recently from bd8f387 to c4c535b Compare August 11, 2020 18:58
@srikartati
Copy link
Member Author

/test-all

antoninbas
antoninbas previously approved these changes Aug 11, 2020
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

@srikartati
Copy link
Member Author

/test-e2e
/test-windows-conformance
/test-windows-networkpolicy

@srikartati
Copy link
Member Author

/test-e2e

3 similar comments
@srikartati
Copy link
Member Author

/test-e2e

@srikartati
Copy link
Member Author

/test-e2e

@srikartati
Copy link
Member Author

/test-e2e

@antoninbas
Copy link
Contributor

antoninbas commented Aug 11, 2020

@srikartati if there is an issue with the Jenkins e2e testbed, we should let @lzhecheng. In some cases, re-triggering the job too much actually makes things worse :(

@srikartati
Copy link
Member Author

@srikartati if there is an issue with the Jenkins e2e testbed, we should let @lzhecheng. In some cases, re-triggering the job too much actually makes things worse :(

Ok. I see the following error:

=== Get kubeconfig (try for 1m) ===
Error from server (NotFound): secrets "antrea-e2e-for-pull-request-1022-kubeconfig" not found
=== Get kubeconfig (try for 1m) ===
Error from server (NotFound): secrets "antrea-e2e-for-pull-request-1022-kubeconfig" not found

I will check with @lzhecheng

@srikartati
Copy link
Member Author

/test-all

@srikartati
Copy link
Member Author

/test-windows-conformance
/test-hw-offload

@srikartati
Copy link
Member Author

Hi @antoninbas: Can I skip hw-offload test for this PR too? This was in pending state for few hours and I could not see the logs as well. I see it is being done for some recent PRs.

@antoninbas
Copy link
Contributor

/skip-hw-offload

Flow exporter can send flow records of Pod-To-Service flows
with service name, when Antrea proxy is enabled. Flow records from
source host (local to pod) contains service name.
For this purpose, added a map in proxier:
ServicePort(clusterIP:Port/Proto) to ServicePortName
@srikartati
Copy link
Member Author

/test-all

@srikartati
Copy link
Member Author

/test-network-policy
/skip-hw-offload

@srikartati
Copy link
Member Author

/test-windows-networkpolicy

@srikartati
Copy link
Member Author

/skip-hw-offload

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.

Approving again

@srikartati srikartati merged commit 14a248d into antrea-io:master Aug 12, 2020
GraysonWu pushed a commit to GraysonWu/antrea that referenced this pull request Sep 22, 2020
…bled (antrea-io#984)

* Flow Exporter: Support Pod-To-Service flows with Antrea Proxy

Flow exporter can send flow records of Pod-To-Service flows
with the service name, when Antrea proxy is enabled. Flow records from
the source host (local to the sender pod) contain a service name.
For this purpose, added a map in proxier:
ServicePort(clusterIP:Port/Proto) to ServicePortName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants