Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
netobserv-ebpf-agent
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hdacloud
netobserv-ebpf-agent
Commits
504add4c
Unverified
Commit
504add4c
authored
1 year ago
by
Mohamed S. Mahmoud
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
use cached api to retrieve interface name to avoid highcpu (#251)
Signed-off-by:
Mohamed Mahmoud
<
mmahmoud@redhat.com
>
parent
3f14e8e3
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
pkg/agent/agent.go
+1
-1
1 addition, 1 deletion
pkg/agent/agent.go
pkg/flow/deduper.go
+5
-6
5 additions, 6 deletions
pkg/flow/deduper.go
pkg/flow/deduper_test.go
+14
-6
14 additions, 6 deletions
pkg/flow/deduper_test.go
pkg/utils/utils.go
+0
-8
0 additions, 8 deletions
pkg/utils/utils.go
with
20 additions
and
21 deletions
pkg/agent/agent.go
+
1
−
1
View file @
504add4c
...
@@ -422,7 +422,7 @@ func (f *Flows) buildAndStartPipeline(ctx context.Context) (*node.Terminal[[]*fl
...
@@ -422,7 +422,7 @@ func (f *Flows) buildAndStartPipeline(ctx context.Context) (*node.Terminal[[]*fl
rbTracer
.
SendsTo
(
accounter
)
rbTracer
.
SendsTo
(
accounter
)
if
f
.
cfg
.
Deduper
==
DeduperFirstCome
{
if
f
.
cfg
.
Deduper
==
DeduperFirstCome
{
deduper
:=
node
.
AsMiddle
(
flow
.
Dedupe
(
f
.
cfg
.
DeduperFCExpiry
,
f
.
cfg
.
DeduperJustMark
,
f
.
cfg
.
DeduperMerge
),
deduper
:=
node
.
AsMiddle
(
flow
.
Dedupe
(
f
.
cfg
.
DeduperFCExpiry
,
f
.
cfg
.
DeduperJustMark
,
f
.
cfg
.
DeduperMerge
,
f
.
interfaceNamer
),
node
.
ChannelBufferLen
(
f
.
cfg
.
BuffersLength
))
node
.
ChannelBufferLen
(
f
.
cfg
.
BuffersLength
))
mapTracer
.
SendsTo
(
deduper
)
mapTracer
.
SendsTo
(
deduper
)
accounter
.
SendsTo
(
deduper
)
accounter
.
SendsTo
(
deduper
)
...
...
This diff is collapsed.
Click to expand it.
pkg/flow/deduper.go
+
5
−
6
View file @
504add4c
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/netobserv/netobserv-ebpf-agent/pkg/ebpf"
"github.com/netobserv/netobserv-ebpf-agent/pkg/ebpf"
"github.com/netobserv/netobserv-ebpf-agent/pkg/utils"
)
)
var
dlog
=
logrus
.
WithField
(
"component"
,
"flow/Deduper"
)
var
dlog
=
logrus
.
WithField
(
"component"
,
"flow/Deduper"
)
...
@@ -40,7 +39,7 @@ type entry struct {
...
@@ -40,7 +39,7 @@ type entry struct {
// (no activity for it during the expiration time)
// (no activity for it during the expiration time)
// The justMark argument tells that the deduper should not drop the duplicate flows but
// The justMark argument tells that the deduper should not drop the duplicate flows but
// set their Duplicate field.
// set their Duplicate field.
func
Dedupe
(
expireTime
time
.
Duration
,
justMark
,
mergeDup
bool
)
func
(
in
<-
chan
[]
*
Record
,
out
chan
<-
[]
*
Record
)
{
func
Dedupe
(
expireTime
time
.
Duration
,
justMark
,
mergeDup
bool
,
ifaceNamer
InterfaceNamer
)
func
(
in
<-
chan
[]
*
Record
,
out
chan
<-
[]
*
Record
)
{
cache
:=
&
deduperCache
{
cache
:=
&
deduperCache
{
expire
:
expireTime
,
expire
:
expireTime
,
entries
:
list
.
New
(),
entries
:
list
.
New
(),
...
@@ -51,7 +50,7 @@ func Dedupe(expireTime time.Duration, justMark, mergeDup bool) func(in <-chan []
...
@@ -51,7 +50,7 @@ func Dedupe(expireTime time.Duration, justMark, mergeDup bool) func(in <-chan []
cache
.
removeExpired
()
cache
.
removeExpired
()
fwd
:=
make
([]
*
Record
,
0
,
len
(
records
))
fwd
:=
make
([]
*
Record
,
0
,
len
(
records
))
for
_
,
record
:=
range
records
{
for
_
,
record
:=
range
records
{
cache
.
checkDupe
(
record
,
justMark
,
mergeDup
,
&
fwd
)
cache
.
checkDupe
(
record
,
justMark
,
mergeDup
,
&
fwd
,
ifaceNamer
)
}
}
if
len
(
fwd
)
>
0
{
if
len
(
fwd
)
>
0
{
out
<-
fwd
out
<-
fwd
...
@@ -61,7 +60,7 @@ func Dedupe(expireTime time.Duration, justMark, mergeDup bool) func(in <-chan []
...
@@ -61,7 +60,7 @@ func Dedupe(expireTime time.Duration, justMark, mergeDup bool) func(in <-chan []
}
}
// checkDupe check current record if its already available nad if not added to fwd records list
// checkDupe check current record if its already available nad if not added to fwd records list
func
(
c
*
deduperCache
)
checkDupe
(
r
*
Record
,
justMark
,
mergeDup
bool
,
fwd
*
[]
*
Record
)
{
func
(
c
*
deduperCache
)
checkDupe
(
r
*
Record
,
justMark
,
mergeDup
bool
,
fwd
*
[]
*
Record
,
ifaceNamer
InterfaceNamer
)
{
mergeEntry
:=
make
(
map
[
string
]
uint8
)
mergeEntry
:=
make
(
map
[
string
]
uint8
)
rk
:=
r
.
Id
rk
:=
r
.
Id
// zeroes fields from key that should be ignored from the flow comparison
// zeroes fields from key that should be ignored from the flow comparison
...
@@ -95,7 +94,7 @@ func (c *deduperCache) checkDupe(r *Record, justMark, mergeDup bool, fwd *[]*Rec
...
@@ -95,7 +94,7 @@ func (c *deduperCache) checkDupe(r *Record, justMark, mergeDup bool, fwd *[]*Rec
*
fwd
=
append
(
*
fwd
,
r
)
*
fwd
=
append
(
*
fwd
,
r
)
}
}
if
mergeDup
{
if
mergeDup
{
ifName
:=
utils
.
GetInter
faceName
(
r
.
Id
.
IfIndex
)
ifName
:=
i
faceName
r
(
int
(
r
.
Id
.
IfIndex
)
)
mergeEntry
[
ifName
]
=
r
.
Id
.
Direction
mergeEntry
[
ifName
]
=
r
.
Id
.
Direction
if
dupEntryNew
(
*
fEntry
.
dupList
,
mergeEntry
)
{
if
dupEntryNew
(
*
fEntry
.
dupList
,
mergeEntry
)
{
*
fEntry
.
dupList
=
append
(
*
fEntry
.
dupList
,
mergeEntry
)
*
fEntry
.
dupList
=
append
(
*
fEntry
.
dupList
,
mergeEntry
)
...
@@ -122,7 +121,7 @@ func (c *deduperCache) checkDupe(r *Record, justMark, mergeDup bool, fwd *[]*Rec
...
@@ -122,7 +121,7 @@ func (c *deduperCache) checkDupe(r *Record, justMark, mergeDup bool, fwd *[]*Rec
expiryTime
:
timeNow
()
.
Add
(
c
.
expire
),
expiryTime
:
timeNow
()
.
Add
(
c
.
expire
),
}
}
if
mergeDup
{
if
mergeDup
{
ifName
:=
utils
.
GetInter
faceName
(
r
.
Id
.
IfIndex
)
ifName
:=
i
faceName
r
(
int
(
r
.
Id
.
IfIndex
)
)
mergeEntry
[
ifName
]
=
r
.
Id
.
Direction
mergeEntry
[
ifName
]
=
r
.
Id
.
Direction
r
.
DupList
=
append
(
r
.
DupList
,
mergeEntry
)
r
.
DupList
=
append
(
r
.
DupList
,
mergeEntry
)
e
.
dupList
=
&
r
.
DupList
e
.
dupList
=
&
r
.
DupList
...
...
This diff is collapsed.
Click to expand it.
pkg/flow/deduper_test.go
+
14
−
6
View file @
504add4c
package
flow
package
flow
import
(
import
(
"net"
"testing"
"testing"
"time"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/netobserv/netobserv-ebpf-agent/pkg/ebpf"
"github.com/netobserv/netobserv-ebpf-agent/pkg/ebpf"
"github.com/netobserv/netobserv-ebpf-agent/pkg/utils"
)
)
var
(
var
(
...
@@ -70,7 +70,7 @@ func TestDedupe(t *testing.T) {
...
@@ -70,7 +70,7 @@ func TestDedupe(t *testing.T) {
input
:=
make
(
chan
[]
*
Record
,
100
)
input
:=
make
(
chan
[]
*
Record
,
100
)
output
:=
make
(
chan
[]
*
Record
,
100
)
output
:=
make
(
chan
[]
*
Record
,
100
)
go
Dedupe
(
time
.
Minute
,
false
,
false
)(
input
,
output
)
go
Dedupe
(
time
.
Minute
,
false
,
false
,
interfaceNamer
)(
input
,
output
)
input
<-
[]
*
Record
{
input
<-
[]
*
Record
{
oneIf2
,
// record 1 at interface 2: should be accepted
oneIf2
,
// record 1 at interface 2: should be accepted
...
@@ -108,7 +108,7 @@ func TestDedupe_EvictFlows(t *testing.T) {
...
@@ -108,7 +108,7 @@ func TestDedupe_EvictFlows(t *testing.T) {
input
:=
make
(
chan
[]
*
Record
,
100
)
input
:=
make
(
chan
[]
*
Record
,
100
)
output
:=
make
(
chan
[]
*
Record
,
100
)
output
:=
make
(
chan
[]
*
Record
,
100
)
go
Dedupe
(
15
*
time
.
Second
,
false
,
false
)(
input
,
output
)
go
Dedupe
(
15
*
time
.
Second
,
false
,
false
,
interfaceNamer
)(
input
,
output
)
// Should only accept records 1 and 2, at interface 1
// Should only accept records 1 and 2, at interface 1
input
<-
[]
*
Record
{
oneIf1
,
twoIf1
,
oneIf2
}
input
<-
[]
*
Record
{
oneIf1
,
twoIf1
,
oneIf2
}
...
@@ -143,7 +143,7 @@ func TestDedupeMerge(t *testing.T) {
...
@@ -143,7 +143,7 @@ func TestDedupeMerge(t *testing.T) {
input
:=
make
(
chan
[]
*
Record
,
100
)
input
:=
make
(
chan
[]
*
Record
,
100
)
output
:=
make
(
chan
[]
*
Record
,
100
)
output
:=
make
(
chan
[]
*
Record
,
100
)
go
Dedupe
(
time
.
Minute
,
false
,
true
)(
input
,
output
)
go
Dedupe
(
time
.
Minute
,
false
,
true
,
interfaceNamer
)(
input
,
output
)
input
<-
[]
*
Record
{
input
<-
[]
*
Record
{
oneIf2
,
// record 1 at interface 2: should be accepted
oneIf2
,
// record 1 at interface 2: should be accepted
...
@@ -155,10 +155,10 @@ func TestDedupeMerge(t *testing.T) {
...
@@ -155,10 +155,10 @@ func TestDedupeMerge(t *testing.T) {
expectedMap
:=
[]
map
[
string
]
uint8
{
expectedMap
:=
[]
map
[
string
]
uint8
{
{
{
utils
.
GetI
nterfaceName
(
oneIf2
.
Id
.
IfIndex
)
:
oneIf2
.
Id
.
Direction
,
i
nterfaceName
r
(
int
(
oneIf2
.
Id
.
IfIndex
)
)
:
oneIf2
.
Id
.
Direction
,
},
},
{
{
utils
.
GetI
nterfaceName
(
oneIf1
.
Id
.
IfIndex
)
:
oneIf1
.
Id
.
Direction
,
i
nterfaceName
r
(
int
(
oneIf1
.
Id
.
IfIndex
)
)
:
oneIf1
.
Id
.
Direction
,
},
},
}
}
...
@@ -174,3 +174,11 @@ type timerMock struct {
...
@@ -174,3 +174,11 @@ type timerMock struct {
func
(
tm
*
timerMock
)
Now
()
time
.
Time
{
func
(
tm
*
timerMock
)
Now
()
time
.
Time
{
return
tm
.
now
return
tm
.
now
}
}
func
interfaceNamer
(
ifIndex
int
)
string
{
iface
,
err
:=
net
.
InterfaceByIndex
(
ifIndex
)
if
err
!=
nil
{
return
"unknown"
}
return
iface
.
Name
}
This diff is collapsed.
Click to expand it.
pkg/utils/utils.go
+
0
−
8
View file @
504add4c
...
@@ -91,11 +91,3 @@ func utsnameStr[T int8 | uint8](in []T) string {
...
@@ -91,11 +91,3 @@ func utsnameStr[T int8 | uint8](in []T) string {
}
}
return
string
(
out
)
return
string
(
out
)
}
}
func
GetInterfaceName
(
ifIndex
uint32
)
string
{
iface
,
err
:=
net
.
InterfaceByIndex
(
int
(
ifIndex
))
if
err
!=
nil
{
return
"unknown"
}
return
iface
.
Name
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment