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

tetragon: remove unnecessary GetProcessCopy() #1254

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/eventcache/eventcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func HandleGenericInternal(ev notify.Event, pid uint32, tid *uint32, timestamp u
var err error

if parent != nil {
ev.SetParent(parent.GetProcessCopy())
ev.SetParent(parent.UnsafeGetProcess())
} else {
errormetrics.ErrorTotalInc(errormetrics.EventCacheParentInfoFailed)
err = ErrFailedToGetParentInfo
Expand Down
10 changes: 4 additions & 6 deletions pkg/grpc/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func GetProcessExec(event *MsgExecveEventUnix, useCache bool) *tetragon.ProcessE

if parent != nil {
parent.RefInc()
tetragonEvent.Parent = parent.GetProcessCopy()
}

// do we need to cleanup anything?
Expand Down Expand Up @@ -186,7 +185,7 @@ func (msg *MsgExecveEventUnix) Retry(internal *process.ProcessInternal, ev notif
// want to panic anyway to help us catch the bug faster. So no need to do a nil check
// here.
internal.AddPodInfo(podInfo)
ev.SetProcess(internal.GetProcessCopy())
ev.SetProcess(internal.UnsafeGetProcess())

// Check we have a parent with exception for pid 1, note we do this last because we want
// to ensure the podInfo and process are set before returning any errors.
Expand All @@ -197,7 +196,7 @@ func (msg *MsgExecveEventUnix) Retry(internal *process.ProcessInternal, ev notif
return err
}
parent.RefInc()
ev.SetParent(parent.GetProcessCopy())
ev.SetParent(parent.UnsafeGetProcess())
}

// do we need to cleanup anything?
Expand Down Expand Up @@ -305,11 +304,10 @@ func GetProcessExit(event *MsgExitEventUnix) *tetragon.ProcessExit {
}
if parent != nil {
parent.RefDec()
tetragonEvent.Parent = parent.GetProcessCopy()
}
if proc != nil {
proc.RefDec()
tetragonEvent.Process = proc.GetProcessCopy()
proc.RefDec()
// Use the bpf recorded TID to update the event
process.UpdateEventProcessTid(tetragonEvent.Process, &event.Info.Tid)
}
Expand All @@ -330,11 +328,11 @@ func (msg *MsgExitEventUnix) RetryInternal(ev notify.Event, timestamp uint64) (*
var err error

if parent != nil {
ev.SetParent(parent.UnsafeGetProcess())
if !msg.RefCntDone[ParentRefCnt] {
parent.RefDec()
msg.RefCntDone[ParentRefCnt] = true
}
ev.SetParent(parent.GetProcessCopy())
} else {
errormetrics.ErrorTotalInc(errormetrics.EventCacheParentInfoFailed)
err = eventcache.ErrFailedToGetParentInfo
Expand Down
11 changes: 3 additions & 8 deletions pkg/grpc/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func GetProcessKprobe(event *MsgGenericKprobeUnix) *tetragon.ProcessKprobe {
process.UpdateEventProcessTid(tetragonEvent.Process, &event.Tid)
}
if parent != nil {
tetragonEvent.Parent = parent.GetProcessCopy()
tetragonEvent.Parent = tetragonParent
}

return tetragonEvent
Expand Down Expand Up @@ -334,11 +334,10 @@ func (msg *MsgGenericTracepointUnix) HandleMessage() *tetragon.GetEventsResponse
if proc != nil {
tetragonEvent.Process = proc.GetProcessCopy()
// Use the bpf recorded TID to update the event
// The cost to get this is relatively high because it requires a
// deep copyo of the process in order to safely modify it.
process.UpdateEventProcessTid(tetragonEvent.Process, &msg.Tid)
}
if parent != nil {
tetragonEvent.Parent = parent.GetProcessCopy()
}

return &tetragon.GetEventsResponse{
Event: &tetragon.GetEventsResponse_ProcessTracepoint{ProcessTracepoint: tetragonEvent},
Expand Down Expand Up @@ -557,10 +556,6 @@ func GetProcessUprobe(event *MsgGenericUprobeUnix) *tetragon.ProcessUprobe {
// Use the bpf recorded TID to update the event
process.UpdateEventProcessTid(tetragonEvent.Process, &event.Tid)
}
if parent != nil {
tetragonEvent.Parent = parent.GetProcessCopy()
}

return tetragonEvent
}

Expand Down