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

[backport/v1.0][bugfix] Fix clone event caching due to missing pod info #2905

Merged
merged 1 commit into from
Sep 24, 2024
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
23 changes: 19 additions & 4 deletions pkg/grpc/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,34 @@ func (msg *MsgCloneEventUnix) Notify() bool {
}

func (msg *MsgCloneEventUnix) RetryInternal(_ notify.Event, _ uint64) (*process.ProcessInternal, error) {
return nil, process.AddCloneEvent(&msg.MsgCloneEvent)
return process.AddCloneEvent(&msg.MsgCloneEvent)
}

func (msg *MsgCloneEventUnix) Retry(_ *process.ProcessInternal, _ notify.Event) error {
func (msg *MsgCloneEventUnix) Retry(internal *process.ProcessInternal, _ notify.Event) error {
proc := internal.UnsafeGetProcess()
if option.Config.EnableK8s && proc.Docker != "" && proc.Pod == nil {
podInfo := process.GetPodInfo(proc.Docker, proc.Binary, proc.Arguments, msg.NSPID)
if podInfo == nil {
errormetrics.ErrorTotalInc(errormetrics.EventCachePodInfoRetryFailed)
return eventcache.ErrFailedToGetPodInfo
}
internal.AddPodInfo(podInfo)
}
return nil
}

func (msg *MsgCloneEventUnix) HandleMessage() *tetragon.GetEventsResponse {
switch msg.Common.Op {
case ops.MSG_OP_CLONE:
if err := process.AddCloneEvent(&msg.MsgCloneEvent); err != nil {
ec := eventcache.Get()
ec := eventcache.Get()
if internal, err := process.AddCloneEvent(&msg.MsgCloneEvent); err == nil {
if ec != nil && ec.Needed(internal.UnsafeGetProcess()) {
// adding to the cache due to missing pod info
ec.Add(internal, nil, msg.MsgCloneEvent.Common.Ktime, msg.MsgCloneEvent.Ktime, msg)
}
} else {
if ec != nil {
// adding to the cache due to missing parent
ec.Add(nil, nil, msg.MsgCloneEvent.Common.Ktime, msg.MsgCloneEvent.Ktime, msg)
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func AddExecEvent(event *tetragonAPI.MsgExecveEventUnix) *ProcessInternal {
}

// AddCloneEvent adds a new process into the cache from a CloneEvent
func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) error {
func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) (*ProcessInternal, error) {
parentExecId := GetProcessID(event.Parent.Pid, event.Parent.Ktime)
parent, err := Get(parentExecId)
if err != nil {
Expand All @@ -449,17 +449,17 @@ func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) error {
"event.parent.pid": event.Parent.Pid,
"event.parent.exec_id": parentExecId,
}).WithError(err).Debug("CloneEvent: parent process not found in cache")
return err
return nil, err
}

proc, err := initProcessInternalClone(event, parent, parentExecId)
if err != nil {
return err
return nil, err
}

parent.RefInc()
procCache.add(proc)
return nil
return proc, nil
}

func Get(execId string) (*ProcessInternal, error) {
Expand Down
Loading