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

NETOBSERV-2005: Support multiple flow filter rules using json fmt string #473

Merged
merged 3 commits into from
Dec 13, 2024

Conversation

msherif1234
Copy link
Contributor

@msherif1234 msherif1234 commented Dec 5, 2024

Description

Example config and the flow filter map content

oc get pods  -n netobserv-privileged netobserv-ebpf-agent-tksvd -o yaml | grep "FLOW_FILTER_RULES" -A1
    - name: FLOW_FILTER_RULES
      value: '[{"ip_cidr":"1.1.1.1/24","protocol":"TCP","source_port":53,"action":"Accept","tcp_flags":"SYN"},{"ip_cidr":"2.2.2.2/24","protocol":"UDP","source_port":80,"action":"Accept","tcp_flags":"SYN"},{"ip_cidr":"3.3.3.3/24","protocol":"ICMP","action":"Accept"}]'

bpftool map dump id 223 
[{
        "key": {
            "prefix_len": 24,
            "ip_data": [1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
            ]
        },
        "value": {
            "protocol": 6,
            "dstPortStart": 0,
            "dstPortEnd": 0,
            "dstPort1": 0,
            "dstPort2": 0,
            "srcPortStart": 53,
            "srcPortEnd": 0,
            "srcPort1": 0,
            "srcPort2": 0,
            "portStart": 0,
            "portEnd": 0,
            "port1": 0,
            "port2": 0,
            "icmpType": 0,
            "icmpCode": 0,
            "direction": "MAX_DIRECTION",
            "action": "ACCEPT",
            "tcpFlags": "SYN_FLAG",
            "filter_drops": 0,
            "ip": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
            ]
        }
    },{
        "key": {
            "prefix_len": 24,
            "ip_data": [2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0
            ]
        },
        "value": {
            "protocol": 17,
            "dstPortStart": 0,
            "dstPortEnd": 0,
            "dstPort1": 0,
            "dstPort2": 0,
            "srcPortStart": 80,
            "srcPortEnd": 0,
            "srcPort1": 0,
            "srcPort2": 0,
            "portStart": 0,
            "portEnd": 0,
            "port1": 0,
            "port2": 0,
            "icmpType": 0,
            "icmpCode": 0,
            "direction": "MAX_DIRECTION",
            "action": "ACCEPT",
            "tcpFlags": "SYN_FLAG",
            "filter_drops": 0,
            "ip": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
            ]
        }
    },{
        "key": {
            "prefix_len": 24,
            "ip_data": [3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0
            ]
        },
        "value": {
            "protocol": 1,
            "dstPortStart": 0,
            "dstPortEnd": 0,
            "dstPort1": 0,
            "dstPort2": 0,
            "srcPortStart": 0,
            "srcPortEnd": 0,
            "srcPort1": 0,
            "srcPort2": 0,
            "portStart": 0,
            "portEnd": 0,
            "port1": 0,
            "port2": 0,
            "icmpType": 0,
            "icmpCode": 0,
            "direction": "MAX_DIRECTION",
            "action": "ACCEPT",
            "tcpFlags": 0,
            "filter_drops": 0,
            "ip": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
            ]
        }
    }
]

Dependencies

n/a

Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

  • Will this change affect NetObserv / Network Observability operator? If not, you can ignore the rest of this checklist.
  • Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix (in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes).
  • Does this PR require product documentation?
    • If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
  • Does this PR require a product release notes entry?
    • If so, fill in "Release Note Text" in the JIRA.
  • Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
    • If so, make sure it is described in the JIRA ticket.
  • QE requirements (check 1 from the list):
    • Standard QE validation, with pre-merge tests unless stated otherwise.
    • Regression tests only (e.g. refactoring with no user-facing change).
    • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 5.47945% with 69 lines in your changes missing coverage. Please review.

Project coverage is 29.41%. Comparing base (70003f2) to head (24151f9).

