Skip to content

Commit

Permalink
NETOBSERV-2010: manage cardinality for netevents nested labels (also …
Browse files Browse the repository at this point in the history
…NETOBSERV-2056) (#999)

* NETOBSERV-2010: manage cardinality for netevents nested labels

* Distinguish type/docType; add missing cardinality

* Align with NETOBSERV-2056

* Add integration test
  • Loading branch information
jotak authored Jan 23, 2025
1 parent 564084e commit d4fa330
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 18 deletions.
38 changes: 25 additions & 13 deletions controllers/consoleplugin/config/static-frontend-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ scopes:
name: Node
shortName: Node
description: Node on which the resources are running
labels:
labels:
- SrcK8S_HostName
- DstK8S_HostName
groups:
Expand All @@ -1095,7 +1095,7 @@ scopes:
name: Namespace
shortName: NS
description: Resource namespace
labels:
labels:
- SrcK8S_Namespace
- DstK8S_Namespace
groups:
Expand All @@ -1116,7 +1116,7 @@ scopes:
name: Owner
shortName: Own
description: Controller owner, such as a Deployment
labels:
labels:
- SrcK8S_OwnerName
- SrcK8S_OwnerType
- DstK8S_OwnerName
Expand Down Expand Up @@ -1146,7 +1146,7 @@ scopes:
name: Resource
shortName: Res
description: Base resource, such as a Pod, a Service or a Node
labels:
labels:
- SrcK8S_Name
- SrcK8S_Type
- SrcK8S_OwnerName
Expand Down Expand Up @@ -1213,6 +1213,7 @@ fields:
description: Source namespace
- name: SrcAddr
type: string
format: IP
description: Source IP address (ipv4 or ipv6)
- name: SrcPort
type: number
Expand All @@ -1222,6 +1223,7 @@ fields:
description: Source MAC address
- name: SrcK8S_HostIP
type: string
format: IP
description: Source node IP
- name: SrcK8S_HostName
type: string
Expand Down Expand Up @@ -1249,6 +1251,7 @@ fields:
description: Destination namespace
- name: DstAddr
type: string
format: IP
description: Destination IP address (ipv4 or ipv6)
- name: DstPort
type: number
Expand All @@ -1258,6 +1261,7 @@ fields:
description: Destination MAC address
- name: DstK8S_HostIP
type: string
format: IP
description: Destination node IP
- name: DstK8S_HostName
type: string
Expand Down Expand Up @@ -1297,24 +1301,24 @@ fields:
- 1: Egress (outgoing traffic, from the node observation point) +
- 2: Inner (with the same source and destination node)
- name: IfDirections
type: number
type: number[]
description: |
Flow directions from the network interface observation point. Can be one of: +
- 0: Ingress (interface incoming traffic) +
- 1: Egress (interface outgoing traffic)
- name: Interfaces
type: string
type: string[]
description: Network interfaces
- name: Udns
type: string
description: Network interfaces UDNs mapping
- name: Flags
type: string
type: string[]
description: |
Logical OR combination of unique TCP flags comprised in the flow, as per RFC-9293, with additional custom flags to represent the following per-packet combinations: +
- SYN+ACK (0x100) +
- FIN+ACK (0x200) +
- RST+ACK (0x400)
List of TCP flags comprised in the flow, as per RFC-9293, with additional custom flags to represent the following per-packet combinations: +
- SYN_ACK +
- FIN_ACK +
- RST_ACK
- name: Bytes
type: number
description: Number of bytes
Expand Down Expand Up @@ -1357,8 +1361,16 @@ fields:
type: number
description: TCP Smoothed Round Trip Time (SRTT), in nanoseconds
- name: NetworkEvents
type: string
description: Network events flow monitoring
type: string[]
docType: object[]
description: |
Network events, such as network policy actions, composed of nested fields: +
- Feature (such as "acl" for network policies) +
- Type (such as an "AdminNetworkPolicy") +
- Namespace (namespace where the event applies, if any) +
- Name (name of the resource that triggered the event) +
- Action (such as "allow" or "drop") +
- Direction (Ingress or Egress)
- name: ZoneId
type: number
description: packet translation zone id
Expand Down
31 changes: 30 additions & 1 deletion controllers/flp/flp_controller_flowmetrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,24 @@ func ControllerFlowMetricsSpecs() {
Labels: []string{"DstAddr"},
},
}
metric3 := metricslatest.FlowMetric{ // With nested labels
ObjectMeta: metav1.ObjectMeta{
Name: "metric-3",
Namespace: operatorNamespace,
},
Spec: metricslatest.FlowMetricSpec{
MetricName: "m_3",
Type: metricslatest.CounterMetric,
Labels: []string{"NetworkEvents>Type", "NetworkEvents>Name"},
},
}
metricUnwatched := metricslatest.FlowMetric{
ObjectMeta: metav1.ObjectMeta{
Name: "metric-unwatched",
Namespace: otherNamespace,
},
Spec: metricslatest.FlowMetricSpec{
MetricName: "m_3",
MetricName: "m_unwatched",
Type: metricslatest.CounterMetric,
},
}
Expand Down Expand Up @@ -121,6 +132,7 @@ func ControllerFlowMetricsSpecs() {
Expect(k8sClient.Create(ctx, &metric1)).Should(Succeed())
Expect(k8sClient.Create(ctx, &metricUnwatched)).Should(Succeed())
Expect(k8sClient.Create(ctx, &metric2)).Should(Succeed())
Expect(k8sClient.Create(ctx, &metric3)).Should(Succeed())
})

