Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 136 additions & 2 deletions .github/workflows/plugin-ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ on:
- main
pull_request:
workflow_dispatch:
# Weekly, for the Slurm release that is built from source (slurm-live).
schedule:
- cron: '17 5 * * 1'

permissions:
contents: read
Expand Down Expand Up @@ -66,8 +69,8 @@ jobs:
for f in *.php include/*.php locales/*.php scripts/*.php tests/bin/*.php; do
php -l "$f"
done
# The Slurm client stand-ins the tests run are POSIX sh.
sh -n tests/fixtures/bin/squeue tests/fixtures/bin/prlimit
# The Slurm client stand-ins and the live cluster scripts are POSIX sh.
sh -n tests/fixtures/bin/squeue tests/fixtures/bin/prlimit tests/slurm-live/*.sh tests/slurm-live/bin/squeue
dash -n tests/fixtures/bin/squeue
dash -n tests/fixtures/bin/prlimit

Expand Down Expand Up @@ -414,6 +417,136 @@ jobs:
exit 1
fi

# A real Slurm cluster (MariaDB, slurmdbd, slurmctld, slurmrestd, six
# dynamic CPU nodes) from giovtorres/slurm-docker-cluster. states.sh
# creates the node states, a maintenance reservation, and the jobs the
# plugin must classify; fetch.sh captures the commands and REST paths the
# plugin reads, for every data parser the release serves; assert.sh checks
# the raw JSON and check.php the plugin's parser on it. The recorded
# captures in tests/fixtures/slurm/live come from these steps.
#
# 26.05.5 uses the published image, pinned by digest, and runs on every
# change. 25.11.8 has no published image (the registry stops at 25.11.4);
# its build takes about eight minutes before the cluster starts, so it
# runs on pushes to main, weekly, and on request, not on pull requests.
slurm-live:
name: Slurm ${{ matrix.slurm }} live cluster
runs-on: ubuntu-latest
timeout-minutes: 45

strategy:
fail-fast: false
matrix:
slurm: ${{ fromJSON(github.event_name == 'pull_request' && '["26.05.5"]' || '["26.05.5", "25.11.8"]') }}

env:
COMPOSE_PROJECT_NAME: slurmci
SLURM_VERSION: ${{ matrix.slurm }}
SLURM_IMAGE: ${{ matrix.slurm == '26.05.5' && 'giovtorres/slurm-docker-cluster@sha256:947fca3c27d78abcdf97f21639e3483a2d6c0569ec812cb514e9cdf2526e0d90' || '' }}

steps:
- name: Checkout hpcsched plugin
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
path: plugin

# Release 3.0.2, pinned by commit.
- name: Checkout slurm-docker-cluster
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
repository: giovtorres/slurm-docker-cluster
ref: 9001503b42e7277c7ff45c08aeecdb6427474d68
path: slurm-cluster

- name: Install PHP 8.2
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.2'
coverage: none

- name: Get the Slurm image
working-directory: slurm-cluster
run: |
set -euo pipefail
if [ -n "$SLURM_IMAGE" ]; then
docker pull "$SLURM_IMAGE"
docker tag "$SLURM_IMAGE" "slurm-docker-cluster:$SLURM_VERSION"
else
docker build \
--build-arg "SLURM_VERSION=$SLURM_VERSION" \
--build-arg GPU_ENABLE=false --build-arg IS_WSL=false \
-t "slurm-docker-cluster:$SLURM_VERSION" .
fi
# The compose file names MariaDB by tag only; pin its digest.
cat > "$RUNNER_TEMP/compose.pin.yml" <<'PIN'
services:
mysql:
image: mariadb:12@sha256:4ebbcf100a3ba320766dfa0e1af008df12261301db6ef72798c7650f70794aed
PIN

# Workers go up one at a time: the image's entrypoint takes a node name
# from the DNS entries of lower-numbered replicas and exits when they do
# not resolve yet, so starting six at once leaves only some running.
- name: Start the cluster with six nodes
working-directory: slurm-cluster
run: |
set -euo pipefail
c="docker compose -f docker-compose.yml -f $RUNNER_TEMP/compose.pin.yml"
CPU_WORKER_COUNT=1 $c up -d --no-build mysql slurmdbd slurmctld slurmrestd cpu-worker
for n in 2 3 4 5 6; do
CPU_WORKER_COUNT=$n $c up -d --no-build --no-recreate --scale cpu-worker=$n cpu-worker
sleep 6
done
$c ps

- name: Create node states, a reservation, and jobs
run: |
set -euo pipefail
docker cp plugin/tests/slurm-live/states.sh slurmctld:/tmp/states.sh
docker exec slurmctld sh /tmp/states.sh

# The token never reaches a command line or the log: it goes from
# scontrol into a token file for the plugin and a curl header file, both
# readable only by this user.
- name: Mint a slurmrestd token
run: |
set -euo pipefail
umask 077
mkdir -p "$RUNNER_TEMP/hpcsched-tokens"
docker exec slurmctld scontrol token lifespan=900 > "$RUNNER_TEMP/hpcsched-tokens/live.token"
tok=$(sed -n 's/^SLURM_JWT=//p' "$RUNNER_TEMP/hpcsched-tokens/live.token")
echo "::add-mask::$tok"
printf 'X-SLURM-USER-TOKEN: %s\n' "$tok" > "$RUNNER_TEMP/jwt-header"
for _ in $(seq 1 30); do
curl -fsS -o /dev/null -H "@$RUNNER_TEMP/jwt-header" -H 'X-SLURM-USER-NAME: root' http://127.0.0.1:6820/openapi/v3 && exit 0
sleep 2
done
echo "slurmrestd did not answer" >&2
exit 1

- name: Capture command and REST output
run: sh plugin/tests/slurm-live/fetch.sh "$RUNNER_TEMP/slurm-out" "$RUNNER_TEMP/jwt-header"

- name: Assert node states, partitions, and pending reasons in the raw JSON
run: sh plugin/tests/slurm-live/assert.sh "$RUNNER_TEMP/slurm-out"

- name: Assert through the plugin's parser
run: php plugin/tests/slurm-live/check.php "$GITHUB_WORKSPACE/plugin" "$RUNNER_TEMP/slurm-out"

# The plugin's own transports, built from a cluster record as the reader
# builds them: the client commands through docker exec into slurmctld,
# and slurmrestd on loopback with the token file.
- name: Collect a snapshot with the plugin's transports
run: php plugin/tests/slurm-live/collect.php "$GITHUB_WORKSPACE/plugin" "$RUNNER_TEMP/slurm-out" "$RUNNER_TEMP/hpcsched-tokens/live.token"

- name: Tear the cluster down
if: always()
working-directory: slurm-cluster
run: |
docker compose -f docker-compose.yml -f "$RUNNER_TEMP/compose.pin.yml" down -v || true

workflow-lint:
name: Workflow lint
runs-on: ubuntu-latest
Expand Down Expand Up @@ -449,6 +582,7 @@ jobs:
- entry-point-lint
- integration-test
- php-guard
- slurm-live
- workflow-lint
- reuse
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ The next collection reads the new file. Generating tokens with `scontrol token`

**Alerting.** Thold can alert on any of these data sources; set Thold durations to at least one collection interval, and alert on `age` to catch a stopped reader. The end-to-end Thold check is milestone 4.

**Tested against real Slurm output.** CI starts a six-node Slurm cluster in containers (26.05.5 on every change, 25.11.8 built from source on pushes to `main`, weekly, and on request) and checks node states, the maintenance reservation, pending reasons, and arrays as the plugin parses them, then collects from that cluster with the plugin's own command and `slurmrestd` transports. Older releases are covered only by synthetic fixtures. The reader has still not run against a production cluster.

**Permissions.** A cluster on a device is shown, exported, and changed only for users Cacti allows that device, on every plugin page; mapping a device also needs permission for the target device. A cluster without a device is visible to everyone with the plugin realm. A cluster still mapped to a device that was deleted while the plugin was disabled is shown only to users with the HPC Scheduler Admin realm, who can create or map a device for it. Graph access is Cacti's own.

## Why
Expand Down
2 changes: 1 addition & 1 deletion docs/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ Phase 2 needs a security review covering mapping input, writes to Maint's tables
## Testing

- **Fixtures.** Captured command and REST output per Slurm release for: idle, busy, and drained clusters; held, array, and multi-partition jobs; every documented reason and an unknown one; every documented node state and an unknown one; reservations including `MAINT` and recurring; nodes in several partitions; shares with and without Fair Tree.
- **Matrix.** Containers for each supported Slurm release (`slurmctld`, and `slurmrestd` where provided) against Cacti 1.2.31 and current `1.2.x`, on every PHP minor in the CI matrix. `setup.php` and shims are also linted under PHP 8.0.
- **Matrix.** Containers for each supported Slurm release (`slurmctld`, and `slurmrestd` where provided) against Cacti 1.2.31 and current `1.2.x`, on every PHP minor in the CI matrix. `setup.php` and shims are also linted under PHP 8.0. **Milestone 3 diverges:** the CI job `slurm-live` runs a real cluster from slurm-docker-cluster 3.0.2 (pinned by commit, MariaDB pinned by digest) with six nodes, creates allocated, mixed, drained, down, down and drained, and maintenance nodes, a maintenance reservation, and held, array, and pending jobs, then checks the raw JSON and the plugin's parser for every data parser the release serves, through both client commands and `slurmrestd`. 26.05.5 uses the published image, pinned by digest, on every change; 25.11.8 has no published image and is built from source, which takes about eight minutes, so it runs on pushes to `main`, weekly, and on request. 25.05 has no matching cluster configuration and stays on the synthetic fixtures. It then collects a snapshot with the plugin's own transports, built from a cluster record as the reader builds them: the client commands through `docker exec` into the `slurmctld` container (so `prlimit` is off there, since it would limit `docker` rather than the client), and `slurmrestd` on loopback with a token file. Each snapshot must complete every section and match the captured parse. The reader's database write is not part of the job; the Cacti replays cover it with stand-ins. Captures from it are in `tests/fixtures/slurm/live` and run in the unit suite.
- **Transport safety.** Hung command, output flood, malformed JSON, 304, 401, 403, 500, slow response, oversized response, and node names with shell metacharacters.
- **Counting.** Fixtures for each counting rule in the Graphs section, checked with `rrdtool xport` against expected values.
- **Permissions.** Every page, graph, and data source as an administrator, a scoped user, a user whose access was just revoked, and a user with no access.
Expand Down
14 changes: 14 additions & 0 deletions docs/research/slurm-client-output.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ No output was captured. Payload size and run time of JSON versus format output a
| #16 | Set a node reason containing `\|`, a newline, and a quote; capture `sinfo -N -o` and JSON | whether `%E` is safe in delimited output |
| #16 | Create a partition named with each character Slurm allows | whether partition names can contain the delimiter |
| #16 | Run a newer client against an older daemon and the reverse, with an explicit parser | what a mismatched pairing prints |

### Results from the milestone 3 live cluster

Run 2026-11-15 on slurm-docker-cluster 3.0.2 (26.05.5 from the published image, 25.11.8 built from source), six dynamic nodes, on arm64; the same steps are the `slurm-live` CI job, and the captures are in `tests/fixtures/slurm/live`. Not covered: a job in two partitions, a 100 task array, the size and time comparison at scale, partition name characters, and mismatched client and daemon releases.

| Observation | Releases | Consequence |
|---|---|---|
| `sinfo -o %T` prints `drained` for a node that is DOWN and DRAIN; the JSON `state` array keeps both | 26.05.5, 25.11.8 | node state comes from JSON, which the plugin already does |
| A node reason containing `\|` adds a field to `sinfo -o '%N\|%T\|%E\|%P'` output | both | reasons come from JSON |
| squeue JSON gives a pending array as one record with `array_task_string` (`1-12`, `1-6%2`); `squeue -r` prints one line per task | both | the task count rule in ADR 0011 holds |
| slurmrestd's jobs endpoint also lists COMPLETED, FAILED, and CANCELLED jobs that slurmctld still keeps; `squeue --json` lists only unfinished ones | both | the parser drops finished jobs, so both transports count the same jobs |
| `DYNAMIC_NORM` is set on every dynamic node | both | ignored when classifying state |
| A maintenance reservation is active at once, but on 25.11.8 the node gained `RESERVED` and `MAINTENANCE` only after several minutes (26.05.5 had them at capture time) | 25.11.8 | the live check waits for the flags with a bound and otherwise accepts the active MAINT reservation; the 25.11 capture shows the node still idle |
| Data parsers served: v0.0.42 to v0.0.45 on 26.05.5; v0.0.42 to v0.0.44 over REST on 25.11.8, whose client also lists v0.0.41 | both | the default v0.0.43 works on both; v0.0.45 is 26.05 only, as the health page warns |
17 changes: 17 additions & 0 deletions lib/JobState.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,23 @@
case Completing = 'completing';
case Other = 'other';

/**
* Base states of a job that has ended. squeue leaves these out by
* default, but slurmrestd's jobs endpoint still lists such jobs while
* slurmctld keeps them (MinJobAge), so both transports drop them to
* count the same jobs. A job still completing is not finished.
*/
private const FINISHED = ['BOOT_FAIL', 'CANCELLED', 'COMPLETED', 'DEADLINE', 'FAILED', 'NODE_FAIL', 'OUT_OF_MEMORY', 'PREEMPTED', 'TIMEOUT'];

