-
Notifications
You must be signed in to change notification settings - Fork 360
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
Add support to dump processCache #2246
Conversation
✅ Deploy Preview for tetragon ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
ceb385b
to
7bff683
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.
Much appreciated @tpapagian ;-)
When merged I will add a send signal to also dump this to logs
api/v1/tetragon/sensors.proto
Outdated
@@ -118,6 +121,20 @@ message GetVersionResponse{ | |||
string version = 1; | |||
} | |||
|
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.
Could you please add comments here so they show up on gRPC reference doc, that this is for debugging only , do not 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.
Used generic GetDebugRequest rpc call.
google.protobuf.UInt32Value refcnt = 3; | ||
string refcntOps = 4; | ||
} | ||
|
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.
same here and others, as we may change later have a generic debugDump with what to dump as an encoded operation for all type of dumps
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.
Also what does refcntOps mean 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.
same here and others, as we may change later have a generic debugDump with what to dump as an encoded operation for all type of dumps
Used generic GetDebugRequest
rpc call.
Also what does refcntOps mean here?
Added a comment there.
@@ -83,7 +83,7 @@ func GetProcessExec(event *MsgExecveEventUnix, useCache bool) *tetragon.ProcessE | |||
} | |||
|
|||
if parent != nil { | |||
parent.RefInc() | |||
parent.RefInc("parent") |
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.
maybe pass int constants and decode later to strings? up to you
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 make a try but this seems to complicate things a bit. So I would propose to keep that as it is if there are no objections from your side.
pkg/process/process.go
Outdated
refcnt uint32 | ||
color int // Writes should happen only inside gc select channel | ||
refcnt uint32 | ||
refcntOps map[string]int |
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 does refcntOps mean here? having some comments will help ;-)
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.
Added a comment there.
pkg/process/cache.go
Outdated
func (pc *Cache) refDec(p *ProcessInternal, reason string) { | ||
p.refcntOpsLock.Lock() | ||
if val, ok := p.refcntOps[reason]; ok { | ||
p.refcntOps[reason] = val + 1 |
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 guess the reason here could be parent or process right? a bit confused why it is an increment? what value we get from this? my simplest suggestion would say having a separate track of increment and decrements could be better, but I'm missing something 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.
This would be something like:
"refcntOps": {
"parent++": 2,
"parent--": 1,
"process++": 1
}
which means that we count separately all increase and decrease operations. So the reason here can be: process++
, process--
, parent++
, or parent--
.
97d38a5
to
265664d
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! That would be a great debug addition :) thanks for reviving this PR.
This patch adds support to print the contents of process cache. This may be useful during debugging. Example: $ sudo ./tetra dump processCache {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6MTAwNjgwMDAwMDAwOjE4OTg=", "pid":1898, "uid":1010, "cwd":"/home/apapag", "binary":"/home/apapag/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/node", "arguments":"--dns-result-order=ipv4first /home/apapag/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/out/bootstrap-fork --type=extensionHost --transformURIs --useHostProxy=false", "flags":"procFS auid", "start_time":"2024-09-05T07:00:23.274832687Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6ODk5NTAwMDAwMDA6MTc3Ng==", "tid":1898}, "color":"inUse", "refcnt":5, "refcntOps":{"parent++":346, "parent--":342, "process++":1}} {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6MTU2OTQ0MDAwMDAwMDozMzM3OA==", "pid":33378, "uid":1010, "cwd":"/home/apapag/tetragon", "binary":"/usr/bin/bash", "flags":"procFS auid", "start_time":"2024-09-05T07:24:52.034832554Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6MTU2OTIyMDAwMDAwMDozMzM3Nw==", "tid":33378}, "color":"inUse", "refcnt":2, "refcntOps":{"parent++":30, "parent--":29, "process++":1}} {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM2Nzc1Nzc4NDo1MjE1Mg==", "pid":52152, "uid":0, "cwd":"/home/apapag/tetragon", "binary":"/usr/bin/sudo", "arguments":"./tetra dump processCache --skip-zero-refcnt", "flags":"execve clone", "start_time":"2024-09-05T07:46:14.962590751Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6MTU2OTQ0MDAwMDAwMDozMzM3OA==", "tid":52152}, "color":"inUse", "refcnt":2, "refcntOps":{"parent++":1, "process++":1}} {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM3NjMxOTI2OTo1MjE1NA==", "pid":52154, "uid":0, "cwd":"/home/apapag/tetragon", "binary":"/home/apapag/tetragon/tetra", "arguments":"dump processCache --skip-zero-refcnt", "flags":"execve clone", "start_time":"2024-09-05T07:46:14.971151996Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM3NTU4MTQxMTo1MjE1Mw==", "tid":52154}, "color":"inUse", "refcnt":1, "refcntOps":{"process++":1}} {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM3NTU4MTQxMTo1MjE1Mw==", "pid":52153, "uid":0, "cwd":"/home/apapag/tetragon", "binary":"/usr/bin/sudo", "arguments":"./tetra dump processCache --skip-zero-refcnt", "flags":"execve", "start_time":"2024-09-05T07:46:14.970414578Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM2Nzc1Nzc4NDo1MjE1Mg==", "refcnt":1, "tid":52153}, "color":"inUse", "refcnt":2, "refcntOps":{"parent++":2, "parent--":1, "process++":1}} [...] We also provide "--skip-zero-refcnt" command line argument to print only the entries with refcnt not equals to zero. $ sudo ./tetra dump processCache --skip-zero-refcnt {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6MTAwNjgwMDAwMDAwOjE4OTg=", "pid":1898, "uid":1010, "cwd":"/home/apapag", "binary":"/home/apapag/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/node", "arguments":"--dns-result-order=ipv4first /home/apapag/.vscode-server/cli/servers/Stable-fee1edb8d6d72a0ddff41e5f71a671c23ed924b9/server/out/bootstrap-fork --type=extensionHost --transformURIs --useHostProxy=false", "flags":"procFS auid", "start_time":"2024-09-05T07:00:23.274832687Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6ODk5NTAwMDAwMDA6MTc3Ng==", "tid":1898}, "color":"inUse", "refcnt":5, "refcntOps":{"parent++":346, "parent--":342, "process++":1}} {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6MTU2OTQ0MDAwMDAwMDozMzM3OA==", "pid":33378, "uid":1010, "cwd":"/home/apapag/tetragon", "binary":"/usr/bin/bash", "flags":"procFS auid", "start_time":"2024-09-05T07:24:52.034832554Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6MTU2OTIyMDAwMDAwMDozMzM3Nw==", "tid":33378}, "color":"inUse", "refcnt":2, "refcntOps":{"parent++":30, "parent--":29, "process++":1}} {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM2Nzc1Nzc4NDo1MjE1Mg==", "pid":52152, "uid":0, "cwd":"/home/apapag/tetragon", "binary":"/usr/bin/sudo", "arguments":"./tetra dump processCache --skip-zero-refcnt", "flags":"execve clone", "start_time":"2024-09-05T07:46:14.962590751Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6MTU2OTQ0MDAwMDAwMDozMzM3OA==", "tid":52152}, "color":"inUse", "refcnt":2, "refcntOps":{"parent++":1, "process++":1}} {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM3NjMxOTI2OTo1MjE1NA==", "pid":52154, "uid":0, "cwd":"/home/apapag/tetragon", "binary":"/home/apapag/tetragon/tetra", "arguments":"dump processCache --skip-zero-refcnt", "flags":"execve clone", "start_time":"2024-09-05T07:46:14.971151996Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM3NTU4MTQxMTo1MjE1Mw==", "tid":52154}, "color":"inUse", "refcnt":1, "refcntOps":{"process++":1}} {"process":{"exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM3NTU4MTQxMTo1MjE1Mw==", "pid":52153, "uid":0, "cwd":"/home/apapag/tetragon", "binary":"/usr/bin/sudo", "arguments":"./tetra dump processCache --skip-zero-refcnt", "flags":"execve", "start_time":"2024-09-05T07:46:14.970414578Z", "auid":1010, "parent_exec_id":"YXBhcGFnLXVidW50dS1kZXY6Mjg1MjM2Nzc1Nzc4NDo1MjE1Mg==", "refcnt":1, "tid":52153}, "color":"inUse", "refcnt":2, "refcntOps":{"parent++":2, "parent--":1, "process++":1}} [...] Signed-off-by: Anastasios Papagiannis <[email protected]>
265664d
to
24fdda8
Compare
Hey @tpapagian any chance we could get this backported into v1.2? |
Sure! Will do that during the next week or so. |
Backport: #3038 |
This patch adds support to print the contents of process cache. This may be useful during debugging.
Example:
We also provide "--skip-zero-refcnt" command line argument to print only the entries with refcnt not equals to zero.