-
Notifications
You must be signed in to change notification settings - Fork 185
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
socket enricher: Use single instance for multiple gadgets #2324
Conversation
f978966
to
8849525
Compare
fc775e7
to
93b7e47
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
func (t *Tracer) SetSocketEnricherMap(m *ebpf.Map) { | ||
t.socketEnricherMap = m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it mean that image-based gadgets would still inconditionally create the socket enricher, even if they don't use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
93b7e47
to
4ea4466
Compare
There's something going on with the tests on this PR. Holding until I have the chance to investigate more. |
At least for |
4ea4466
to
a310bbd
Compare
7cf681b
to
18710d6
Compare
a310bbd
to
54895fb
Compare
81a62ba
to
321ec53
Compare
7de748a
to
bc86a15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi.
I will take a deeper look later, but I have some initial comments.
Best regards.
socketEnricherOp := operators.GetRaw(socketenricher.OperatorName).(*socketenricher.SocketEnricher) | ||
socketEnricherOp.Init(nil) | ||
t.socketEnricherInst, err = socketEnricherOp.Instantiate(nil, t.tracer, nil) | ||
if err == nil { | ||
t.socketEnricherInst.PreGadgetRun() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering if we cannot factorize this whole logic using an array and a loop.
For now, it is OK, but if we keep adding operators, the code will definitely grow and we should avoid this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole file is legacy and all this operators-related stuff there is a big hack, I hope we can get rid of it very soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we need to get rid of it?
Cannot we just drop it now?
bc86a15
to
65c46d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good optimization!
I tested it and we still have N to N maps but only 1 to N instance:
$ ps aux | grep ./ig (remotes/origin/mauricio/optmize-socket-enricher) %
root 40174 0.0 0.0 16740 5632 pts/4 SN 11:38 0:00 sudo ./ig trace network
root 40178 0.0 0.0 16740 2296 pts/5 SNs+ 11:38 0:00 sudo ./ig trace network
root 40179 0.5 0.2 5635336 96668 pts/5 SNl 11:38 0:02 ./ig trace network
root 40210 0.0 0.0 16744 5632 pts/4 SN 11:38 0:00 sudo ./ig trace dns
root 40214 0.0 0.0 16744 2296 pts/6 SNs+ 11:38 0:00 sudo ./ig trace dns
root 40215 0.6 0.3 5635016 97600 pts/6 SNl 11:38 0:03 ./ig trace dns
francis 40788 0.0 0.0 11780 2560 pts/4 S+ 11:47 0:00 grep --color=auto ./ig
$ sudo bpftool map list | grep 'gadget_sockets'
67: hash name gadget_sockets flags 0x0
90: hash name gadget_sockets flags 0x0
|
||
i.manager.refCount-- | ||
if i.manager.refCount == 0 { | ||
i.manager.socketEnricher.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't there a way to call the above Close()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but I think the semantics are not the same. (s *SocketEnricher) Close()
should destroy everything related to the parent, while (i *SocketEnricherInstance) PostGadgetRun()
is only for this instance. They are exactly the same now, but they could be different later on.
Move it to a non-internal pkg to use it on the next commits. Signed-off-by: Mauricio Vasquez <mauriciov@microsoft.com>
Split the logic into Init() and Run() functions. Init() now only installs the network tracer, and Run() runs it. It's needed by the following commit because the socket enricher operator sets the map after Init() but before Run(). Signed-off-by: Mauricio Vasquez <mauriciov@microsoft.com>
Implement a new operator that provides the socket enricher map to gadgets using it. Signed-off-by: Mauricio Vasquez <mauriciov@microsoft.com>
Implement the SetSocketEnricherMap() interface in gadgets using it. Signed-off-by: Mauricio Vasquez <mauriciov@microsoft.com>
Fixes: 35b9e87 ("socket enricher: make iterators optional") Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
See #2364 Signed-off-by: Mauricio Vásquez <mauriciov@microsoft.com>
65c46d4
to
85e8b3f
Compare
Check the details in #1695.
Fixes #1695