Skip to content

Commit

Permalink
tetragon: Adding missing tid setup to HandleGenericEvent
Browse files Browse the repository at this point in the history
We set tid for process part of the event to the tid value
we received from kprobe/uprobe/tracepoint event.

We missed tid update in HandleGenericEvent function which
is called from Retry eventcache events callbacks.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
olsajiri committed May 30, 2023
1 parent 066f7d4 commit 2625699
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions pkg/eventcache/eventcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,19 @@ func HandleGenericInternal(ev notify.Event, pid uint32, tid *uint32, timestamp u
// so we only need to wait for the internal link to the process context to
// resolve PodInfo. This happens when the msg populates the internal state
// but that event is not fully populated yet.
func HandleGenericEvent(internal *process.ProcessInternal, ev notify.Event) error {
func HandleGenericEvent(internal *process.ProcessInternal, ev notify.Event, tid *uint32) error {
p := internal.UnsafeGetProcess()
if option.Config.EnableK8s && p.Pod == nil {
errormetrics.ErrorTotalInc(errormetrics.EventCachePodInfoRetryFailed)
return ErrFailedToGetPodInfo
}

ev.SetProcess(internal.GetProcessCopy())
proc := internal.GetProcessCopy()
// The TID of the cached process can be different from the
// TID that triggered the event, so always use the recorded
// one from bpf.
process.UpdateEventProcessTid(proc, tid)
ev.SetProcess(proc)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/grpc/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (msg *MsgExitEventUnix) RetryInternal(ev notify.Event, timestamp uint64) (*
}

func (msg *MsgExitEventUnix) Retry(internal *process.ProcessInternal, ev notify.Event) error {
return eventcache.HandleGenericEvent(internal, ev)
return eventcache.HandleGenericEvent(internal, ev, &msg.Info.Tid)
}

func (msg *MsgExitEventUnix) HandleMessage() *tetragon.GetEventsResponse {
Expand Down
2 changes: 1 addition & 1 deletion pkg/grpc/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (msg *MsgTestEventUnix) RetryInternal(ev notify.Event, timestamp uint64) (*
}

func (msg *MsgTestEventUnix) Retry(internal *process.ProcessInternal, ev notify.Event) error {
return eventcache.HandleGenericEvent(internal, ev)
return eventcache.HandleGenericEvent(internal, ev, nil)
}

func (msg *MsgTestEventUnix) HandleMessage() *tetragon.GetEventsResponse {
Expand Down
8 changes: 4 additions & 4 deletions pkg/grpc/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (msg *MsgGenericTracepointUnix) RetryInternal(ev notify.Event, timestamp ui
}

func (msg *MsgGenericTracepointUnix) Retry(internal *process.ProcessInternal, ev notify.Event) error {
return eventcache.HandleGenericEvent(internal, ev)
return eventcache.HandleGenericEvent(internal, ev, &msg.Tid)
}

func (msg *MsgGenericTracepointUnix) HandleMessage() *tetragon.GetEventsResponse {
Expand Down Expand Up @@ -357,7 +357,7 @@ func (msg *MsgGenericKprobeUnix) RetryInternal(ev notify.Event, timestamp uint64
}

func (msg *MsgGenericKprobeUnix) Retry(internal *process.ProcessInternal, ev notify.Event) error {
return eventcache.HandleGenericEvent(internal, ev)
return eventcache.HandleGenericEvent(internal, ev, &msg.Tid)
}

func (msg *MsgGenericKprobeUnix) HandleMessage() *tetragon.GetEventsResponse {
Expand Down Expand Up @@ -444,7 +444,7 @@ func (msg *MsgProcessLoaderUnix) RetryInternal(ev notify.Event, timestamp uint64

func (msg *MsgProcessLoaderUnix) Retry(internal *process.ProcessInternal, ev notify.Event) error {
LoaderMetricInc(LoaderResolvedRetry)
return eventcache.HandleGenericEvent(internal, ev)
return eventcache.HandleGenericEvent(internal, ev, nil)
}

func (msg *MsgProcessLoaderUnix) HandleMessage() *tetragon.GetEventsResponse {
Expand Down Expand Up @@ -490,7 +490,7 @@ func (msg *MsgGenericUprobeUnix) RetryInternal(ev notify.Event, timestamp uint64
}

func (msg *MsgGenericUprobeUnix) Retry(internal *process.ProcessInternal, ev notify.Event) error {
return eventcache.HandleGenericEvent(internal, ev)
return eventcache.HandleGenericEvent(internal, ev, &msg.Tid)
}

func GetProcessUprobe(event *MsgGenericUprobeUnix) *tetragon.ProcessUprobe {
Expand Down

0 comments on commit 2625699

Please sign in to comment.