Skip to content

Commit 582c56a

Browse files
authored
chore: improve e2e and pipeline for debuggability (#4552)
1 parent 3ac936c commit 582c56a

File tree

2 files changed

+44
-20
lines changed

2 files changed

+44
-20
lines changed

pkg/ebpf/events_pipeline.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,14 @@ func (t *Tracee) decodeEvents(ctx context.Context, sourceChan chan []byte) (<-ch
222222
syscall = events.Core.GetDefinitionByID(id).GetName()
223223
} else {
224224
// This should never fail, as the translation used in eBPF relies on the same event definitions
225-
logger.Errorw(fmt.Sprintf("No syscall event with id %d", id))
225+
commStr := string(eCtx.Comm[:bytes.IndexByte(eCtx.Comm[:], 0)])
226+
utsNameStr := string(eCtx.UtsName[:bytes.IndexByte(eCtx.UtsName[:], 0)])
227+
logger.Errorw(
228+
fmt.Sprintf("Event %s with an invalid syscall id %d", evtName, id),
229+
"Comm", commStr,
230+
"UtsName", utsNameStr,
231+
"EventContext", eCtx,
232+
)
226233
}
227234
}
228235

tests/e2e-inst-test.sh

+36-19
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ if [[ ! -x ./dist/tracee ]]; then
7979
error_exit "could not find tracee executable"
8080
fi
8181

82+
logfile=$SCRIPT_TMP_DIR/tracee-log-$$
83+
outputfile=$SCRIPT_TMP_DIR/output-$$
84+
8285
anyerror=""
8386

8487
# Run tests, one by one
@@ -138,18 +141,18 @@ for TEST in $TESTS; do
138141

139142
# Run tracee
140143

141-
rm -f $SCRIPT_TMP_DIR/build-$$
142-
rm -f $SCRIPT_TMP_DIR/tracee-log-$$
144+
rm -f $outputfile
145+
rm -f $logfile
143146

144147
tracee_command="./dist/tracee \
145148
--install-path $TRACEE_TMP_DIR \
146149
--cache cache-type=mem \
147150
--cache mem-cache-size=512 \
148151
--proctree source=both \
149152
--output option:sort-events \
150-
--output json:$SCRIPT_TMP_DIR/build-$$ \
151153
--output option:parse-arguments \
152-
--log file:$SCRIPT_TMP_DIR/tracee-log-$$ \
154+
--output json:$outputfile \
155+
--log file:$logfile \
153156
--signatures-dir "$SIG_DIR" \
154157
--dnscache enable \
155158
--grpc-listen-addr unix:/tmp/tracee.sock \
@@ -201,7 +204,7 @@ for TEST in $TESTS; do
201204
info
202205
info "$TEST: FAILED. ERRORS:"
203206
info
204-
cat $SCRIPT_TMP_DIR/tracee-log-$$
207+
cat $logfile
205208

206209
anyerror="${anyerror}$TEST,"
207210
continue
@@ -232,12 +235,18 @@ for TEST in $TESTS; do
232235

233236
# The cleanup happens at EXIT
234237

235-
logfile=$SCRIPT_TMP_DIR/tracee-log-$$
238+
# Make sure we exit tracee before checking output and log files
239+
240+
pid_tracee=$(pidof tracee | cut -d' ' -f1)
241+
kill -SIGINT "$pid_tracee"
242+
sleep $TRACEE_SHUTDOWN_TIMEOUT
243+
kill -SIGKILL "$pid_tracee" >/dev/null 2>&1
244+
sleep 3
236245

237246
# Check if the test has failed or not
238247

239248
found=0
240-
cat $SCRIPT_TMP_DIR/build-$$ | jq .eventName | grep -q "$TEST" && found=1
249+
cat $outputfile | jq .eventName | grep -q "$TEST" && found=1
241250
errors=$(cat $logfile | wc -l 2>/dev/null)
242251

243252
if [[ $TEST == "BPF_ATTACH" ]]; then
@@ -249,25 +258,33 @@ for TEST in $TESTS; do
249258
info "$TEST: SUCCESS"
250259
else
251260
anyerror="${anyerror}$TEST,"
261+
252262
info "$TEST: FAILED, stderr from tracee:"
253-
cat $SCRIPT_TMP_DIR/tracee-log-$$
263+
cat $logfile
264+
254265
info "$TEST: FAILED, events from tracee:"
255-
cat $SCRIPT_TMP_DIR/build-$$
266+
cat $outputfile
267+
268+
info "Tracee command:"
269+
echo "$tracee_command" | tr -s ' '
270+
271+
info "Tracee process is running?"
272+
traceepids=$(pgrep tracee)
273+
if [[ -n $traceepids ]]; then
274+
info "YES, Tracee is still running (should not be, fix me!), pids: $traceepids"
275+
info "Aborting tests"
276+
break
277+
else
278+
info "NO, Tracee is not running"
279+
fi
256280
info
257281
fi
258282
info
259283

260-
rm -f $SCRIPT_TMP_DIR/build-$$
261-
rm -f $SCRIPT_TMP_DIR/tracee-log-$$
262-
263-
# Make sure we exit tracee to start it again
264-
265-
pid_tracee=$(pidof tracee | cut -d' ' -f1)
266-
kill -SIGINT "$pid_tracee"
267-
sleep $TRACEE_SHUTDOWN_TIMEOUT
268-
kill -SIGKILL "$pid_tracee" >/dev/null 2>&1
269-
sleep 3
284+
# Cleanup
270285

286+
rm -f $outputfile
287+
rm -f $logfile
271288
# Cleanup leftovers
272289
rm -rf $TRACEE_TMP_DIR
273290
done

0 commit comments

Comments
 (0)