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

refactor(monitor) : add debug logs #969

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions KubeArmor/monitor/systemMonitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,8 @@ type SystemMonitor struct {
ContextChan chan ContextCombined

// system events
SyscallChannel chan []byte
SyscallLostChannel chan uint64
SyscallPerfMap *perf.Reader
SyscallChannel chan []byte
SyscallPerfMap *perf.Reader

// lists to skip
UntrackedNamespaces []string
Expand Down Expand Up @@ -356,7 +355,6 @@ func (mon *SystemMonitor) InitBPF() error {
}

mon.SyscallChannel = make(chan []byte, 8192)
mon.SyscallLostChannel = make(chan uint64)

mon.SyscallPerfMap, err = perf.NewReader(mon.BpfModule.Maps["sys_events"], os.Getpagesize()*1024)
if err != nil {
Expand Down Expand Up @@ -406,13 +404,16 @@ func (mon *SystemMonitor) TraceSyscall() {
record, err := mon.SyscallPerfMap.Read()
if err != nil {
if errors.Is(err, perf.ErrClosed) {
// This should only happen when we call DestroyMonitor while terminating the process.
// Adding a Warn just in case it happens at runtime, to help debug
mon.Logger.Warnf("Perf Buffer closed, exiting TraceSyscall %s", err.Error())
return
}
continue
}

if record.LostSamples != 0 {
mon.SyscallLostChannel <- record.LostSamples
mon.Logger.Warnf("Lost Perf Events Count : %d", record.LostSamples)
continue
}

Expand All @@ -421,6 +422,7 @@ func (mon *SystemMonitor) TraceSyscall() {
}
}()
} else {
mon.Logger.Err("Perf Buffer nil, exiting TraceSyscall")
return
}

Expand Down Expand Up @@ -704,9 +706,6 @@ func (mon *SystemMonitor) TraceSyscall() {

// push the context to the channel for logging
mon.ContextChan <- ContextCombined{ContainerID: containerID, ContextSys: ctx, ContextArgs: args}

case <-mon.SyscallLostChannel:
continue
}
}
}