From 5699010417f7e13274bf7e5b5dd3aab8e000e0e6 Mon Sep 17 00:00:00 2001 From: Daniel Dao Date: Mon, 31 Jan 2022 11:39:38 +0000 Subject: [PATCH] integration test for PSI metrics in runc events Signed-off-by: Daniel Dao --- tests/integration/events.bats | 25 +++++++++++++++++++++++++ tests/integration/helpers.bash | 7 +++++++ 2 files changed, 32 insertions(+) diff --git a/tests/integration/events.bats b/tests/integration/events.bats index 9d28420e5b2..e62e068be73 100644 --- a/tests/integration/events.bats +++ b/tests/integration/events.bats @@ -26,6 +26,31 @@ function teardown() { [[ "${lines[0]}" == *"data"* ]] } +@test "events --stats with psi data" { + requires root cgroups_v2 psi + init_cgroup_paths + + update_config '.linux.resources.cpu |= { "quota": 1000 }' + + runc run -d --console-socket "$CONSOLE_SOCKET" test_busybox + [ "$status" -eq 0 ] + + # stress the cpu a little bit + runc exec test_busybox dd if=/dev/zero bs=1M count=5 of=/dev/null + [ "$status" -eq 0 ] + + runc events --stats test_busybox + [ "$status" -eq 0 ] + # fetch stats to see PSI metrics + for psi_type in some full; do + for psi_metric in avg10 avg60 avg300 total; do + [[ "$(echo "${lines[0]}" | jq .data.cpu.psi.$psi_type.$psi_metric)" != "" ]] + done + done + # total must have been more than 0 + [[ "$(echo "${lines[0]}" | jq .data.cpu.psi.some.total)" != "0" ]] +} + function test_events() { # XXX: currently cgroups require root containers. requires root diff --git a/tests/integration/helpers.bash b/tests/integration/helpers.bash index aaa68dd7c33..95573b83d18 100644 --- a/tests/integration/helpers.bash +++ b/tests/integration/helpers.bash @@ -448,6 +448,13 @@ function requires() { skip_me=1 fi ;; + psi) + # If PSI is not compiled in the kernel, the file will not exist. + # If PIS is compiled, but not enable, read will fail with ENOSUPP + if [[ ! $(cat /sys/fs/cgroup/cpu.pressure) ]]; then + skip_me=1 + fi + ;; *) fail "BUG: Invalid requires $var." ;;