Skip to content

Commit

Permalink
test: Add e2e test for jobstats package
Browse files Browse the repository at this point in the history
* Add supporting fixtures

Signed-off-by: mahendrapaipuri <[email protected]>
  • Loading branch information
mahendrapaipuri committed Nov 28, 2023
1 parent 136bbe8 commit f27a5d4
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 6 deletions.
37 changes: 37 additions & 0 deletions pkg/jobstats/fixtures/jobstats.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE jobs (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"Jobid" TEXT,
"Jobuuid" TEXT,
"Cluster" TEXT,
"Partition" TEXT,
"Account" TEXT,
"Grp" TEXT,
"Gid" TEXT,
"Usr" TEXT,
"Uid" TEXT,
"Submit" TEXT,
"Eligible" TEXT,
"Start" TEXT,
"End" TEXT,
"Elapsed" TEXT,
"Elapsedraw" TEXT,
"Exitcode" TEXT,
"State" TEXT,
"Nnodes" TEXT,
"Ncpus" TEXT,
"Reqcpus" TEXT,
"Reqmem" TEXT,
"Reqtres" TEXT,
"Timelimit" TEXT,
"Nodelist" TEXT,
"NodelistExp" TEXT,
"Jobname" TEXT,
"Workdir" TEXT
);
INSERT INTO jobs VALUES(1,'1479763','d4b98df4-e636-ea14-59ff-37db752e6c30','test','part1','acc1','grp','1000','usr','1000','2023-02-21T14:37:02','2023-02-21T14:37:02','2023-02-21T14:37:07','2023-02-21T15:26:29','00:49:22','2962','0:0','CANCELLED by 302137','1','2','1','4G','cpu=1,mem=4G,node=1','01:00:00','compute-0','compute-0','test_script2','/home/usr');
INSERT INTO jobs VALUES(2,'1481508','44cbb62d-db8f-c0c5-e123-76766afbd190','test','part1','acc1','grp','1000','usr','1000','2023-02-21T15:48:20','2023-02-21T15:48:20','2023-02-21T15:49:06','2023-02-21T15:57:23','00:08:17','497','0:0','CANCELLED by 302137','2','40','40','80G','cpu=40,mem=80G,node=2','01:00:00','compute-[0-2]','compute-0|compute-1|compute-2','test_script2','/home/usr');
DELETE FROM sqlite_sequence;
INSERT INTO sqlite_sequence VALUES('jobs',2);
COMMIT;
6 changes: 6 additions & 0 deletions pkg/jobstats/fixtures/sacct
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo """JobID|Cluster|Partition|Account|Group|GID|User|UID|Submit|Eligible|Start|End|Elapsed|ElapsedRaw|ExitCode|State|NNodes|NCPUS|ReqCPUS|ReqMem|ReqTRES|Timelimit|NodeList|JobName|WorkDir
1479763|test|part1|acc1|grp|1000|usr|1000|2023-02-21T14:37:02|2023-02-21T14:37:02|2023-02-21T14:37:07|2023-02-21T15:26:29|00:49:22|2962|0:0|CANCELLED by 302137|1|2|1|4G|cpu=1,mem=4G,node=1|01:00:00|compute-0|test_script2|/home/usr
1481508|test|part1|acc1|grp|1000|usr|1000|2023-02-21T15:48:20|2023-02-21T15:48:20|2023-02-21T15:49:06|2023-02-21T15:57:23|00:08:17|497|0:0|CANCELLED by 302137|2|40|40|80G|cpu=40,mem=80G,node=2|01:00:00|compute-[0-2]|test_script2|/home/usr
"""
39 changes: 33 additions & 6 deletions scripts/e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ cgroups_mode=$([ $(stat -fc %T /sys/fs/cgroup/) = "cgroup2fs" ] && echo "unified
echo "cgroups mode detected is ${cgroups_mode}"

case "${cgroups_mode}" in
legacy|hybrid) fixture='pkg/collector/fixtures/e2e-test-cgroupsv1-output.txt' ;;
*) fixture='pkg/collector/fixtures/e2e-test-cgroupsv2-output.txt' ;;
legacy|hybrid) exporter_fixture='pkg/collector/fixtures/e2e-test-cgroupsv1-output.txt' ;;
*) exporter_fixture='pkg/collector/fixtures/e2e-test-cgroupsv2-output.txt' ;;
esac

jobstats_fixture='pkg/jobstats/fixtures/jobstats.dump'

keep=0; update=0; verbose=0
while getopts 'hkuv' opt
do
Expand All @@ -37,7 +39,7 @@ do
*)
echo "Usage: $0 [-k] [-u] [-v]"
echo " -k: keep temporary files and leave batchjob_exporter running"
echo " -u: update fixture"
echo " -u: update fixtures"
echo " -v: verbose output"
exit 1
;;
Expand Down Expand Up @@ -69,13 +71,15 @@ finish() {
cat << EOF >&2
LOG =====================
$(cat "${tmpdir}/batchjob_exporter.log")
$(cat "${tmpdir}/batchjob_stats.log")
=========================
EOF
fi

if [ ${update} -ne 0 ]
then
cp "${tmpdir}/e2e-test-output.txt" "${fixture}"
cp "${tmpdir}/e2e-test-output.txt" "${exporter_fixture}"
cp "${tmpdir}/output.dump" "${jobstats_fixture}"
fi

if [ ${keep} -eq 0 ]
Expand Down Expand Up @@ -108,5 +112,28 @@ sleep 1
get "127.0.0.1:${port}/metrics" | grep -E -v "${skip_re}" > "${tmpdir}/e2e-test-output.txt"

diff -u \
"${fixture}" \
"${tmpdir}/e2e-test-output.txt"
"${exporter_fixture}" \
"${tmpdir}/e2e-test-output.txt"

if [ ! -x ./bin/batchjob_stats ]
then
echo './bin/batchjob_stats not found. Consider running `go build` first.' >&2
exit 1
fi

./bin/batchjob_stats \
--slurm.sacct.path="pkg/jobstats/fixtures/sacct" \
--path.data="${tmpdir}" \
--log.level="debug" > "${tmpdir}/batchjob_stats.log" 2>&1

if ! command -v sqlite3 &> /dev/null
then
echo "sqlite3 could not be found. Skipping batchjob_stats test..."
exit 0
fi

sqlite3 "${tmpdir}/jobstats.db" .dump >"${tmpdir}/output.dump"

diff -u \
"${jobstats_fixture}" \
"${tmpdir}/output.dump"

0 comments on commit f27a5d4

Please sign in to comment.