Check warning on line 40 in lib/JobState.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Split this 142 characters long line (which is greater than 120 authorized).

See more on https://sonarcloud.io/project/issues?id=somethingwithproof_plugin_hpcsched&issues=AaHhMFPEB_udLTV_KSZu&open=AaHhMFPEB_udLTV_KSZu&pullRequest=74

/**
* @param list<string> $state the JSON job_state array (base state and flags)
*/
public static function finished(array $state): bool {

Check warning on line 45 in lib/JobState.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this open curly brace to the beginning of the next line.

See more on https://sonarcloud.io/project/issues?id=somethingwithproof_plugin_hpcsched&issues=AaHhMFPEB_udLTV_KSZv&open=AaHhMFPEB_udLTV_KSZv&pullRequest=74
$set = array_map(static fn (string $s): string => strtoupper(trim($s)), $state);

return !in_array('COMPLETING', $set, true) && array_intersect($set, self::FINISHED) !== [];
}

/**
* @param list<string> $state the JSON job_state array (base state and flags)
*/
Expand Down
4 changes: 4 additions & 0 deletions lib/SlurmParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public static function jobs(array $doc): JobTally {
throw new TransportError(ErrorClass::Malformed, 'job without a state');
}

if (JobState::finished($states)) {
continue;
}

$reason = SlurmJson::string($job, 'state_reason');
$state = JobState::of($states, $reason);
$tasks = SlurmJson::string($job, 'array_task_string');
Expand Down
Loading
Loading