Skip to content

Commit

Permalink
tetragon: Add overhead metrics test for tracepoint
Browse files Browse the repository at this point in the history
Adding test for overhead metrics on top of tracepoint tracing policy.

Signed-off-by: Jiri Olsa <[email protected]>
  • Loading branch information
olsajiri committed Oct 7, 2024
1 parent f3f4526 commit f885780
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions pkg/sensors/tracing/tracepoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,3 +869,64 @@ spec:

testListSyscallsDupsRange(t, checker, configHook)
}

func TestTracepointOverheadStats(t *testing.T) {
var doneWG, readyWG sync.WaitGroup
defer doneWG.Wait()

ctx, cancel := context.WithTimeout(context.Background(), tus.Conf().CmdWaitTime)
defer cancel()

testNop := testutils.RepoRootPath("contrib/tester-progs/nop")

// enable bpf stats
stats, err := ebpf.EnableStats(uint32(unix.BPF_STATS_RUN_TIME))
if err != nil {
t.Fatalf("Failed to enable overhead stats: %s", err)
}
defer stats.Close()

tracingPolicy := `
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
name: "overhead"
spec:
tracepoints:
- subsystem: "raw_syscalls"
event: "sys_enter"
args:
- index: 4
type: "syscall64"
- index: 5
type: "uint64"
selectors:
- matchBinaries:
- operator: "In"
values:
- "` + testNop + `"
`
createCrdFile(t, tracingPolicy)

obs, err := observertesthelper.GetDefaultObserverWithFile(t, ctx, testConfigFile, tus.Conf().TetragonLib)
if err != nil {
t.Fatalf("GetDefaultObserverWithFile error: %s", err)
}
observertesthelper.LoopEvents(ctx, t, &doneWG, &readyWG, obs)
readyWG.Wait()

if err := exec.Command(testNop).Run(); err != nil {
fmt.Printf("Failed to execute test binary: %s\n", err)
}

res := []*metricResult{
{label: "attach=\"raw_syscalls/sys_enter\",policy=\"overhead\"", value: 1},
{label: "attach=\"acct_process\",policy=\"__base__\"", value: 1},
{label: "attach=\"sched/sched_process_exec\",policy=\"__base__\"", value: 1},
{label: "attach=\"security_bprm_committing_creds\",policy=\"__base__\"", value: 1},
{label: "attach=\"wake_up_new_task\",policy=\"__base__\"", value: 1},
}

checkMetric(t, "http://localhost:2112", "tetragon_overhead_cnt_program_total", res)
checkMetric(t, "http://localhost:2112", "tetragon_overhead_time_program_total", res)
}

0 comments on commit f885780

Please sign in to comment.