Skip to content

Commit

Permalink
NETOBSERV-1640: add ovs monitoring feature to cli repo
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Aug 9, 2024
1 parent 9dad619 commit 931301f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 25 deletions.
36 changes: 25 additions & 11 deletions cmd/flow_capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ var (
regexes = []string{}
lastFlows = []config.GenericMap{}

rawDisplay = "Raw"
standardDisplay = "Standard"
pktDropDisplay = "PktDrop"
dnsDisplay = "DNS"
rttDisplay = "RTT"
display = []string{pktDropDisplay, dnsDisplay, rttDisplay}
rawDisplay = "Raw"
standardDisplay = "Standard"
pktDropDisplay = "PktDrop"
dnsDisplay = "DNS"
rttDisplay = "RTT"
networkEventsDisplay = "NetworkEvents"
display = []string{pktDropDisplay, dnsDisplay, rttDisplay, networkEventsDisplay}

noEnrichment = "None"
zoneEnrichment = "Zone"
Expand Down Expand Up @@ -196,7 +197,7 @@ func toSize(fieldName string) int {
return 40
case "DropState":
return 20
case "Time", "Interfaces", "SrcZone", "DstZone":
case "Time", "Interfaces", "SrcZone", "DstZone", "NetworkEvents":
return 16
case "DropBytes", "DropPackets", "SrcOwnerType", "DstOwnerType":
return 12
Expand Down Expand Up @@ -313,6 +314,11 @@ func updateTable() {
"RTT",
)
}
if slices.Contains(display, networkEventsDisplay) {
cols = append(cols,
"NetworkEvents",
)
}
} else {
cols = append(cols,
"Dir",
Expand Down Expand Up @@ -389,7 +395,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, networkEventsDisplay) {
display = []string{rawDisplay}
} else if slices.Contains(display, rawDisplay) {
display = []string{standardDisplay}
Expand All @@ -398,23 +405,30 @@ func scanner() {
} else if slices.Contains(display, pktDropDisplay) {
display = []string{dnsDisplay}
} else if slices.Contains(display, dnsDisplay) {
display = []string{networkEventsDisplay}
} else if slices.Contains(display, networkEventsDisplay) {
display = []string{rttDisplay}
} else if slices.Contains(display, rttDisplay) {
display = []string{rawDisplay}
} else {
display = []string{pktDropDisplay, dnsDisplay, rttDisplay}
display = []string{pktDropDisplay, dnsDisplay, rttDisplay, networkEventsDisplay}
}
} 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, networkEventsDisplay) {
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{networkEventsDisplay}
} else if slices.Contains(display, networkEventsDisplay) {
display = []string{standardDisplay}
} else if slices.Contains(display, standardDisplay) {
display = []string{rawDisplay}
} else {
display = []string{pktDropDisplay, dnsDisplay, rttDisplay}
display = []string{pktDropDisplay, dnsDisplay, rttDisplay, networkEventsDisplay}
}
} else if key == keyboard.KeyPgup {
if slices.Contains(enrichement, zoneEnrichment) && slices.Contains(enrichement, hostEnrichment) && slices.Contains(enrichement, ownerEnrichment) {
Expand Down
23 changes: 15 additions & 8 deletions cmd/flow_capture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 NetworkEvents `, 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])
}

Expand Down Expand Up @@ -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, networkEventsDisplay}, []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 NetworkEvents `, 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
Expand Down Expand Up @@ -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 NetworkEvents
rows = getRows([]string{networkEventsDisplay}, []string{noEnrichment})
assert.Equal(t, 4, len(rows))
assert.Equal(t, `Time SrcAddr SrcPort DstAddr DstPort NetworkEvents `, 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])
}
1 change: 1 addition & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
"PktDropLatestFlags":16,
"PktDropLatestState":"TCP_INVALID_STATE",
"PktDropPackets":1,
"NetworkEvents":["hello"],
"Proto":6,
"SrcAddr":"10.128.0.29",
"SrcK8S_HostIP":"10.0.1.1",
Expand Down
13 changes: 7 additions & 6 deletions docs/netobserv_cli_flows_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,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 |
| --interfaces | Interfaces to match on the flow | e.g., "eth0,eth1" | "" |
| --enable_network_events_monitoring | Enable Network events Monitoring | true, false | false |

- The following table shows flow filter configuration options.

Expand Down
17 changes: 17 additions & 0 deletions res/flow-capture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ spec:
value: "false"
- name: ENABLE_DNS_TRACKING
value: "false"
- name: ENABLE_NETWORK_EVENTS_MONITORING
value: "false"
- name: ENABLE_FLOW_FILTER
value: "false"
- name: FILTER_DIRECTION
Expand Down Expand Up @@ -142,8 +144,23 @@ spec:
- name: bpf-kernel-debug
mountPath: /sys/kernel/debug
mountPropagation: Bidirectional
- name: var-run-ovn
mountPath: /var/run/ovn
mountPropagation: Bidirectional
- name: var-run-ovs
mountPath: /var/run/openvswitch
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
- name: var-run-ovs
hostPath:
path: /var/run/openvswitch
type: DirectoryOrCreate
16 changes: 16 additions & 0 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,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_network_events_monitoring: enable Network events Monitoring (default: false)"
echo " --enable_filter: enable flow filter (default: false)"
# common
common_usage
Expand Down Expand Up @@ -221,6 +222,9 @@ function edit_manifest() {
"rtt_enable")
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"ENABLE_RTT\").value|=\"$2\"" "$3"
;;
"network_events_monitoring_enable")
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"ENABLE_NETWORK_EVENTS_MONITORING\").value|=\"$2\"" "$3"
;;
"filter_enable")
yq e --inplace ".spec.template.spec.containers[0].env[] |= select(.name==\"ENABLE_FLOW_FILTER\").value|=\"$2\"" "$3"
;;
Expand Down Expand Up @@ -329,6 +333,18 @@ function check_args_and_apply() {
exit 1
fi
;;
--enable_network_events_monitoring) # Enable Network events monitoring
if [[ "$3" == "flows" ]]; then
if [[ "$value" == "true" || "$value" == "false" ]]; then
edit_manifest "network_events_monitoring_enable" "$value" "$2"
else
echo "invalid value for --enable_network_events_monitoring"
fi
else
echo "--enable_network_events_monitoring is invalid option for packets"
exit 1
fi
;;
--enable_filter) # Enable flow filter
if [[ "$3" == "flows" ]]; then
if [[ "$value" == "true" || "$value" == "false" ]]; then
Expand Down

0 comments on commit 931301f

Please sign in to comment.