It("Should update configmap with custom metrics", func() {
Expand All @@ -139,6 +151,7 @@ func ControllerFlowMetricsSpecs() {
names := getSortedMetricsNames(metrics)
return slices.Contains(names, metric1.Spec.MetricName) &&
slices.Contains(names, metric2.Spec.MetricName) &&
slices.Contains(names, metric3.Spec.MetricName) &&
!slices.Contains(names, metricUnwatched.Spec.MetricName)
}))
})
Expand All @@ -153,6 +166,7 @@ func ControllerFlowMetricsSpecs() {
}, timeout, interval).Should(Satisfy(func(conds []metav1.Condition) bool {
ready := meta.FindStatusCondition(conds, fmstatus.ConditionReady)
card := meta.FindStatusCondition(conds, fmstatus.ConditionCardinalityOK)
// Metrics 1 has cardinality FINE (no label)
return ready != nil && card != nil && ready.Status == metav1.ConditionTrue && card.Status == metav1.ConditionTrue &&
ready.Reason == "Ready" && card.Reason == string(cardinality.WarnFine)
}))
Expand All @@ -164,11 +178,26 @@ func ControllerFlowMetricsSpecs() {
}
return metric2.Status.Conditions
}, timeout, interval).Should(Satisfy(func(conds []metav1.Condition) bool {
// Metrics 2 has cardinality AVOID (Addr label)
ready := meta.FindStatusCondition(conds, fmstatus.ConditionReady)
card := meta.FindStatusCondition(conds, fmstatus.ConditionCardinalityOK)
return ready != nil && card != nil && ready.Status == metav1.ConditionTrue && card.Status == metav1.ConditionFalse &&
ready.Reason == "Ready" && card.Reason == string(cardinality.WarnAvoid)
}))

Eventually(func() interface{} {
err := k8sClient.Get(ctx, helper.NamespacedName(&metric3), &metric3)
if err != nil {
return err
}
return metric3.Status.Conditions
}, timeout, interval).Should(Satisfy(func(conds []metav1.Condition) bool {
// Metrics 3 has cardinality FINE (NetworkEvents nested labels)
ready := meta.FindStatusCondition(conds, fmstatus.ConditionReady)
card := meta.FindStatusCondition(conds, fmstatus.ConditionCardinalityOK)
return ready != nil && card != nil && ready.Status == metav1.ConditionTrue && card.Status == metav1.ConditionTrue &&
ready.Reason == "Ready" && card.Reason == string(cardinality.WarnFine)
}))
})
})

Expand Down
14 changes: 11 additions & 3 deletions hack/asciidoc-flows-gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ nbfields=$(yq '.fields | length' $FE_SOURCE)
lokiLabels=$(cat $LOKI_LABEL_SOURCE)
cardinalityMap=$(cat $CARDINALITY_SOURCE)
otelMap=$(cat $OTEL_SOURCE)
errors=""

for i in $(seq 0 $(( $nbfields-1 )) ); do
frontEntry=$(yq ".fields | sort_by(.name) | .[$i]" $FE_SOURCE)
name=$(printf "$frontEntry" | yq ".name")
type=$(printf "$frontEntry" | yq ".type")
type=$(printf "$frontEntry" | yq ".docType")
if [[ "$type" == "null" ]]; then
type=$(printf "$frontEntry" | yq ".type")
fi
desc=$(printf "$frontEntry" | yq ".description")
filter=$(printf "$frontEntry" | yq ".filter")
if [[ "$filter" == "null" ]]; then
Expand All @@ -44,8 +48,7 @@ for i in $(seq 0 $(( $nbfields-1 )) ); do
fi
cardWarn=$(printf "$cardinalityMap" | jq -r ".$name")
if [[ "$cardWarn" == "null" ]]; then
echo "missing cardinality for field $name"
exit 1
errors="$errors\nmissing cardinality for field $name"
fi
otel=$(printf "$otelMap" | jq -r ".$name")
if [[ "$otel" == "null" ]]; then
Expand All @@ -60,4 +63,9 @@ for i in $(seq 0 $(( $nbfields-1 )) ); do
echo -e "| $otel" >> $ADOC
done

if [[ $errors != "" ]]; then
echo -e $errors
exit 1
fi

echo -e '|===' >> $ADOC
15 changes: 14 additions & 1 deletion pkg/helper/cardinality/cardinality.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@
"DnsErrno": "fine",
"TimeFlowRttNs": "avoid",
"NetworkEvents": "avoid",
"NetworkEvents>Feature": "fine",
"NetworkEvents>Type": "fine",
"NetworkEvents>Namespace": "fine",
"NetworkEvents>Name": "fine",
"NetworkEvents>Action": "fine",
"NetworkEvents>Direction": "fine",
"K8S_ClusterName": "fine",
"Sampling": "fine",
"ZoneId": "avoid",
"XlatSrcPort": "careful",
"XlatSrcAddr": "avoid",
"XlatIcmpId": "avoid",
"XlatDstPort": "careful",
"XlatDstAddr": "avoid",
"_RecordType": "fine",
"_HashId": "avoid"
}
}

0 comments on commit d4fa330

Please sign in to comment.