diff --git a/tests/metrics/density/README.md b/tests/metrics/density/README.md index e07ee18b39..d553740156 100644 --- a/tests/metrics/density/README.md +++ b/tests/metrics/density/README.md @@ -51,3 +51,8 @@ For more details see the [footprint test documentation](footprint_data.md). Measures the memory statistics *inside* the container. This allows evaluation of the overhead the VM kernel and rootfs are having on the memory that was requested by the container co-ordination system, and thus supplied to the VM. + +## `k8s-sysbench` + +`Sysbench`is an open-source and multi-purpose benchmark utility that evaluates parameters features tests for `CPU`, memory +and I/O. Currently the `k8s-sysbench` test is measuring the `CPU` performance. diff --git a/tests/metrics/density/k8s-sysbench.sh b/tests/metrics/density/k8s-sysbench.sh new file mode 100755 index 0000000000..288e69957a --- /dev/null +++ b/tests/metrics/density/k8s-sysbench.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# +# Copyright (c) 2022-2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +set -o errexit +set -o nounset +set -o pipefail + +SCRIPT_PATH=$(dirname "$(readlink -f "$0")") +source "${SCRIPT_PATH}/../lib/common.bash" +sysbench_file=$(mktemp sysbenchresults.XXXXXXXXXX) +TEST_NAME="${TEST_NAME:-sysbench}" +CI_JOB="${CI_JOB:-}" +IMAGE="docker.io/library/local-sysbench:latest" +DOCKERFILE="${SCRIPT_PATH}/sysbench-dockerfile/Dockerfile" + +function remove_tmp_file() { + rm -rf "${sysbench_file}" +} + +trap remove_tmp_file EXIT + +function sysbench_memory() { + kubectl exec -i "$pod_name" -- sh -c "sysbench memory --threads=2 run" > "${sysbench_file}" + metrics_json_init + local memory_latency_sum=$(cat "$sysbench_file" | grep sum | cut -f2 -d':' | sed 's/[[:blank:]]//g') + metrics_json_start_array + local json="$(cat << EOF + { + "memory-latency-sum": { + "Result" : $memory_latency_sum, + "Units" : "ms" + } + } +EOF +)" + metrics_json_add_array_element "$json" + metrics_json_end_array "Results" + metrics_json_save +} + +function sysbench_start_deployment() { + cmds=("bc" "jq") + check_cmds "${cmds[@]}" + + # Check no processes are left behind + check_processes + + export pod_name="test-sysbench" + + kubectl create -f "${SCRIPT_PATH}/runtimeclass_workloads/sysbench-pod.yaml" + kubectl wait --for=condition=Ready --timeout=120s pod "$pod_name" +} + +function sysbench_cleanup() { + kubectl delete pod "$pod_name" + check_processes +} + +function main() { + init_env + sysbench_start_deployment + sysbench_memory + sysbench_cleanup +} + +main "$@" diff --git a/tests/metrics/density/runtimeclass_workloads/sysbench-pod.yaml b/tests/metrics/density/runtimeclass_workloads/sysbench-pod.yaml new file mode 100644 index 0000000000..03dc850f46 --- /dev/null +++ b/tests/metrics/density/runtimeclass_workloads/sysbench-pod.yaml @@ -0,0 +1,18 @@ +# +# Copyright (c) 2018-2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 +# +apiVersion: v1 +kind: Pod +metadata: + name: test-sysbench +spec: + terminationGracePeriodSeconds: 0 + runtimeClassName: kata + containers: + - name: test-sysbench + image: localhost:5000/sysbench-kata:latest + command: + - sleep + - "60" diff --git a/tests/metrics/density/sysbench-dockerfile/Dockerfile b/tests/metrics/density/sysbench-dockerfile/Dockerfile new file mode 100644 index 0000000000..f6d1ba398b --- /dev/null +++ b/tests/metrics/density/sysbench-dockerfile/Dockerfile @@ -0,0 +1,17 @@ +# Copyright (c) 2022-2023 Intel Corporation +# +# SPDX-License-Identifier: Apache-2.0 + +# Usage: FROM [image name] +FROM ubuntu:20.04 + +# Version of the Dockerfile +LABEL DOCKERFILE_VERSION="1.0" + +RUN apt-get update && \ + apt-get install -y build-essential git curl sudo && \ + apt-get remove -y unattended-upgrades && \ + curl -OkL https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh && \ + apt-get install -y sysbench + +CMD ["/bin/bash"]