Files with missing lines Patch % Lines
pkg/agent/agent.go 0.00% 22 Missing ⚠️
pkg/agent/packets_agent.go 0.00% 22 Missing ⚠️
pkg/tracer/flow_filter.go 4.34% 20 Missing and 2 partials ⚠️
pkg/model/flow_content.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #473      +/-   ##
==========================================
- Coverage   29.68%   29.41%   -0.28%     
==========================================
  Files          51       51              
  Lines        4915     4947      +32     
==========================================
- Hits         1459     1455       -4     
- Misses       3350     3382      +32     
- Partials      106      110       +4     
Flag Coverage Δ
unittests 29.41% <5.47%> (-0.28%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/agent/config.go 8.33% <ø> (ø)
pkg/decode/decode_protobuf.go 30.11% <100.00%> (+0.61%) ⬆️
pkg/ebpf/bpf_x86_bpfel.go 0.00% <ø> (ø)
pkg/tracer/tracer.go 0.00% <ø> (ø)
pkg/model/flow_content.go 62.02% <0.00%> (-2.45%) ⬇️
pkg/agent/agent.go 32.92% <0.00%> (-0.82%) ⬇️
pkg/agent/packets_agent.go 0.00% <0.00%> (ø)
pkg/tracer/flow_filter.go 45.54% <4.34%> (-2.02%) ⬇️

... and 2 files with indirect coverage changes

@msherif1234
Copy link
Contributor Author

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 5, 2024
Copy link

github-actions bot commented Dec 5, 2024

New image:
quay.io/netobserv/netobserv-ebpf-agent:1ec52cf

It will expire after two weeks.

To deploy this build, run from the operator repo, assuming the operator is running:

USER=netobserv VERSION=1ec52cf make set-agent-image

@msherif1234 msherif1234 changed the title WIP: Support multiple flow filter rules using json fmt string Support multiple flow filter rules using json fmt string Dec 5, 2024
@msherif1234 msherif1234 requested a review from jotak December 5, 2024 20:10
@msherif1234 msherif1234 changed the title Support multiple flow filter rules using json fmt string NETOBSERV-2005: Support multiple flow filter rules using json fmt string Dec 6, 2024
@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Dec 6, 2024

@msherif1234: This pull request references NETOBSERV-2005 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.19.0" version, but no target version was set.

In response to this:

Description

Example of running as standalone

sudo TARGET_HOST=127.0.0.1 TARGET_PORT=9999 LOG_LEVEL="debug" ENABLE_FLOW_FILTER="true" FLOW_FILTER_RULES='[{"ip_cidr":"1.1.1.1/24","port":53},{"ip_cidr":"2.2.2.2/16","port":80}]'

Dependencies

n/a

Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

  • Will this change affect NetObserv / Network Observability operator? If not, you can ignore the rest of this checklist.
  • Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix (in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes).
  • Does this PR require product documentation?
  • If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
  • Does this PR require a product release notes entry?
  • If so, fill in "Release Note Text" in the JIRA.
  • Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
  • If so, make sure it is described in the JIRA ticket.
  • QE requirements (check 1 from the list):
  • Standard QE validation, with pre-merge tests unless stated otherwise.
  • Regression tests only (e.g. refactoring with no user-facing change).
  • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

Copy link

@stleerh stleerh left a comment

Choose a reason for hiding this comment

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

Minor comments.
/lgtm

pkg/agent/agent.go Outdated Show resolved Hide resolved
pkg/agent/config.go Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot added the lgtm label Dec 6, 2024
@openshift-ci openshift-ci bot removed the lgtm label Dec 7, 2024
@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 7, 2024
@msherif1234
Copy link
Contributor Author

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 7, 2024
@msherif1234 msherif1234 requested a review from stleerh December 7, 2024 01:49
Copy link

github-actions bot commented Dec 7, 2024

New image:
quay.io/netobserv/netobserv-ebpf-agent:34179d9

It will expire after two weeks.

To deploy this build, run from the operator repo, assuming the operator is running:

USER=netobserv VERSION=34179d9 make set-agent-image

@openshift-ci-robot
Copy link
Collaborator

openshift-ci-robot commented Dec 7, 2024

@msherif1234: This pull request references NETOBSERV-2005 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "4.19.0" version, but no target version was set.

In response to this:

Description

Example config and the flow filter map content

oc get pods  -n netobserv-privileged netobserv-ebpf-agent-tksvd -o yaml | grep "FLOW_FILTER_RULES" -A1
   - name: FLOW_FILTER_RULES
     value: '[{"ip_cidr":"1.1.1.1/24","protocol":"TCP","source_port":53,"action":"Accept","tcp_flags":"SYN"},{"ip_cidr":"2.2.2.2/24","protocol":"UDP","source_port":80,"action":"Accept","tcp_flags":"SYN"},{"ip_cidr":"3.3.3.3/24","protocol":"ICMP","action":"Accept"}]'

bpftool map dump id 223 
[{
       "key": {
           "prefix_len": 24,
           "ip_data": [1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0
           ]
       },
       "value": {
           "protocol": 6,
           "dstPortStart": 0,
           "dstPortEnd": 0,
           "dstPort1": 0,
           "dstPort2": 0,
           "srcPortStart": 53,
           "srcPortEnd": 0,
           "srcPort1": 0,
           "srcPort2": 0,
           "portStart": 0,
           "portEnd": 0,
           "port1": 0,
           "port2": 0,
           "icmpType": 0,
           "icmpCode": 0,
           "direction": "MAX_DIRECTION",
           "action": "ACCEPT",
           "tcpFlags": "SYN_FLAG",
           "filter_drops": 0,
           "ip": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
           ]
       }
   },{
       "key": {
           "prefix_len": 24,
           "ip_data": [2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0
           ]
       },
       "value": {
           "protocol": 17,
           "dstPortStart": 0,
           "dstPortEnd": 0,
           "dstPort1": 0,
           "dstPort2": 0,
           "srcPortStart": 80,
           "srcPortEnd": 0,
           "srcPort1": 0,
           "srcPort2": 0,
           "portStart": 0,
           "portEnd": 0,
           "port1": 0,
           "port2": 0,
           "icmpType": 0,
           "icmpCode": 0,
           "direction": "MAX_DIRECTION",
           "action": "ACCEPT",
           "tcpFlags": "SYN_FLAG",
           "filter_drops": 0,
           "ip": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
           ]
       }
   },{
       "key": {
           "prefix_len": 24,
           "ip_data": [3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0
           ]
       },
       "value": {
           "protocol": 1,
           "dstPortStart": 0,
           "dstPortEnd": 0,
           "dstPort1": 0,
           "dstPort2": 0,
           "srcPortStart": 0,
           "srcPortEnd": 0,
           "srcPort1": 0,
           "srcPort2": 0,
           "portStart": 0,
           "portEnd": 0,
           "port1": 0,
           "port2": 0,
           "icmpType": 0,
           "icmpCode": 0,
           "direction": "MAX_DIRECTION",
           "action": "ACCEPT",
           "tcpFlags": 0,
           "filter_drops": 0,
           "ip": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
           ]
       }
   }
]

