Skip to content

tetragon: Allow retry logic for clone events #362

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

Merged
merged 2 commits into from
Aug 26, 2022
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
4 changes: 4 additions & 0 deletions pkg/api/readyapi/readyapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (

type MsgTetragonReady struct{}

func (msg *MsgTetragonReady) Notify() bool {
return false
}

func (msg *MsgTetragonReady) RetryInternal(ev notify.Event, timestamp uint64) (*process.ProcessInternal, error) {
return nil, fmt.Errorf("Unsupported cache event MsgTetragonReady")
}
Expand Down
14 changes: 8 additions & 6 deletions pkg/eventcache/eventcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ func (ec *Cache) handleEvents() {
}
}

processedEvent := &tetragon.GetEventsResponse{
Event: event.event.Encapsulate(),
NodeName: nodeName,
Time: ktime.ToProto(event.timestamp),
}
if event.msg.Notify() {
processedEvent := &tetragon.GetEventsResponse{
Event: event.event.Encapsulate(),
NodeName: nodeName,
Time: ktime.ToProto(event.timestamp),
}

ec.server.NotifyListeners(event.msg, processedEvent)
ec.server.NotifyListeners(event.msg, processedEvent)
}
}
ec.cache = tmp
}
Expand Down
23 changes: 20 additions & 3 deletions pkg/grpc/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ type MsgExecveEventUnix struct {
processapi.MsgExecveEventUnix
}

func (msg *MsgExecveEventUnix) Notify() bool {
return true
}

func (msg *MsgExecveEventUnix) RetryInternal(ev notify.Event, timestamp uint64) (*process.ProcessInternal, error) {
return nil, fmt.Errorf("Unreachable state: MsgExecveEventUnix with missing internal")
}
Expand Down Expand Up @@ -142,18 +146,27 @@ type MsgCloneEventUnix struct {
processapi.MsgCloneEvent
}

func (msg *MsgCloneEventUnix) Notify() bool {
return false
}

func (msg *MsgCloneEventUnix) RetryInternal(ev notify.Event, timestamp uint64) (*process.ProcessInternal, error) {
return nil, fmt.Errorf("Unreachable state: MsgCloneEventUnix with missing internal")
return nil, process.AddCloneEvent(&msg.MsgCloneEvent)
}

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

func (msg *MsgCloneEventUnix) HandleMessage() *tetragon.GetEventsResponse {
switch msg.Common.Op {
case ops.MSG_OP_CLONE:
process.AddCloneEvent(&msg.MsgCloneEvent)
if err := process.AddCloneEvent(&msg.MsgCloneEvent); err != nil {
ec := eventcache.Get()
if ec != nil {
ec.Add(nil, nil, msg.MsgCloneEvent.Ktime, msg)
}
}
default:
logger.GetLogger().WithField("message", msg).Warn("HandleCloneMessage: Unhandled event")
}
Expand Down Expand Up @@ -207,6 +220,10 @@ type MsgExitEventUnix struct {
tetragonAPI.MsgExitEvent
}

func (msg *MsgExitEventUnix) Notify() bool {
return true
}

func (msg *MsgExitEventUnix) RetryInternal(ev notify.Event, timestamp uint64) (*process.ProcessInternal, error) {
p := ev.GetProcess()
internal, parent := process.GetParentProcessInternal(p.Pid.Value, timestamp)
Expand Down
4 changes: 4 additions & 0 deletions pkg/grpc/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ type MsgTestEventUnix struct {
testapi.MsgTestEvent
}

func (msg *MsgTestEventUnix) Notify() bool {
return true
}

func (msg *MsgTestEventUnix) RetryInternal(ev notify.Event, timestamp uint64) (*process.ProcessInternal, error) {
return eventcache.HandleGenericInternal(ev, timestamp)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/grpc/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ type MsgGenericTracepointUnix struct {
Args []tracingapi.MsgGenericTracepointArg
}

func (msg *MsgGenericTracepointUnix) Notify() bool {
return true
}

func (msg *MsgGenericTracepointUnix) RetryInternal(ev notify.Event, timestamp uint64) (*process.ProcessInternal, error) {
return eventcache.HandleGenericInternal(ev, timestamp)
}
Expand Down Expand Up @@ -282,6 +286,10 @@ type MsgGenericKprobeUnix struct {
Args []tracingapi.MsgGenericKprobeArg
}

func (msg *MsgGenericKprobeUnix) Notify() bool {
return true
}

func (msg *MsgGenericKprobeUnix) RetryInternal(ev notify.Event, timestamp uint64) (*process.ProcessInternal, error) {
return eventcache.HandleGenericInternal(ev, timestamp)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ func AddExecEvent(event *tetragonAPI.MsgExecveEventUnix) *ProcessInternal {
}

// AddCloneEvent adds a new process into the cache from a CloneEvent
func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) {
func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) error {
parentExecId := GetProcessID(event.Parent.Pid, event.Parent.Ktime)
parent, err := Get(parentExecId)
if err != nil {
logger.GetLogger().WithField("parent-exec-id", parentExecId).Debug("AddCloneEvent: process not found in cache")
return
return err
}
pi := parent.GetProcessInternalCopy()
if pi.process != nil {
Expand All @@ -288,6 +288,7 @@ func AddCloneEvent(event *tetragonAPI.MsgCloneEvent) {
}
}
procCache.Add(pi)
return nil
}

func Get(execId string) (*ProcessInternal, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/reader/notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Message interface {
HandleMessage() *tetragon.GetEventsResponse
RetryInternal(Event, uint64) (*process.ProcessInternal, error)
Retry(*process.ProcessInternal, Event) error
Notify() bool
}

type Event interface {
Expand Down