Configure flow sampling and filtering rules
Configure flow sampling rates and filtering rules to control which network flows the eBPF agent collects, so you can balance observability detail against resource usage.
Update the FlowCollector resource
As an alternative to using the web console, use the oc patch command with the flowcollector custom resource to quickly update specific specifications, such as eBPF sampling
-
Run the following command to patch the
flowcollectorCR and update thespec.agent.ebpf.samplingvalue:$ oc patch flowcollector cluster --type=json -p "[{"op": "replace", "path": "/spec/agent/ebpf/sampling", "value": <new value>}] -n netobserv"
Filter network flows at ingestion
Create filters to reduce the number of generated network flows. Filtering network flows can reduce the resource usage of the network observability components.
You can configure two kinds of filters:
-
eBPF agent filters
-
Flowlogs-pipeline filters
eBPF agent filters maximize performance because they take effect at the earliest stage of the network flows collection process.
To configure eBPF agent filters with the Network Observability Operator, see "Filtering eBPF flow data using multiple rules".
Flowlogs-pipeline filters provide greater control over traffic selection because they take effect later in the network flows collection process. They are primarily used to improve data storage.
Flowlogs-pipeline filters use a simple query language to filter network flow, as shown in the following example:
(srcnamespace="netobserv" OR (srcnamespace="ingress" AND dstnamespace="netobserv")) AND srckind!="service"
The query language uses the following syntax:
| Category | Operators |
|---|---|
Logical boolean operators (not case-sensitive) |
|
Comparison operators |
|
Unary operations |
|
You can configure flowlogs-pipeline filters in the spec.processor.filters section of the FlowCollector resource. For example:
apiVersion: flows.netobserv.io/v1beta2
kind: FlowCollector
metadata:
name: cluster
spec:
namespace: netobserv
agent:
processor:
filters:
- query: |
(SrcK8S_Namespace="netobserv" OR (SrcK8S_Namespace="openshift-ingress" AND DstK8S_Namespace="netobserv"))
outputTarget: Loki
sampling: 10
where:
spec.processor.filters.outputTarget-
Specifies the output destination for matching flows, such as
Loki,Prometheus, or an external system. If you omit this parameter, the system sends the flows to all configured outputs. spec.processor.filters.sampling-
Specifies an optional sampling interval to limit the number of matching flows stored or exported. For example, a value of
10means there is a 1 in 10 chance that a flow is kept.
Flow filter configuration parameters
Reference the required and optional parameters for configuring flow filter rules in the FlowCollector resource, including CIDR ranges, filter actions, protocols, and specific port configurations.
| Parameter | Description |
|---|---|
|
Set |
|
Provides the IP address and CIDR mask for the flow filter rule. Supports both IPv4 and IPv6 address format. If you want to match against any IP, you can use |
|
Describes the action that is taken for the flow filter rule. The possible values are
|
| Parameter | Description |
|---|---|
|
Defines the direction of the flow filter rule. Possible values are |
|
Defines the protocol of the flow filter rule. Possible values are |
|
Defines the TCP flags to filter flows. Possible values are |
|
Defines the ports to use for filtering flows. It can be used for either source or destination ports. To filter a single port, set a single port as an integer value. For example |
|
Defines the source port to use for filtering flows. To filter a single port, set a single port as an integer value, for example |
|
DestPorts defines the destination ports to use for filtering flows. To filter a single port, set a single port as an integer value, for example |
|
Defines the ICMP type to use for filtering flows. |
|
Defines the ICMP code to use for filtering flows. |
|
Defines the IP address to use for filtering flows, for example: |
eBPF flow data filtering examples
Use these FlowCollector custom resource examples to filter eBPF flows using multiple rules to control the flow of packets cached in the eBPF flow table.
By default, all other flows are rejected.
apiVersion: flows.netobserv.io/v1beta2
kind: FlowCollector
metadata:
name: cluster
spec:
namespace: netobserv
deploymentModel: Service
agent:
type: eBPF
ebpf:
flowFilter:
enable: true
rules:
- action: Accept
cidr: 0.0.0.0/0
sampling: 1
- action: Accept
cidr: 10.128.0.0/14
peerCIDR: 10.128.0.0/14
- action: Accept
cidr: 172.30.0.0/16
peerCIDR: 10.128.0.0/14
sampling: 50
where:
spec.agent.ebpf.flowFilter.enable-
Specifies whether to enable
eBPFflow filtering. Set totrueto enable flow filtering. spec.agent.ebpf.flowFilter.rules.action-
Specifies the action for the flow filter rule. Valid values are
AcceptorReject. spec.agent.ebpf.flowFilter.rules.cidr-
Specifies the IP address and
CIDRmask for the flow filter rule. This parameter supports bothIPv4andIPv6address formats. Use0.0.0.0/0forIPv4or::/0forIPv6to match any IP address. spec.agent.ebpf.flowFilter.rules.peerCIDR-
Specifies the Peer IP
CIDRused to filter flows. spec.agent.ebpf.flowFilter.rules.sampling-
Specifies the sampling interval for matched flows. This value overrides the global sampling setting defined in
spec.agent.ebpf.sampling.
By default, all other flows are rejected.
apiVersion: flows.netobserv.io/v1beta2
kind: FlowCollector
metadata:
name: cluster
spec:
namespace: netobserv
deploymentModel: Service
agent:
type: eBPF
ebpf:
privileged: true
features:
- PacketDrop
flowFilter:
enable: true
rules:
- action: Accept
cidr: 172.30.0.0/16
pktDrops: true
where:
spec.agent.ebpf.privileged-
Specifies whether to enable privileged mode, which is required for reporting packet drops.
spec.agent.ebpf.features-
Specifies the list of eBPF features to enable. Adding the
PacketDropvalue to this list reports packet drops for each network flow. spec.agent.ebpf.flowFilter.enable-
Specifies whether to enable
eBPFflow filtering. spec.agent.ebpf.flowFilter.rules.action-
Specifies the action for the flow filter rule. Valid values are
AcceptorReject. spec.agent.ebpf.flowFilter.rules.pktDrops-
Specifies whether to filter for flows that contain packet drops.