From b5e3fb10c4ffb3ca6b74fc9697881d7d67fc77d8 Mon Sep 17 00:00:00 2001 From: Mohamed Mahmoud Date: Mon, 3 Jun 2024 15:09:11 -0400 Subject: [PATCH] NETOBSERV-1640: add ovs monitoring feature to cli repo Signed-off-by: Mohamed Mahmoud --- cmd/flow_capture.go | 26 ++++++++++++++++++++------ cmd/flow_capture_test.go | 23 +++++++++++++++-------- cmd/root_test.go | 1 + docs/netobserv_cli_flows_config.md | 13 +++++++------ res/flow-capture.yml | 10 ++++++++++ scripts/functions.sh | 16 ++++++++++++++++ 6 files changed, 69 insertions(+), 20 deletions(-) diff --git a/cmd/flow_capture.go b/cmd/flow_capture.go index b0a5e0e1..80ac6a31 100644 --- a/cmd/flow_capture.go +++ b/cmd/flow_capture.go @@ -39,7 +39,8 @@ var ( pktDropDisplay = "PktDrop" dnsDisplay = "DNS" rttDisplay = "RTT" - display = []string{pktDropDisplay, dnsDisplay, rttDisplay} + ovsDisplay = "OVS" + display = []string{pktDropDisplay, dnsDisplay, rttDisplay, ovsDisplay} noEnrichment = "None" zoneEnrichment = "Zone" @@ -170,7 +171,7 @@ func toSize(fieldName string) int { return 40 case "DropState": return 20 - case "Time", "Interfaces", "SrcZone", "DstZone": + case "Time", "Interfaces", "SrcZone", "DstZone", "OvsMonitorMDs": return 16 case "DropBytes", "DropPackets", "SrcOwnerType", "DstOwnerType": return 12 @@ -282,6 +283,11 @@ func updateTable() { "RTT", ) } + if slices.Contains(display, ovsDisplay) { + cols = append(cols, + "OvsMonitorMDs", + ) + } } else { cols = append(cols, "Dir", @@ -358,7 +364,8 @@ func scanner() { flowsToShow = flowsToShow - 1 } } else if key == keyboard.KeyArrowRight { - if slices.Contains(display, pktDropDisplay) && slices.Contains(display, dnsDisplay) && slices.Contains(display, rttDisplay) { + if slices.Contains(display, pktDropDisplay) && slices.Contains(display, dnsDisplay) && + slices.Contains(display, rttDisplay) && slices.Contains(display, ovsDisplay) { display = []string{rawDisplay} } else if slices.Contains(display, rawDisplay) { display = []string{standardDisplay} @@ -367,23 +374,30 @@ func scanner() { } else if slices.Contains(display, pktDropDisplay) { display = []string{dnsDisplay} } else if slices.Contains(display, dnsDisplay) { + display = []string{ovsDisplay} + } else if slices.Contains(display, ovsDisplay) { display = []string{rttDisplay} + } else if slices.Contains(display, rttDisplay) { + display = []string{rawDisplay} } else { - display = []string{pktDropDisplay, dnsDisplay, rttDisplay} + display = []string{pktDropDisplay, dnsDisplay, rttDisplay, ovsDisplay} } } else if key == keyboard.KeyArrowLeft { - if slices.Contains(display, pktDropDisplay) && slices.Contains(display, dnsDisplay) && slices.Contains(display, rttDisplay) { + if slices.Contains(display, pktDropDisplay) && slices.Contains(display, dnsDisplay) && slices.Contains(display, rttDisplay) && + slices.Contains(display, ovsDisplay) { display = []string{rttDisplay} } else if slices.Contains(display, rttDisplay) { display = []string{dnsDisplay} } else if slices.Contains(display, dnsDisplay) { display = []string{pktDropDisplay} } else if slices.Contains(display, pktDropDisplay) { + display = []string{ovsDisplay} + } else if slices.Contains(display, ovsDisplay) { display = []string{standardDisplay} } else if slices.Contains(display, standardDisplay) { display = []string{rawDisplay} } else { - display = []string{pktDropDisplay, dnsDisplay, rttDisplay} + display = []string{pktDropDisplay, dnsDisplay, rttDisplay, ovsDisplay} } } else if key == keyboard.KeyPgup { if slices.Contains(enrichement, zoneEnrichment) && slices.Contains(enrichement, hostEnrichment) && slices.Contains(enrichement, ownerEnrichment) { diff --git a/cmd/flow_capture_test.go b/cmd/flow_capture_test.go index 7c76bdb9..3fc7f03b 100644 --- a/cmd/flow_capture_test.go +++ b/cmd/flow_capture_test.go @@ -39,9 +39,9 @@ func TestFlowTableDefaultDisplay(t *testing.T) { rows := strings.Split(buf.String(), "\n") assert.Equal(t, 4, len(rows)) - assert.Equal(t, `Time SrcName SrcType DstName DstType DropBytes DropPackets DropState DropCause DnsId DnsLatency DnsRCode DnsErrno RTT `, rows[0]) - assert.Equal(t, `17:25:28.703000 src-pod Pod dst-pod Pod 32B 1 TCP_INVALID_STATE SKB_DROP_REASON_TCP_INVALID_SEQUENCE 31319 1ms NoError 0 10µs `, rows[1]) - assert.Equal(t, `---------------- --------------------------------------------- -------- --------------------------------------------- -------- ------------ ------------ -------------------- ---------------------------------------- ------ ------ ------ ------ ------ `, rows[2]) + assert.Equal(t, `Time SrcName SrcType DstName DstType DropBytes DropPackets DropState DropCause DnsId DnsLatency DnsRCode DnsErrno RTT OvsMonitorMDs `, rows[0]) + assert.Equal(t, `17:25:28.703000 src-pod Pod dst-pod Pod 32B 1 TCP_INVALID_STATE SKB_DROP_REASON_TCP_INVALID_SEQUENCE 31319 1ms NoError 0 10µs hello `, rows[1]) + assert.Equal(t, `---------------- --------------------------------------------- -------- --------------------------------------------- -------- ------------ ------------ -------------------- ---------------------------------------- ------ ------ ------ ------ ------ ---------------- `, rows[2]) assert.Empty(t, rows[3]) } @@ -127,12 +127,11 @@ func TestFlowTableAdvancedDisplay(t *testing.T) { } // set display without enrichment - rows := getRows([]string{pktDropDisplay, dnsDisplay, rttDisplay}, []string{noEnrichment}) - + rows := getRows([]string{pktDropDisplay, dnsDisplay, rttDisplay, ovsDisplay}, []string{noEnrichment}) assert.Equal(t, 4, len(rows)) - assert.Equal(t, `Time SrcAddr SrcPort DstAddr DstPort DropBytes DropPackets DropState DropCause DnsId DnsLatency DnsRCode DnsErrno RTT `, rows[0]) - assert.Equal(t, `17:25:28.703000 10.128.0.29 1234 10.129.0.26 5678 32B 1 TCP_INVALID_STATE SKB_DROP_REASON_TCP_INVALID_SEQUENCE 31319 1ms NoError 0 10µs `, rows[1]) - assert.Equal(t, `---------------- ---------------------------------------- ------ ---------------------------------------- ------ ------------ ------------ -------------------- ---------------------------------------- ------ ------ ------ ------ ------ `, rows[2]) + assert.Equal(t, `Time SrcAddr SrcPort DstAddr DstPort DropBytes DropPackets DropState DropCause DnsId DnsLatency DnsRCode DnsErrno RTT OvsMonitorMDs `, rows[0]) + assert.Equal(t, `17:25:28.703000 10.128.0.29 1234 10.129.0.26 5678 32B 1 TCP_INVALID_STATE SKB_DROP_REASON_TCP_INVALID_SEQUENCE 31319 1ms NoError 0 10µs hello `, rows[1]) + assert.Equal(t, `---------------- ---------------------------------------- ------ ---------------------------------------- ------ ------------ ------------ -------------------- ---------------------------------------- ------ ------ ------ ------ ------ ---------------- `, rows[2]) assert.Empty(t, rows[3]) // set display to standard @@ -170,4 +169,12 @@ func TestFlowTableAdvancedDisplay(t *testing.T) { assert.Equal(t, `17:25:28.703000 10.128.0.29 1234 10.129.0.26 5678 10µs `, rows[1]) assert.Equal(t, `---------------- ---------------------------------------- ------ ---------------------------------------- ------ ------ `, rows[2]) assert.Empty(t, rows[3]) + + // set display to OVS + rows = getRows([]string{ovsDisplay}, []string{noEnrichment}) + assert.Equal(t, 4, len(rows)) + assert.Equal(t, `Time SrcAddr SrcPort DstAddr DstPort OvsMonitorMDs `, rows[0]) + assert.Equal(t, `17:25:28.703000 10.128.0.29 1234 10.129.0.26 5678 hello `, rows[1]) + assert.Equal(t, `---------------- ---------------------------------------- ------ ---------------------------------------- ------ ---------------- `, rows[2]) + assert.Empty(t, rows[3]) } diff --git a/cmd/root_test.go b/cmd/root_test.go index 82ecc484..34ce1277 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -44,6 +44,7 @@ const ( "PktDropLatestFlags":16, "PktDropLatestState":"TCP_INVALID_STATE", "PktDropPackets":1, + "OvsMonitorMDs":["hello"], "Proto":6, "SrcAddr":"10.128.0.29", "SrcK8S_HostIP":"10.0.1.1", diff --git a/docs/netobserv_cli_flows_config.md b/docs/netobserv_cli_flows_config.md index 5d8461a9..1be79d3f 100644 --- a/docs/netobserv_cli_flows_config.md +++ b/docs/netobserv_cli_flows_config.md @@ -19,12 +19,13 @@ USER=netobserv make commands - The following table shows all supported features options. -| Option | Description | Possible values | Default | -|------------------|---------------------------------|-------------------|---------| -| --enable_pktdrop | Enable packet drop | true, false | false | -| --enable_rtt | Enable round trip time | true, false | false | -| --enable_dns | Enable DNS tracking | true, false | false | -| --interfaces | Interfaces to match on the flow | e.g., "eth0,eth1" | "" | +| Option | Description | Possible values | Default | +|------------------------|---------------------------------|-------------------|---------| +| --enable_pktdrop | Enable packet drop | true, false | false | +| --enable_rtt | Enable round trip time | true, false | false | +| --enable_dns | Enable DNS tracking | true, false | false | +| --enable_ovsmonitoring | Enable OVS Monitoring | true, false | false | +| --interfaces | Interfaces to match on the flow | e.g., "eth0,eth1" | "" | - The following table shows flow filter configuration options. diff --git a/res/flow-capture.yml b/res/flow-capture.yml index e80fada0..9797e1f0 100644 --- a/res/flow-capture.yml +++ b/res/flow-capture.yml @@ -41,6 +41,8 @@ spec: value: "false" - name: ENABLE_DNS_TRACKING value: "false" + - name: ENABLE_OVS_MONITORING + value: "false" - name: ENABLE_FLOW_FILTER value: "false" - name: FILTER_DIRECTION @@ -140,8 +142,16 @@ spec: - name: bpf-kernel-debug mountPath: /sys/kernel/debug mountPropagation: Bidirectional + - name: var-run-ovn + mountPath: /var/run/ovn + mountPropagation: Bidirectional + volumes: - name: bpf-kernel-debug hostPath: path: /sys/kernel/debug type: Directory + - name: var-run-ovn + hostPath: + path: /var/run/ovn-ic + type: DirectoryOrCreate diff --git a/scripts/functions.sh b/scripts/functions.sh index 7132cb8b..e25cfcce 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -143,6 +143,7 @@ function flows_usage { echo " --enable_pktdrop: enable packet drop (default: false)" echo " --enable_dns: enable DNS tracking (default: false)" echo " --enable_rtt: enable RTT tracking (default: false)" + echo " --enable_ovsmonitoring: enable OVS Monitoring (default: false)" echo " --enable_filter: enable flow filter (default: false)" echo " --direction: flow filter direction" echo " --cidr: flow filter CIDR (default: 0.0.0.0/0)" @@ -192,6 +193,9 @@ function edit_manifest() { "rtt_enable") yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"ENABLE_RTT\").value|=\"$2\"" "$3" ;; + "ovsmonitoring_enable") + yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"ENABLE_OVS_MONITORING\").value|=\"$2\"" "$3" + ;; "filter_enable") yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"ENABLE_FLOW_FILTER\").value|=\"$2\"" "$3" ;; @@ -286,6 +290,18 @@ function check_args_and_apply() { exit 1 fi ;; + --enable_ovsmonitoring) # Enable OVS monitoring + if [[ "$3" == "flows" ]]; then + if [[ "$value" == "true" || "$value" == "false" ]]; then + edit_manifest "ovsmonitoring_enable" "$value" "$2" + else + echo "invalid value for --enable_ovsmonitoring" + fi + else + echo "--enable_ovsmonitoring is invalid option for packets" + exit 1 + fi + ;; --enable_filter) # Enable flow filter if [[ "$3" == "flows" ]]; then if [[ "$value" == "true" || "$value" == "false" ]]; then