Dependencies

n/a

Checklist

If you are not familiar with our processes or don't know what to answer in the list below, let us know in a comment: the maintainers will take care of that.

  • Will this change affect NetObserv / Network Observability operator? If not, you can ignore the rest of this checklist.
  • Is this PR backed with a JIRA ticket? If so, make sure it is written as a title prefix (in general, PRs affecting the NetObserv/Network Observability product should be backed with a JIRA ticket - especially if they bring user facing changes).
  • Does this PR require product documentation?
  • If so, make sure the JIRA epic is labelled with "documentation" and provides a description relevant for doc writers, such as use cases or scenarios. Any required step to activate or configure the feature should be documented there, such as new CRD knobs.
  • Does this PR require a product release notes entry?
  • If so, fill in "Release Note Text" in the JIRA.
  • Is there anything else the QE team should know before testing? E.g: configuration changes, environment setup, etc.
  • If so, make sure it is described in the JIRA ticket.
  • QE requirements (check 1 from the list):
  • Standard QE validation, with pre-merge tests unless stated otherwise.
  • Regression tests only (e.g. refactoring with no user-facing change).
  • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 10, 2024
@msherif1234
Copy link
Contributor Author

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 10, 2024
Copy link

New image:
quay.io/netobserv/netobserv-ebpf-agent:6139f89

It will expire after two weeks.

To deploy this build, run from the operator repo, assuming the operator is running:

USER=netobserv VERSION=6139f89 make set-agent-image

@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 12, 2024
@msherif1234
Copy link
Contributor Author

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 12, 2024
Copy link

New image:
quay.io/netobserv/netobserv-ebpf-agent:141b6ac

It will expire after two weeks.

To deploy this build, run from the operator repo, assuming the operator is running:

USER=netobserv VERSION=141b6ac make set-agent-image

@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 12, 2024
@msherif1234
Copy link
Contributor Author

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 12, 2024
Copy link

New image:
quay.io/netobserv/netobserv-ebpf-agent:f691cf5

It will expire after two weeks.

To deploy this build, run from the operator repo, assuming the operator is running:

USER=netobserv VERSION=f691cf5 make set-agent-image

@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 12, 2024
@msherif1234
Copy link
Contributor Author

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 12, 2024
Copy link

New image:
quay.io/netobserv/netobserv-ebpf-agent:22832d2

It will expire after two weeks.

To deploy this build, run from the operator repo, assuming the operator is running:

USER=netobserv VERSION=22832d2 make set-agent-image

@github-actions github-actions bot removed the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 13, 2024
@msherif1234
Copy link
Contributor Author

/ok-to-test

@openshift-ci openshift-ci bot added the ok-to-test To set manually when a PR is safe to test. Triggers image build on PR. label Dec 13, 2024
Copy link

New image:
quay.io/netobserv/netobserv-ebpf-agent:405541b

It will expire after two weeks.

To deploy this build, run from the operator repo, assuming the operator is running:

USER=netobserv VERSION=405541b make set-agent-image

Copy link
Contributor

@jpinsonneau jpinsonneau left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @msherif1234 !

@msherif1234
Copy link
Contributor Author

/approve

Copy link

openshift-ci bot commented Dec 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: msherif1234

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@msherif1234 msherif1234 merged commit 7e7f8c4 into netobserv:main Dec 13, 2024
8 of 10 checks passed
@msherif1234 msherif1234 deleted the multi_filter branch December 13, 2024 17:00
@@ -77,15 +79,7 @@ static inline void update_dns(additional_metrics *extra_metrics, pkt_info *pkt,
}

static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
// If sampling is defined, will only parse 1 out of "sampling" flows
Copy link
Member

@jotak jotak Dec 16, 2024

Choose a reason for hiding this comment

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

we could have optimized this, and if no filter_sampling is defined, run the global sampling check earlier. Keep the late sampling check only when there filter-based sampling defined.
So when user runs with no filter-sampling defined, but just global sampling, it's more efficient and doesn't parse headers.

Copy link
Member

@jotak jotak Dec 16, 2024

Choose a reason for hiding this comment

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

Running some perf, while user-space metrics look unchanged, using bpftop I do see a consequent increase in CPU in kernel, around +100%, when using global sampling=50 and no filter sampling, compared to main baseline before this PR was merged.
I've put some numbers here: https://docs.google.com/spreadsheets/d/1BzrAXr-XEWjizBf-tFhtHcKMNyQOvvW2HH4zXeoDxE8/edit?gid=0#gid=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved jira/valid-reference lgtm ok-to-test To set manually when a PR is safe to test. Triggers image build on PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants