diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c0ceec4..94b9695 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,18 +13,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false - - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 - with: - python-version: "3.14" - - name: Install promtool 3.7.3 - run: | - curl -fsSLO https://github.com/prometheus/prometheus/releases/download/v3.7.3/prometheus-3.7.3.linux-amd64.tar.gz - echo 'fc9e5da126817438cf2820d9a7206c75e3122802ba8d20add3a6219a59ca6913 prometheus-3.7.3.linux-amd64.tar.gz' | sha256sum -c - - tar -xzf prometheus-3.7.3.linux-amd64.tar.gz - sudo install -m 0755 prometheus-3.7.3.linux-amd64/promtool /usr/local/bin/promtool - - run: shellcheck -S warning eb-keep-logs tests/test_eb_keep_logs.sh tests/test_metrics.sh tests/corpus/run.sh tests/corpus/make-fixtures.sh - - run: bash tests/test_eb_keep_logs.sh - - run: bash tests/test_metrics.sh + - run: shellcheck -S warning tests/test_eb_keep_logs.sh tests/test_metrics.sh tests/test_output_stability.sh tests/test_tutorial_which.sh tests/corpus/run.sh tests/corpus/make-fixtures.sh - name: no site names in the tree run: | ! git grep -nIiE 'snellius|snel-|surf\.nl|/gpfs/|/projects/0|rg\.terra|scratch-shared|scratch-node' -- . ':!.github/workflows/ci.yml' @@ -60,7 +49,7 @@ jobs: tar -xzf "${archive}" sudo install -m 0755 "prometheus-3.7.3.linux-${arch}/promtool" /usr/local/bin/promtool - run: zig fmt --check build.zig build.zig.zon src - - run: shellcheck -S warning tests/differential.sh tests/test_metrics.sh tests/test_why.sh tests/test_json_schemas.sh tests/test_crash_safety.sh tests/test_rotate_fsync_durability.sh tests/lib/check.sh tests/test_report_utf8_safety.sh tests/test_lifecycle_modulerc_safety.sh + - run: shellcheck -S warning tests/test_cases.sh tests/test_metrics.sh tests/test_why.sh tests/test_json_schemas.sh tests/test_crash_safety.sh tests/test_rotate_fsync_durability.sh tests/lib/check.sh tests/test_report_utf8_safety.sh tests/test_lifecycle_modulerc_safety.sh - run: pip install jsonschema - uses: ./.github/actions/install-strace - run: zig build test --summary all diff --git a/.gitignore b/.gitignore index f574a91..3f057ce 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ zig-pkg/ /docs/**/__pycache__/ /.pixi/ /.lycheecache + +# Recorded stderr of the stability test; a global *.err ignore must not drop it. +!tests/golden/**/*.err diff --git a/COMPAT.md b/COMPAT.md index 7df713d..ecbbd94 100644 --- a/COMPAT.md +++ b/COMPAT.md @@ -1,9 +1,12 @@ # Compatibility of the Zig build with the shell script -The Zig build (0.2.0 and later) keeps the shell script's (0.1.0) interface. The shell -script stays in the repository as the reference: `tests/test_eb_keep_logs.sh` -runs against either through `TOOL_BIN`, and `tests/differential.sh` runs both -on the same invocations. +The Zig build (0.2.0 and later) keeps the interface of the shell script it +was ported from (0.1.0), which is no longer in the repository. This page is +for a site that ran the script: what the binary keeps, and where it differs. +`tests/test_cases.sh` compares the binary with the script's own output on +fixed invocations, recorded under `tests/golden/cases`, and +`tests/test_output_stability.sh` does the same for `failed` and `rotate` +byte for byte. ## Kept diff --git a/README.md b/README.md index 4288375..eb121b1 100644 --- a/README.md +++ b/README.md @@ -35,9 +35,7 @@ sha256sum --check --ignore-missing SHA256SUMS install -m 0755 "eb-keep-logs-$v-$arch-linux-musl" ~/.local/bin/eb-keep-logs ``` -The shell script `eb-keep-logs` in this repository is the reference for `failed` and `rotate`, with the same options and output; copy it onto `PATH`. -It refuses `why`, `history`, `failures`, `loads`, `runs`, `used`, `usage`, `pending`, `test-bundle`, `test-compare` and `lifecycle` with `is in the Zig build only` and exit 2: only the binary has them. -It needs `bash`, coreutils, GNU `grep` (for `grep -P`), `sed`, `find`, `gzip`, `awk`, `flock` from util-linux for `rotate` and, for `failed`, `eb`. +The binary is the one implementation. The shell script it was ported from, 0.1.0, is no longer in the repository; [COMPAT.md](https://github.com/stackhands/eb-keep-logs/blob/main/COMPAT.md) lists what the binary keeps of its interface and where it differs. Without `grep -P` it still keeps the log and the command output, but not the meson testlog. There is no EasyBuild recipe for eb-keep-logs here or in the EasyBuild easyconfigs repository. @@ -50,11 +48,9 @@ zig build -Drelease=true zig-out/bin/eb-keep-logs --version ``` -`zig build test` runs its unit tests, the shell test suite against the -binary, and `tests/differential.sh`, which runs the shell script and the -binary on the same invocations. -[COMPAT.md](https://github.com/stackhands/eb-keep-logs/blob/main/COMPAT.md) lists what the two share and where they differ on -purpose. +`zig build test` runs its unit tests, the shell test suites against the +binary, and `tests/test_cases.sh`, which compares the binary's output on +fixed invocations with the expected output under `tests/golden/cases`. ## Keep a failed build's logs diff --git a/RELEASING.md b/RELEASING.md index a44ef29..a0752f6 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -19,9 +19,7 @@ leaves to a person. 2. Edit, in a commit of its own, the prose the hook leaves alone: the README sentence on what `main` has that the latest release lacks, the "Release X.Y.Z runs ..." rows of `docs/orgmode/howto/install.org`, the - `--version` example of `docs/orgmode/reference/cli.org`, and a row in - `COMPAT.md` with its label in `tests/differential.sh` for each new - deliberate difference from the shell script. + `--version` example of `docs/orgmode/reference/cli.org`. 3. `cog bump --minor` (or `--patch`, `--major`, `--version X.Y.Z`). It runs the hook, commits `chore(version): X.Y.Z` and creates the tag on that commit. `cog bump --minor --dry-run` prints the version only. diff --git a/build.zig b/build.zig index 8997c4c..69bf096 100644 --- a/build.zig +++ b/build.zig @@ -63,8 +63,8 @@ pub fn build(b: *std.Build) void { crash_safety.has_side_effects = true; b.step("crash-safety", "Run the signal and crash safety suite").dependOn(&crash_safety.step); - // The shell suite of the old implementation, run against this binary. - // It and the differential run below run in the build root: their script + // The shell suite, run against this binary. + // It and the case run below run in the build root: their script // paths are relative, and zig build may be started in a subdirectory. // Both run every time, as the cache sees neither their scripts nor the // date and tzdata of the host, which the suite compares with. @@ -73,14 +73,15 @@ pub fn build(b: *std.Build) void { suite.setCwd(b.path(".")); suite.expectExitCode(0); suite.has_side_effects = true; - // The same invocations through the shell implementation and this one. - const diff = b.addSystemCommand(&.{ "bash", "-c", "TOOL_BIN=\"$0\" TEST_OPS_BIN=\"$1\" exec bash tests/differential.sh" }); + // Fixed invocations, against the expected output under tests/golden/cases. + // The killed-mid-compress case runs the test-ops binary. + const diff = b.addSystemCommand(&.{ "bash", "-c", "TOOL_BIN=\"$0\" TEST_OPS_BIN=\"$1\" exec bash tests/test_cases.sh" }); diff.addArtifactArg(exe); diff.addArtifactArg(test_ops_exe); diff.setCwd(b.path(".")); diff.expectExitCode(0); diff.has_side_effects = true; - // why, which the shell implementation does not have, on the kept logs + // why on the kept logs // of real EasyBuild failures. const why = b.addSystemCommand(&.{ "bash", "-c", "TOOL_BIN=\"$0\" exec bash tests/test_why.sh" }); why.addArtifactArg(exe); @@ -164,7 +165,7 @@ pub fn build(b: *std.Build) void { modulerc_safety_test.expectExitCode(0); modulerc_safety_test.has_side_effects = true; - const test_step = b.step("test", "Run the unit tests, the command-line suites and the differential run"); + const test_step = b.step("test", "Run the unit tests, the command-line suites and the expected-output cases"); test_step.dependOn(&b.addRunArtifact(unit).step); test_step.dependOn(&suite.step); test_step.dependOn(&diff.step); diff --git a/changelog.d/+retire-shell-script.removal.md b/changelog.d/+retire-shell-script.removal.md new file mode 100644 index 0000000..c549ef3 --- /dev/null +++ b/changelog.d/+retire-shell-script.removal.md @@ -0,0 +1 @@ +The shell script `eb-keep-logs` 0.1.0 is no longer in the repository; the binary is the one implementation. `tests/test_cases.sh` holds the binary to the script's recorded output on the invocations `tests/differential.sh` compared, and COMPAT.md stays as the record of what changed for a site that ran the script. diff --git a/docs/orgmode/contributing.org b/docs/orgmode/contributing.org index 0a6e48b..6b31661 100644 --- a/docs/orgmode/contributing.org +++ b/docs/orgmode/contributing.org @@ -31,9 +31,8 @@ With Zig 0.17.1, from the top of the repository: zig build test #+end_src -This runs the unit tests, the command-line suite =tests/test_eb_keep_logs.sh= against the binary, and =tests/differential.sh=, which runs the shell script and the binary on the same invocations. -=bash tests/test_eb_keep_logs.sh= runs the suite against the shell script. -A deliberate difference between the two has its row in =COMPAT.md=, which [[file:reference/compatibility.org][Compatibility]] shows, and its label in =tests/differential.sh=. +This runs the unit tests, the command-line suites such as =tests/test_eb_keep_logs.sh= against the binary, and =tests/test_cases.sh=, which compares the binary's output on fixed invocations with the files under =tests/golden/cases=. +A change that alters one of those outputs on purpose rewrites them with =RECORD=1 TOOL_BIN=zig-out/bin/eb-keep-logs bash tests/test_cases.sh=; the diff of =tests/golden= shows what changed. ** The log corpus diff --git a/docs/orgmode/howto/check-prefix-use.org b/docs/orgmode/howto/check-prefix-use.org index d4ae7a8..c9d26b1 100644 --- a/docs/orgmode/howto/check-prefix-use.org +++ b/docs/orgmode/howto/check-prefix-use.org @@ -10,7 +10,7 @@ Before uninstalling or retiring an install tree, see whether XALT or Lmod record ** Before starting -- The Zig build of =eb-keep-logs=. The shell script answers =used= with =used is in the Zig build only=. +- =eb-keep-logs= 0.2.0 or later. The shell script 0.1.0 answers =used= with =used is in the Zig build only=. - Files of XALT JSON objects and/or Lmod ModuleUsageTracking lines, as the site already keeps. Run records carry =userT= and optionally =libA=. Link records carry =resultT= and =linkA=. Package records carry =package_path=. Lmod lines carry =path= under the module tree. @@ -45,7 +45,7 @@ Before uninstalling or retiring an install tree, see whether XALT or Lmod record | Message | Cause | What to do | |---|---|---| -| =eb-keep-logs: used is in the Zig build only= | The =eb-keep-logs= on =PATH= is the shell script. | Put the Zig build first on =PATH=. | +| =eb-keep-logs: used is in the Zig build only= | The =eb-keep-logs= on =PATH= is the shell script 0.1.0. | Put the Zig build first on =PATH=. | | =eb-keep-logs: used needs --prefix= | =--prefix= was omitted or empty. | Pass the install tree to check. | | =eb-keep-logs: used needs a record file= | No file was given. | Pass at least one record file. | | =eb-keep-logs: used: PATH is not XALT run JSON= | A file held truncated or invalid JSON. | Fix the file; partial hits from a bad object are not printed. | diff --git a/docs/orgmode/howto/find-why-a-build-failed.org b/docs/orgmode/howto/find-why-a-build-failed.org index 39d967d..7bf4416 100644 --- a/docs/orgmode/howto/find-why-a-build-failed.org +++ b/docs/orgmode/howto/find-why-a-build-failed.org @@ -9,7 +9,7 @@ Use this after a run in which builds failed, to see for each the EasyBuild step ** Before you start -- =eb-keep-logs= on your =PATH= as the release binary or a Zig build; the shell script in the repository has no =why= or =history=. +- =eb-keep-logs= 0.2.0 or later on your =PATH=; the shell script 0.1.0 has no =why= or =history=. - A log tree, here =~/build-logs=, whose runs are named by their date and time, =YYYYMMDD_HHMMSS=, as [[file:call-from-a-pipeline.org][Call eb-keep-logs from a build pipeline]] makes them. A run keeps each build's =NAME.stdout.log= and, for a failed build, =NAME.failed.ebout.log=, in its own directory or in a directory per target, as eb-pipeline keeps them. @@ -126,7 +126,7 @@ Use this after a run in which builds failed, to see for each the EasyBuild step | Message | Cause | What to do | |----------------------------------------------+-----------------------------------------------------------------------------------------------------------+------------------------------------------------------------------| -| =eb-keep-logs: why is in the Zig build only= | The =eb-keep-logs= on your =PATH= is the shell script. | Put the Zig build first on =PATH=. | +| =eb-keep-logs: why is in the Zig build only= | The =eb-keep-logs= on your =PATH= is the shell script 0.1.0. | Put the Zig build first on =PATH=. | | =eb-keep-logs: ROOT PATH is not a directory= | =--root= names no directory. | Give =--root= the log tree. | | =eb-keep-logs: no run under ROOT; it holds no directory named YYYYMMDD_HHMMSS. Give --root the directory of the runs, or name one run= | =ROOT= holds no directory named =YYYYMMDD_HHMMSS=. =ROOT= is the current directory when =--root= is left out. | Give =--root= the directory that holds the runs, or name one run. | | =RUN: 0 failed builds of 0= | The run holds no =NAME.stdout.log= or =NAME.failed.ebout.log=, in its own directory or one below it. | Check that the pipeline writes its logs where =why= reads them. | diff --git a/docs/orgmode/howto/what-a-dry-run-would-build.org b/docs/orgmode/howto/what-a-dry-run-would-build.org index bb78647..05a5ee1 100644 --- a/docs/orgmode/howto/what-a-dry-run-would-build.org +++ b/docs/orgmode/howto/what-a-dry-run-would-build.org @@ -11,7 +11,7 @@ A module marked =[x]= is already installed and is not listed. ** Before you start -- The Zig build of =eb-keep-logs=. The shell script answers =pending= with =pending is in the Zig build only=. +- =eb-keep-logs= 0.2.0 or later. The shell script 0.1.0 answers =pending= with =pending is in the Zig build only=. - A file that holds the report. =eb -Dr= prints a dry run, and =eb -M= prints the missing modules. The shapes are the ones in [[https://docs.easybuild.io/using-easybuild/][Getting an overview of planned installations]]. @@ -33,7 +33,7 @@ A module marked =[x]= is already installed and is not listed. | Message | Cause | What to do | |---|---|---| -| =eb-keep-logs: pending is in the Zig build only= | The =eb-keep-logs= on =PATH= is the shell script. | Put the Zig build first on =PATH=. | +| =eb-keep-logs: pending is in the Zig build only= | The =eb-keep-logs= on =PATH= is the shell script 0.1.0. | Put the Zig build first on =PATH=. | | =eb-keep-logs: pending needs a report= | No file was given. | Pass the path of the saved report. | | =eb-keep-logs: pending: PATH is not a dry-run or missing-modules report= | The file has neither shape. | Point it at the output of =eb --dry-run= or =eb --missing-modules=. | | =eb-keep-logs: pending does not know 'OPTION'= | An option was given. | The command takes the report path and nothing else. | diff --git a/docs/orgmode/howto/who-loaded-a-module.org b/docs/orgmode/howto/who-loaded-a-module.org index b3fec06..cbc592c 100644 --- a/docs/orgmode/howto/who-loaded-a-module.org +++ b/docs/orgmode/howto/who-loaded-a-module.org @@ -10,7 +10,7 @@ Lmod can syslog each load as =user=USER module=NAME path=PATH host=HOST time=TIM ** Before you start -- The Zig build of =eb-keep-logs=. The shell script answers =loads= with =loads is in the Zig build only=. +- =eb-keep-logs= 0.2.0 or later. The shell script 0.1.0 answers =loads= with =loads is in the Zig build only=. Put the Zig build first on =PATH=, as [[file:find-why-a-build-failed.org][Find why a build failed]] does for =why=. - A file of tracking lines. A syslog prefix in front of the record is fine. =journalctl= output redirected to a file is one. @@ -42,7 +42,7 @@ Lmod can syslog each load as =user=USER module=NAME path=PATH host=HOST time=TIM | Message | Cause | What to do | |---|---|---| -| =eb-keep-logs: loads is in the Zig build only= | The =eb-keep-logs= on =PATH= is the shell script. | Put the Zig build first on =PATH=. | +| =eb-keep-logs: loads is in the Zig build only= | The =eb-keep-logs= on =PATH= is the shell script 0.1.0. | Put the Zig build first on =PATH=. | | =eb-keep-logs: loads needs --module= | =--module= was omitted, or its value was empty. | Pass the full module name, as =GROMACS/2024.1=. | | =eb-keep-logs: loads needs a log file= | No file was given. | Pass the path of the tracking log. | | =eb-keep-logs: cannot read FILE: ERROR= | The file cannot be opened or is larger than 64 MiB. | Point at the log you can read, or split a larger one. | diff --git a/docs/orgmode/howto/who-ran-an-executable.org b/docs/orgmode/howto/who-ran-an-executable.org index f081f15..689f587 100644 --- a/docs/orgmode/howto/who-ran-an-executable.org +++ b/docs/orgmode/howto/who-ran-an-executable.org @@ -11,7 +11,7 @@ A link record, the one that lists libraries, is not a run and is skipped. ** Before you start -- The Zig build of =eb-keep-logs=. The shell script answers =runs= with =runs is in the Zig build only=. +- =eb-keep-logs= 0.2.0 or later. The shell script 0.1.0 answers =runs= with =runs is in the Zig build only=. - A file of XALT run records. Each record is a JSON object, and several may follow one another. =userT= holds =user=, =exec_path= and, when XALT wrote them, =syshost= and =start_time=. The shape is the one in [[https://xalt.readthedocs.io/en/latest/120_xalt_json.html][XALT's JSON record]]. @@ -32,7 +32,7 @@ A link record, the one that lists libraries, is not a run and is skipped. | Message | Cause | What to do | |---|---|---| -| =eb-keep-logs: runs is in the Zig build only= | The =eb-keep-logs= on =PATH= is the shell script. | Put the Zig build first on =PATH=. | +| =eb-keep-logs: runs is in the Zig build only= | The =eb-keep-logs= on =PATH= is the shell script 0.1.0. | Put the Zig build first on =PATH=. | | =eb-keep-logs: runs needs --exec= | =--exec= was omitted, or its value was empty. | Pass the executable path, or its last component, as =gmx=. | | =eb-keep-logs: runs needs a record file= | No file was given. | Pass the path of the XALT records. | | =eb-keep-logs: runs: PATH is not XALT run JSON= | The file is not one or more JSON objects. | Point it at the run records, not a log of another shape. | diff --git a/docs/orgmode/index.org b/docs/orgmode/index.org index 6b1a7ce..736a13e 100644 --- a/docs/orgmode/index.org +++ b/docs/orgmode/index.org @@ -8,7 +8,7 @@ Keep the logs of EasyBuild builds that a build pipeline would otherwise lose, an After a failed build, =eb-keep-logs failed= copies the EasyBuild log and the failing command's own output next to the build's output, where the end of the job does not take them, and closes the copies to other users, because a failed compile line of licensed software can print the licence number. =eb-keep-logs rotate= compresses the logs of old runs and removes the oldest runs. =eb-keep-logs why= says from the kept logs why a run's builds failed, and =eb-keep-logs history= how a package's builds went run by run. -Each release is one static binary per architecture that needs nothing but =eb=; the shell script it was ported from stays in the repository as the same tool, without =why= and =history=. +Each release is one static binary per architecture that needs nothing but =eb=. New here? [[file:tutorials/keep-a-failed-build-log.org][Keep a failed build's logs]] runs an EasyBuild build that fails and ends with its log and the compiler's error kept in a directory of your own. diff --git a/docs/orgmode/reference/json-schemas.org b/docs/orgmode/reference/json-schemas.org index e0c7b74..f7a3b40 100644 --- a/docs/orgmode/reference/json-schemas.org +++ b/docs/orgmode/reference/json-schemas.org @@ -6,7 +6,7 @@ The Zig build's =--json= on =why=, =history=, =failures=, =loads=, =runs=, =used=, =usage=, =pending=, =test-compare= and =lifecycle= prints one line of JSON with =schema_version= 1. The =test-bundle= command always writes one JSON document with =schema_version= 1. -The shell script refuses those commands; see [[file:compatibility.org][Compatibility]]. +The shell script 0.1.0 refused those commands; see [[file:compatibility.org][Compatibility]]. Each document is validated in CI against a JSON Schema file in the repository tree under =docs/orgmode/reference/json/=. The schemas use draft 2020-12; a new =schema_version= may drop or rename a key, or change what one means. diff --git a/docs/orgmode/tutorials/keep-a-failed-build-log.org b/docs/orgmode/tutorials/keep-a-failed-build-log.org index dc96f03..fb1a6a3 100644 --- a/docs/orgmode/tutorials/keep-a-failed-build-log.org +++ b/docs/orgmode/tutorials/keep-a-failed-build-log.org @@ -42,7 +42,6 @@ eb-keep-logs 0.3.1 (x86_64-linux-musl, zig 0.17.1, abc1234) #+end_example [[file:../howto/install.org][Install eb-keep-logs]] has the release binary when you do not need the main-branch fix. -The shell script in the repository runs =failed= and =rotate= only; =why= and =history= are in the Zig build only, and the script says so when it is asked for them. ** Make a directory for this run's logs diff --git a/eb-keep-logs b/eb-keep-logs deleted file mode 100755 index 0f48bc9..0000000 --- a/eb-keep-logs +++ /dev/null @@ -1,1095 +0,0 @@ -#!/bin/bash -# eb-keep-logs: keep the logs of EasyBuild builds that a build pipeline would -# otherwise lose, and keep the pipeline's log tree bounded. -# -# A failed build's log is in EasyBuild's tmpdir on the build node, which goes -# with the job; and EasyBuild wraps the "Results of the build can be found in -# the log file(s)" line, so parsing stdout for the path finds nothing. -# `eb --last-log` gives the path, on one line with the basic output style. -set -uo pipefail - -VERSION=0.1.0 - -# src/main.zig's usage_text holds the same text: tests/differential.sh -# compares the two. -usage() { - cat <<'EOF' -eb-keep-logs: keep the logs of EasyBuild builds that a build pipeline would -otherwise lose, and keep the pipeline's log tree bounded. - - eb-keep-logs failed [--syslog TARGET] [--metrics-file PATH] STATUS NAME LOGDIR [TMP_LOGDIR] - After `eb` returned STATUS for easyconfig NAME: when STATUS is not 0, - copy the EasyBuild session log `eb --last-log` names, the failing - command's output and a meson testlog next to LOGDIR/NAME.stdout.log, - closed to others and listed in LOGDIR/.licensed-logs. TMP_LOGDIR is - the --tmp-logdir eb ran with; without it, the newest log in - EasyBuild's default place is used, unless it is another build's. - NAME.stdout.log and a TMP_LOGDIR below LOGDIR are closed to others too. - --syslog TARGET, --syslog=TARGET - Emit an RFC 5424 or native systemd-journald event when logs are - kept or none are found. Default: EB_KEEP_LOGS_SYSLOG, else none. - --metrics-file PATH, --metrics-file=PATH - Atomically update Prometheus counters for kept logs and bytes. - Default: none. - eb-keep-logs rotate ROOT --compress-after DAYS [--delete-after DAYS] - [--dry-run] [--lock-timeout SECONDS] - [--syslog TARGET] [--metrics-file PATH] - In the run directories directly under ROOT (named YYYYMMDD_HHMMSS), - gzip the *.log and *.txt files of old runs and remove older runs - whole, leaving alone a run that is still written into. A run's age is - in days from the local midnight of the date in its name. Permissions - and .licensed-logs follow. One rotate of ROOT runs at a time, holding - ROOT/.eb-keep-logs-rotate.lock. Options and ROOT come in any order. - --compress-after DAYS, --compress-after=DAYS - Gzip the files of runs at least DAYS old. Required; there is no - default. - --delete-after DAYS, --delete-after=DAYS - Remove whole runs at least DAYS old; DAYS must be larger than - that of --compress-after. Default: none; no run is removed. An - empty value is the default. - --dry-run - Print each file that would be compressed and run that would be - deleted, but change nothing, create no lock, emit no event and - write no metrics. - --lock-timeout SECONDS, --lock-timeout=SECONDS - While another rotate holds the lock, wait up to SECONDS for it, - then give up and exit 75. Default: 600; 0 does not wait. An empty - value is the default. - --syslog TARGET, --syslog=TARGET - Emit an RFC 5424 or native systemd-journald event with the - compressed and deleted counts. Default: EB_KEEP_LOGS_SYSLOG, - else none. - --metrics-file PATH, --metrics-file=PATH - Atomically record when this rotation completed, unless --dry-run - is given. Default: none. - eb-keep-logs why [RUN | --latest] [--target TARGET] [--package PACKAGE] - [--since DATE] [--until DATE] [--root ROOT] [--json] - Say why the builds of a run failed: for each failed easyconfig, its - package and easyconfig, the EasyBuild step it failed in, EasyBuild's - message, and the line of its kept log that shows the error: the first - compiler or linker error, else EasyBuild's own error line, with the - line number and three lines either side. Logs rotate compressed are - read as they are. Zig build only. RUN and the options come in any - order. - RUN - A run directory, as a path or as a name under ROOT. - --latest - The newest run under ROOT, or the newest with a directory - TARGET. The default when no RUN is given. - --target TARGET, --target=TARGET - Only the builds in the run's directory TARGET. Default: those in - the run's own directory and in every directory in it. - --package PACKAGE, --package=PACKAGE - Only builds matching PACKAGE (an easyconfig name without .eb, - a prefix up to a dash, or NAME/VERSION). Default: all builds. - --since DATE, --since=DATE - Only consider runs at or after DATE when picking --latest. - DATE is YYYY-MM-DD, YYYYMMDD, or YYYYMMDD_HHMMSS. - Default: none. - --until DATE, --until=DATE - Only consider runs at or before DATE when picking --latest. - DATE is YYYY-MM-DD, YYYYMMDD, or YYYYMMDD_HHMMSS. - Default: none. - --root ROOT, --root=ROOT - The directory that holds the runs. Default: the current - directory. - --json - Print one line of JSON instead, with schema_version 1. - eb-keep-logs history PACKAGE [--target TARGET] [--since DATE] - [--until DATE] [--failed] [--root ROOT] [--json] - Say how each kept build of PACKAGE went, oldest run first: success, - failed or unknown, and how long EasyBuild took, from its output. - PACKAGE is an easyconfig's name or its start up to a dash, as hello - or hello-2.12.1 for hello-2.12.1-GCCcore-14.2.0, or a module name, as - hello/2.12.1; hello also takes hello-world-1.0. Zig build only. - PACKAGE and the options come in any order. - --target TARGET, --target=TARGET - Only the builds in each run's directory TARGET. Default: those in - each run's own directory and in every directory in it. - --since DATE, --since=DATE - Only read runs at or after DATE (YYYY-MM-DD, YYYYMMDD, or - YYYYMMDD_HHMMSS). Default: none. - --until DATE, --until=DATE - Only read runs at or before DATE (YYYY-MM-DD, YYYYMMDD, or - YYYYMMDD_HHMMSS). Default: none. - --failed - Only list failed builds. - --root ROOT, --root=ROOT - The directory that holds the runs. Default: the current - directory. - --json - Print one line of JSON instead, with schema_version 1. - eb-keep-logs failures [--package PACKAGE] [--target TARGET] - [--since DATE] [--until DATE] [--root ROOT] [--json] - List failed builds across runs under --root, oldest run first. - Each row gives the run, target, failed step, duration and build - name. Zig build only. Options come in any order. - --package PACKAGE, --package=PACKAGE - Only failed builds matching PACKAGE (an easyconfig name - without .eb, a prefix up to a dash, or NAME/VERSION). Default: - all packages. - --target TARGET, --target=TARGET - Only the builds in each run's directory TARGET. Default: those - in each run's own directory and in every directory in it. - --since DATE, --since=DATE - Only read runs at or after DATE (YYYY-MM-DD, YYYYMMDD, or - YYYYMMDD_HHMMSS). Default: none. - --until DATE, --until=DATE - Only read runs at or before DATE (YYYY-MM-DD, YYYYMMDD, or - YYYYMMDD_HHMMSS). Default: none. - --root ROOT, --root=ROOT - The directory that holds the runs. Default: the current - directory. - --json - Print one line of JSON instead, with schema_version 1. - eb-keep-logs loads --module NAME [--json] FILE - Print who loaded NAME, from Lmod's ModuleUsageTracking lines in FILE. - Each record is user=USER module=NAME path=PATH host=HOST time=TIME, - in any order, and a syslog prefix is left in place. Each load is - one line, user=USER host=HOST time=TIME path=PATH, in the file's - order. A file with no load of NAME prints no load of NAME. Zig - build only. - --module NAME, --module=NAME - The module's full name, as Lmod recorded it, such as - GROMACS/2024.1. Required. - --json - Print one line of JSON instead, with schema_version 1. - FILE - The log that holds the records. A line that is not one is - skipped. - eb-keep-logs used --prefix PREFIX [--json] [--require-none] FILE... - Print paths under PREFIX that appear in XALT or Lmod records in - FILE. A run record lists userT.exec_path (kind run) and each libA - path under PREFIX (kind run-lib) even when exec_path is outside. - A link record lists resultT.exec_path and each linkA path (kind - link). A package record lists package_path (kind pkg). An Lmod - tracking line lists path when it is under PREFIX (kind module-load). - Each line is path=PATH kind=KIND last=TIME count=N; last is the - newest time seen for that path. With no hit, nothing under PREFIX. - --json prints one JSON document with schema_version 1. --require-none - exits 2 when any hit is listed. Zig build only. - --prefix PREFIX, --prefix=PREFIX - The install tree to check. Required; a newline in it is refused. - --json - Print one line of JSON instead. - --require-none - Exit 2 when any path under PREFIX was found. - FILE - One or more files of concatenated XALT JSON objects and/or Lmod - ModuleUsageTracking lines. Required. - eb-keep-logs usage --software DIR --modules DIR [--since EPOCH] - [--unused | --active] [--json] FILE... - Compare installed DIR/Name/Version software with XALT and Lmod - records. XALT paths below the software directory and Lmod module - loads below the modules directory count as hits. By default, print - every installed Name/Version with its state, hit count and newest - time. --unused and --active print only Name/Version lines; - --active output is accepted by eb-stack stack gap --site. --since - ignores records older than EPOCH and records without a time. - --json prints one JSON document with schema_version 1. Zig build - only. - --software DIR, --software=DIR - The software install tree, with Name/Version directories. - Required. - --modules DIR, --modules=DIR - The module tree that Lmod record paths must be below. Required. - --since EPOCH, --since=EPOCH - Count records at or after this non-negative epoch time. - Default: all record times. - --unused - List installed Name/Version entries with no hit. - --active - List installed Name/Version entries with at least one hit. - --json - Print one line of JSON instead. - FILE - One or more files of concatenated XALT JSON objects and/or Lmod - ModuleUsageTracking lines. Required. - eb-keep-logs runs --exec PATH [--json] FILE - Print who ran PATH, from XALT run records in FILE. A run record is a - JSON object whose userT holds user, exec_path and, when present, - syshost and start_time. A link record is not a run and is skipped. - PATH matches exec_path in full or as its last component. Each run is - one line, user=USER host=HOST time=TIME path=PATH, in the file's - order. A file with no run of PATH prints no run of PATH. Zig build - only. It does not record runs. - --exec PATH, --exec=PATH - The executable, as a full path or its last component. Required. - --json - Print one line of JSON instead, with schema_version 1. - FILE - One or more JSON objects. An object that is not a run record is - skipped. - eb-keep-logs pending [--json] FILE - Print what an EasyBuild dry-run or missing-modules report still has - to build. A dry-run line is "* [ ] PATH (module: NAME)", and [F] and - [R] count as still to build; [x] is already installed and is not - printed. --terse prints "x PATH" or "- PATH". A missing-modules line - is "* NAME (FILE.eb)", or with --terse one easyconfig path on each - line. Each is one line, build NAME or missing NAME, in the file's - order. A report with nothing left prints nothing to build. Zig build - only. It does not run eb, and it does not resolve dependencies. - --json - Print one line of JSON instead, with schema_version 1. - FILE - The report, as eb --dry-run or eb --missing-modules printed it. - Required. - eb-keep-logs test-bundle --test-id ID --suite-revision REV --eessi-target TARGET - ... --stdout FILE --stderr FILE [--input FILE ...] - ... [--module NAME=PATH ...] --seed SEED - ... --allocation TEXT --binding TEXT --cpu TEXT --gpu TEXT - [--out FILE] - Write one flaky-test evidence bundle as JSON schema_version 1, with a - stable test identity (ID), normalized stdout and stderr, input and - seed hashes, full module list and module paths, EESSI target, - scheduler allocation and binding, CPU and GPU facts, and test-suite - revision. Without --out, print it on stdout. Zig build only. - --test-id ID, --test-id=ID - Stable test identity. Required. - --suite-revision REV, --suite-revision=REV - Test-suite revision. Required. - --eessi-target TARGET, --eessi-target=TARGET - EESSI target of the run. Required. - --stdout FILE, --stdout=FILE - Captured stdout, normalized and hashed. Required. - --stderr FILE, --stderr=FILE - Captured stderr, normalized and hashed. Required. - --input FILE, --input=FILE - Input file to hash. Optional; may be repeated. Default: none. - --module NAME=PATH, --module=NAME=PATH - Loaded module and its modulefile path. Optional; may be - repeated. Default: none. - --seed SEED, --seed=SEED - Seed value to hash. Required. - --allocation TEXT, --allocation=TEXT - Scheduler allocation summary. Required. - --binding TEXT, --binding=TEXT - Scheduler binding summary. Required. - --cpu TEXT, --cpu=TEXT - CPU facts. Required. - --gpu TEXT, --gpu=TEXT - GPU facts, or none. Required. - --out FILE, --out=FILE - Write JSON to FILE. Default: stdout. - eb-keep-logs test-compare [--json] BUNDLE... - Summarize which evidence fields differ across two or more - test-bundle JSON files, without deciding pass or fail. --json prints - schema_version 1. Zig build only. - --json - Print one line of JSON instead of text. Default: text. - BUNDLE - Two or more test-bundle JSON files. Required. - eb-keep-logs lifecycle --policy FILE [--modulerc-out FILE] - [--easyconfigs DIR ...] [--easystack FILE ...] - [--eb-stack PATH] [--rebuild-set FILE] - [--now EPOCH] [--json] FILE - Generate a reversible lifecycle plan and Lmod .modulerc.lua - warnings/forbids from usage --json output and a TOML policy. Never - deletes software or modulefiles. Requires a minimum observation - window and checks installed dependents via eb-stack rebuild-set - before allowing candidate-remove. Zig build only. - --policy FILE, --policy=FILE - TOML lifecycle policy file. Required. - --modulerc-out FILE, --modulerc-out=FILE - Write the generated Lmod .modulerc.lua warnings and forbids - durably to FILE. Default: none; no file is written. - --easyconfigs DIR, --easyconfigs=DIR - Easyconfig tree passed to eb-stack rebuild-set to identify - dependents of candidate removals. Repeatable. Default: none. - --easystack FILE, --easystack=FILE - Deployed easystack YAML passed to eb-stack rebuild-set. - Repeatable. Default: none. - --eb-stack PATH, --eb-stack=PATH - Path to the eb-stack executable. Default: eb-stack on PATH. - --rebuild-set FILE, --rebuild-set=FILE - Precomputed eb-stack rebuild-set.json report instead of - running eb-stack. Default: none. - --now EPOCH, --now=EPOCH - Reference epoch time in seconds for idle age and observation - window checks. Default: the environment time override, else - the current time. - --json - Print one line of JSON instead, with schema_version 1. - FILE - JSON output produced by eb-keep-logs usage --json (with - selection "all"). Required. - eb-keep-logs -h | --help - Print this help on stdout and exit 0. - eb-keep-logs --version - Print the version line on stdout and exit 0. - -Environment: - PATH Where failed looks up eb. - EASYBUILD_TMPDIR failed copies a command's output only from below it; - unset or empty, it copies none. - EB_KEEP_LOGS_NOW The time rotate and lifecycle take as now, in seconds - since the epoch; unset or empty, the current time. - EB_PIPELINE_LOG_DIR rotate leaves alone the run that holds this path. - EB_KEEP_LOGS_SYSLOG Default --syslog target (journald, syslog, unix:///..., - journal+unix:///..., udp://host:port, tcp://host:port). - EB_KEEP_LOGS_SYSLOG_PEN - IANA Private Enterprise Number for RFC 5424 SD-ID - ebKeepLogs@. Default: 32473 (RFC 5398 placeholder). - TZ, TZDIR The time zone of the local midnights, and the - directory of zone files. - -Exit status: - 0 -h, --help or --version, or a failed, rotate, why, history, failures, loads, runs, used, usage, pending, test-bundle, test-compare or lifecycle that - accepted its arguments, whatever it could keep, compress, remove or - read: what it could not do is reported on stderr. used with - --require-none also exits 2 when any path was listed. - 2 The invocation was refused, with eb-keep-logs: MESSAGE on stderr; or - no command was given, and this help is on stdout. - 75 rotate waited --lock-timeout seconds for the lock another rotate - held, then gave up and changed nothing; run it again later. -EOF -} - -die() { echo "eb-keep-logs: $*" >&2; exit 2; } - -# A directory argument as paths join it to a name with "/": without trailing -# slashes, so "logs/" gives "logs/NAME" and "/" gives "/NAME". -_joinable() { - local dir="$1" - while [[ "${dir}" == */ ]]; do dir="${dir%/}"; done - printf '%s\n' "${dir}" -} - -# COUNT WORD: "1 WORD", else COUNT and WORD with an s. -_count() { - if [ "$1" -eq 1 ]; then echo "$1 $2"; else echo "$1 $2s"; fi -} - -# Record a kept file as one that may carry a licence number: a failed compile -# line of licensed software prints it. Once: a retried build keeps the same -# files again. -_list() { - local path="$1" logdir="$2" abs - abs=$(realpath "${path}") - grep -qxF -- "${abs}" "${logdir}/.licensed-logs" 2>/dev/null || - echo "${abs}" >> "${logdir}/.licensed-logs" -} - -_private() { - local path="$1" logdir="$2" - chmod o-rwx "${path}" - _list "${path}" "${logdir}" -} - -# The last command output a session log names, unless the lines after it -# record that command ending well: EasyBuild logs "... completed -# successfully" or "... FAILED (exit code N)" when a command ends, and -# nothing when the build died while it ran. -_failed_command_output() { - local hit outcome - hit=$(grep -noE '/[^[:space:]]*/run-shell-cmd-output/[^/[:space:]]+/out\.txt' "$1" | tail -n 1) - [ -n "${hit}" ] || return 0 - outcome=$(tail -n +"$((${hit%%:*} + 1))" "$1" | grep -m 1 -oE ' FAILED \(exit code | completed successfully' | head -n 1) - [ "${outcome}" = " completed successfully" ] || echo "${hit#*:}" -} - -# Whether a meson testlog's summary shows every test passing: an "Ok:" line, -# and no "Fail:", "Unexpected Pass:" or "Timeout:" line counting more than 0. -_meson_passed() { - grep -q '^Ok:' "$1" && ! grep -qE '^(Fail|Unexpected Pass|Timeout):[[:space:]]*[1-9]' "$1" -} - -# The last line `eb --last-log` prints. EasyBuild 5.3 and later fold that path -# at the terminal width, 80 columns on a pipe, unless given -# --output-style=basic (EasyBuild 4.5 and later); an older eb refuses the -# option and does not fold, so it is asked again without it. -_last_log() { - local line - if line=$(eb --last-log "$@" --output-style=basic 2>/dev/null | tail -1) && [ -n "${line}" ]; then - printf '%s\n' "${line}" - else - eb --last-log "$@" 2>/dev/null | tail -1 - fi -} - -_resolve_syslog_pen() { - local raw="${EB_KEEP_LOGS_SYSLOG_PEN:-}" - SYSLOG_PEN="32473" - [ -n "${raw}" ] || return 0 - local s="${raw#"${raw%%[![:space:]]*}"}" - s="${s%"${s##*[![:space:]]}"}" - [[ -n "${s}" && "${#s}" -le 20 && "${s}" =~ ^[0-9]+$ ]] || - die "EB_KEEP_LOGS_SYSLOG_PEN must be a positive integer, not '${raw}'" - local trimmed="${s#"${s%%[!0]*}"}" - [ -n "${trimmed}" ] || - die "EB_KEEP_LOGS_SYSLOG_PEN must be a positive integer, not '${raw}'" - if [ "${#trimmed}" -eq 20 ]; then - local hi="${trimmed:0:10}" lo="${trimmed:10:10}" - lo="1${lo}" - if [ "${hi}" -gt 1844674407 ] || { [ "${hi}" -eq 1844674407 ] && [ "${lo}" -gt 13709551615 ]; }; then - die "EB_KEEP_LOGS_SYSLOG_PEN must be a positive integer, not '${raw}'" - fi - fi - SYSLOG_PEN="${trimmed}" -} - -_resolve_syslog() { - local raw="${1}" - SYSLOG_TARGET="" - [ -n "${raw}" ] || return 0 - case "${raw}" in - *$'\n'*|*$'\r'*) die "invalid syslog target '${raw}'" ;; - syslog|journald|journal|/*|unix:///*|journal+unix:///*) ;; - udp://*:*|tcp://*:*) - local hp port host - hp="${raw#*://}" - port="${hp##*:}" - host="${hp%:*}" - [[ -n "${host}" && "${port}" =~ ^[0-9]+$ && "${port}" -ge 1 && "${port}" -le 65535 ]] || - die "invalid syslog target '${raw}'" - ;; - *) die "invalid syslog target '${raw}'" ;; - esac - SYSLOG_TARGET="${raw}" -} - -_emit_syslog() { - local target="$1" sev="$2" msgid="$3" msg="$4" - shift 4 - [ -n "${target}" ] || return 0 - local py="" - if command -v python3 >/dev/null 2>&1; then - py=$(command -v python3) - elif [ -x /usr/bin/python3 ]; then - py=/usr/bin/python3 - fi - if [ -n "${py}" ]; then - if ! "${py}" - "$target" "${SYSLOG_PEN:-32473}" "$sev" "$msgid" "$msg" "$$" "$@" <<'PY' -import datetime, os, socket, sys - -target, pen, sev_s, msgid, msg, pid = sys.argv[1:7] -pairs = [kv.split("=", 1) for kv in sys.argv[7:] if "=" in kv] - -def one_line(s, limit=500): - return "".join(" " if ord(c) < 32 or ord(c) == 127 else c for c in s)[:limit] - -def sd_esc(v): - return one_line(v, 256).replace("\\", "\\\\").replace('"', '\\"').replace("]", "\\]") - -def send_unix(path, payload, stream_nl): - try: - with socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM) as s: - s.settimeout(0.5) - s.connect(path) - s.sendall(payload) - return True - except OSError: - if not stream_nl: - return False - try: - with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: - s.settimeout(0.5) - s.connect(path) - s.sendall(payload + b"\n") - return True - except OSError: - return False - -if target in ("journald", "journal"): - scheme, hp, port = "journal", "/run/systemd/journal/socket", 0 -elif target == "syslog": - scheme, hp, port = "unix", "/dev/log", 0 -elif target.startswith("/"): - scheme, hp, port = "unix", target, 0 -elif target.startswith("unix://"): - scheme, hp, port = "unix", target[7:], 0 -elif target.startswith("journal+unix://"): - scheme, hp, port = "journal", target[15:], 0 -elif target.startswith("udp://"): - h, p = target[6:].rsplit(":", 1) - if h.startswith("[") and h.endswith("]"): - h = h[1:-1] - scheme, hp, port = "udp", h, int(p) -else: - h, p = target[6:].rsplit(":", 1) - if h.startswith("[") and h.endswith("]"): - h = h[1:-1] - scheme, hp, port = "tcp", h, int(p) - -if scheme == "journal": - entries = [ - ("MESSAGE", one_line(msg)), - ("PRIORITY", sev_s), - ("SYSLOG_IDENTIFIER", "eb-keep-logs"), - ("SYSLOG_FACILITY", "1"), - ("MSGID", msgid), - ] - for k, v in pairs: - if k.startswith("J:") and v: - entries.append((k[2:], one_line(v))) - payload = b"".join( - f"{k}={v}\n".encode("utf-8", "replace") - for k, v in entries - ) - ok = send_unix(hp, payload, False) -else: - pri = 8 + int(sev_s) - ts = datetime.datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ") - host = "".join(c for c in socket.gethostname() if 33 <= ord(c) <= 126)[:255] or "-" - sd = " ".join(f'{k[2:]}="{sd_esc(v)}"' for k, v in pairs if k.startswith("P:")) - line = f"<{pri}>1 {ts} {host} eb-keep-logs {pid} {msgid} [ebKeepLogs@{pen} {sd}] {one_line(msg)}" - payload = line.encode("utf-8", "replace") - cap = os.environ.get("EB_KEEP_LOGS_SYSLOG_CAPTURE") - if cap: - out = payload - if scheme == "tcp": - out = f"{len(payload)} ".encode("ascii") + payload - with open(cap, "wb") as fh: - fh.write(out) - sys.exit(0) - if scheme == "unix": - ok = send_unix(hp, payload, True) - elif scheme == "udp": - ok = False - for fam, _, _, _, sa in socket.getaddrinfo(hp, port, 0, socket.SOCK_DGRAM): - try: - with socket.socket(fam, socket.SOCK_DGRAM) as s: - s.settimeout(0.5) - s.sendto(payload, sa) - ok = True - break - except OSError: - continue - else: - frame = f"{len(payload)} ".encode("ascii") + payload - try: - with socket.create_connection((hp, port), timeout=0.5) as s: - s.sendall(frame) - ok = True - except OSError: - ok = False -sys.exit(0 if ok else 1) -PY - then - echo "eb-keep-logs: cannot emit syslog event" >&2 - fi - fi -} - -_emit_failed_syslog() { - local target="$1" status="$2" name="$3" logdir_s="$4" ebout="$5" cmd_kept="$6" meson="$7" reason="$8" - [ -n "${target}" ] || return 0 - local kept=$((ebout + cmd_kept + meson)) - local licensed="${kept}" - local cmdout=0; [ "${cmd_kept}" -gt 0 ] && cmdout=1 - local msgid="EB_KEEP_NONE" - [ "${kept}" -gt 0 ] && msgid="EB_KEEP_FAILED" - local msg - if [ "${kept}" -gt 0 ]; then - msg="eb-keep-logs failed: kept $(_count "${kept}" file) for ${name} (status ${status})" - else - msg="eb-keep-logs failed: no EasyBuild log kept for ${name} (${reason})" - fi - local extra=() - [ -n "${SLURM_JOB_ID:-}" ] && extra+=("P:job=${SLURM_JOB_ID}" "J:SLURM_JOB_ID=${SLURM_JOB_ID}") - [ -n "${SLURM_STEP_ID:-}" ] && extra+=("P:step=${SLURM_STEP_ID}" "J:SLURM_STEP_ID=${SLURM_STEP_ID}") - _emit_syslog "${target}" 4 "${msgid}" "${msg}" \ - "P:cmd=failed" "P:status=${status}" "P:name=${name}" "P:logdir=${logdir_s}" \ - "P:kept=${kept}" "P:licensed=${licensed}" "P:ebout=${ebout}" \ - "P:cmdout=${cmdout}" "P:meson=${meson}" "P:reason=${reason}" \ - "J:EB_KEEP_CMD=failed" "J:EB_KEEP_STATUS=${status}" "J:EB_KEEP_NAME=${name}" \ - "J:EB_KEEP_LOGDIR=${logdir_s}" "J:EB_KEEP_KEPT=${kept}" "J:EB_KEEP_LICENSED=${licensed}" \ - "J:EB_KEEP_EBOUT=${ebout}" "J:EB_KEEP_CMDOUT=${cmdout}" "J:EB_KEEP_MESON=${meson}" \ - "J:EB_KEEP_REASON=${reason}" "${extra[@]}" -} - -# Add two unsigned decimal integers without using Bash's signed arithmetic. -# Refuse a result beyond the u64 range used by the Zig implementation. -_add_u64() { - local a="$1" b="$2" out="" carry=0 da db sum - local i j max=18446744073709551615 - a="${a#"${a%%[!0]*}"}"; a="${a:-0}" - b="${b#"${b%%[!0]*}"}"; b="${b:-0}" - i=${#a}; j=${#b} - while [ "${i}" -gt 0 ] || [ "${j}" -gt 0 ] || [ "${carry}" -gt 0 ]; do - da=0 - db=0 - if [ "${i}" -gt 0 ]; then i=$((i - 1)); da="${a:i:1}"; fi - if [ "${j}" -gt 0 ]; then j=$((j - 1)); db="${b:j:1}"; fi - sum=$((da + db + carry)) - out="$((sum % 10))${out}" - carry=$((sum / 10)) - done - # Decimal strings of equal length are ordered lexically. - # shellcheck disable=SC2071 - if [ "${#out}" -gt "${#max}" ] || - { [ "${#out}" -eq "${#max}" ] && [[ "${out}" > "${max}" ]]; }; then - return 1 - fi - printf '%s\n' "${out}" -} - -_u64_gt() { - local a="$1" b="$2" - a="${a#"${a%%[!0]*}"}"; a="${a:-0}" - b="${b#"${b%%[!0]*}"}"; b="${b:-0}" - [ "${#a}" -gt "${#b}" ] && return 0 - [ "${#a}" -lt "${#b}" ] && return 1 - # Decimal strings of equal length are ordered lexically. - # shellcheck disable=SC2071 - [[ "${a}" > "${b}" ]] -} - -_update_metrics() { - local file="$1" add_logs="$2" add_bytes="$3" prune="$4" - [ -n "${file}" ] || return 0 - local dir base lock fd tmp logs=0 bytes=0 last=0 value new_logs new_bytes - dir="${file%/*}"; [ "${dir}" != "${file}" ] || dir=. - base="${file##*/}" - if [ -z "${base}" ] || [ ! -d "${dir}" ]; then - echo "eb-keep-logs: cannot update metrics file ${file}: invalid path" >&2 - return 0 - fi - lock="${dir}/.${base}.lock" - if [ -L "${lock}" ] || { [ -e "${lock}" ] && [ ! -f "${lock}" ]; } || - ! { exec {fd}>>"${lock}"; } 2>/dev/null || ! flock "${fd}"; then - echo "eb-keep-logs: cannot update metrics file ${file}: cannot lock it" >&2 - return 0 - fi - if [ -e "${file}" ]; then - if [ ! -f "${file}" ] || [ -L "${file}" ]; then - echo "eb-keep-logs: cannot update metrics file ${file}: not a regular file" >&2 - exec {fd}>&- - return 0 - fi - value=$(awk '$1 == "eb_keep_logs_logs_kept_total" { if (++n > 1 || $2 !~ /^[0-9]+$/) exit 2; v=$2 } END { if (n) print v }' "${file}") - if [ "$?" -ne 0 ]; then - echo "eb-keep-logs: cannot update metrics file ${file}: invalid metrics" >&2 - exec {fd}>&- - return 0 - fi - logs=${value:-0} - value=$(awk '$1 == "eb_keep_logs_bytes_kept_total" { if (++n > 1 || $2 !~ /^[0-9]+$/) exit 2; v=$2 } END { if (n) print v }' "${file}") - if [ "$?" -ne 0 ]; then - echo "eb-keep-logs: cannot update metrics file ${file}: invalid metrics" >&2 - exec {fd}>&- - return 0 - fi - bytes=${value:-0} - value=$(awk '$1 == "eb_keep_logs_last_prune_timestamp_seconds" { if (++n > 1 || $2 !~ /^[0-9]+$/) exit 2; v=$2 } END { if (n) print v }' "${file}") - if [ "$?" -ne 0 ]; then - echo "eb-keep-logs: cannot update metrics file ${file}: invalid metrics" >&2 - exec {fd}>&- - return 0 - fi - last=${value:-0} - fi - if ! new_logs=$(_add_u64 "${logs}" "${add_logs}") || - ! new_bytes=$(_add_u64 "${bytes}" "${add_bytes}"); then - echo "eb-keep-logs: cannot update metrics file ${file}: counter overflow" >&2 - exec {fd}>&- - return 0 - fi - logs="${new_logs}" - bytes="${new_bytes}" - # Choose completion time only after taking the metrics lock. Keep a later - # completion already recorded by a concurrent, out-of-order rotation. - if [ "${prune}" = "now" ]; then - if [ -n "${EB_KEEP_LOGS_CLOCK:-}" ]; then - prune=$(tr -d '[:space:]' < "${EB_KEEP_LOGS_CLOCK}") - else - prune=$(date +%s) - fi - fi - if [ -n "${prune}" ] && _u64_gt "${prune}" "${last}"; then - last="${prune}" - fi - tmp=$(mktemp -- "${dir}/.${base}.XXXXXXXX.tmp") || { - echo "eb-keep-logs: cannot update metrics file ${file}: cannot create temporary file" >&2 - exec {fd}>&- - return 0 - } - if ! cat > "${tmp}" <&- - return 0 - fi - if { [ -e "${file}" ] && ! chmod --reference="${file}" -- "${tmp}"; } || - { [ ! -e "${file}" ] && ! chmod 644 "${tmp}"; }; then - echo "eb-keep-logs: cannot update metrics file ${file}: cannot set temporary file mode" >&2 - rm -f -- "${tmp}" - exec {fd}>&- - return 0 - fi - if ! sync -f "${tmp}" || ! mv -f -- "${tmp}" "${file}"; then - echo "eb-keep-logs: cannot update metrics file ${file}: cannot replace it" >&2 - rm -f -- "${tmp}" - elif ! sync -f "${dir}"; then - echo "eb-keep-logs: cannot update metrics file ${file}: cannot sync its directory" >&2 - fi - exec {fd}>&- -} - -cmd_failed() { - local pos=() syslog_opt="" have_syslog=0 metrics_file="" have_metrics=0 - while [ $# -gt 0 ]; do - case "$1" in - --syslog) - [ $# -ge 2 ] || die "--syslog needs a target" - syslog_opt="$2"; have_syslog=1; shift 2 ;; - --syslog=*) - syslog_opt="${1#*=}"; have_syslog=1; shift ;; - --metrics-file) - [ $# -ge 2 ] || die "--metrics-file needs a path" - metrics_file="$2"; have_metrics=1; shift 2 ;; - --metrics-file=*) - metrics_file="${1#*=}"; have_metrics=1; shift ;; - *) pos+=("$1"); shift ;; - esac - done - [ ${#pos[@]} -ge 3 ] || die "failed needs STATUS NAME LOGDIR [TMP_LOGDIR]" - local status="${pos[0]}" name="${pos[1]}" logdir="${pos[2]}" explicit_logdir="${pos[3]:-}" - local src dest - [[ "${status}" =~ ^[0-9]+$ ]] || die "STATUS must be a number, not '${status}'" - [ -d "${logdir}" ] || die "LOGDIR ${logdir} is not a directory" - [ "${have_metrics}" -eq 0 ] || [ -n "${metrics_file}" ] || die "--metrics-file needs a path" - local syslog_target="" - _resolve_syslog_pen - if [ "${have_syslog}" -eq 1 ]; then - _resolve_syslog "${syslog_opt}" - syslog_target="${SYSLOG_TARGET}" - elif [ -n "${EB_KEEP_LOGS_SYSLOG:-}" ]; then - _resolve_syslog "${EB_KEEP_LOGS_SYSLOG}" - syslog_target="${SYSLOG_TARGET}" - fi - logdir=$(_joinable "${logdir}") - if [ "${status}" -eq 0 ]; then - _update_metrics "${metrics_file}" 0 0 "" - return 0 - fi - # The failed lines the kept copies hold are also in the build's own stdout - # log and in the logs EasyBuild writes to TMP_LOGDIR. Close both to others, - # TMP_LOGDIR with the regular files directly in it, not through a symbolic - # link; TMP_LOGDIR only when it lies below LOGDIR, as the documented layout - # puts it. - local stdout_log="${logdir}/${name}.stdout.log" real_logdir real_tmp - if [ -f "${stdout_log}" ] && [ ! -L "${stdout_log}" ]; then - chmod o-rwx "${stdout_log}" - fi - if [ -n "${explicit_logdir}" ] && [ -d "${explicit_logdir}" ] && [ ! -L "${explicit_logdir}" ] && - real_logdir=$(realpath -e "${logdir:-/}") && real_tmp=$(realpath -e "${explicit_logdir}"); then - case "${real_tmp}" in - "${real_logdir%/}"/?*) - chmod o-rwx "${explicit_logdir}" - find "${explicit_logdir}" -mindepth 1 -maxdepth 1 -type f -exec chmod o-rwx {} + - ;; - esac - fi - if ! command -v eb >/dev/null 2>&1; then - echo "No EasyBuild log to keep for ${name}: eb is not on PATH." - _emit_failed_syslog "${syslog_target}" "${status}" "${name}" "${logdir}" 0 0 0 "no-eb" - _update_metrics "${metrics_file}" 0 0 "" - return 0 - fi - local rc=0 - if [ -n "${explicit_logdir}" ]; then - src=$(_last_log --tmp-logdir="${explicit_logdir}") || rc=$? - else - src=$(_last_log) || rc=$? - fi - if [ "${rc}" -ne 0 ]; then - echo "No EasyBuild log to keep for ${name}: eb --last-log exited ${rc}." - _emit_failed_syslog "${syslog_target}" "${status}" "${name}" "${logdir}" 0 0 0 "last-log-failed" - _update_metrics "${metrics_file}" 0 0 "" - return 0 - fi - if [ -z "${src}" ] || [ ! -f "${src}" ]; then - echo "No EasyBuild log to keep for ${name}." - _emit_failed_syslog "${syslog_target}" "${status}" "${name}" "${logdir}" 0 0 0 "no-log" - _update_metrics "${metrics_file}" 0 0 "" - return 0 - fi - # Without TMP_LOGDIR, `eb --last-log` names the newest log in EasyBuild's - # default place, which can be a later build's. Nothing is taken from that - # log; the build's own stdout log still names its failing command. - local foreign="" ebout_kept=0 cmd_kept=0 meson_kept=0 kept_bytes=0 - if [ -z "${explicit_logdir}" ] && grep -q 'processing EasyBuild easyconfig ' "${src}" && - ! grep -qF -- "${name}.eb" "${src}"; then - echo "No EasyBuild log to keep for ${name}: ${src} is another build's log." - foreign=1 - else - dest="${logdir}/${name}.failed.ebout.log" - cp "${src}" "${dest}" - _private "${dest}" "${logdir}" - echo "Failed build log: ${dest}" - ebout_kept=1 - kept_bytes=$(_add_u64 "${kept_bytes}" "$(stat -c %s "${dest}")") - fi - - # The failing command's own output holds the diagnostic beyond EasyBuild's - # printed tail. Only the final command's text streams are kept, and from - # the session log only when that command did not complete successfully; - # only from inside EASYBUILD_TMPDIR and owned by the build account. - local command_output command_root resolved_output stream - command_output="" - if [ -f "${logdir}/${name}.stdout.log" ]; then - command_output=$(grep -oE '/[^[:space:]]*/run-shell-cmd-output/[^/[:space:]]+/out\.txt' "${logdir}/${name}.stdout.log" | tail -n 1) - fi - if [ -z "${command_output}" ] && [ -z "${foreign}" ]; then - command_output=$(_failed_command_output "${src}") - fi - command_root="${command_output%/out.txt}" - if [ -n "${command_output}" ] && [ -z "${EASYBUILD_TMPDIR:-}" ]; then - echo "Failed command output not kept: EASYBUILD_TMPDIR is not set." - elif [ -n "${command_output}" ]; then - # EasyBuild names the streams through EASYBUILD_TMPDIR as it was - # given, so both are compared resolved. - local tmp_real stream_path - tmp_real=$(realpath -e "${EASYBUILD_TMPDIR}" 2>/dev/null) - for stream in out err; do - stream_path="${command_root}/${stream}.txt" - [ ! -L "${stream_path}" ] && [ -f "${stream_path}" ] || continue - resolved_output=$(realpath -e "${stream_path}" 2>/dev/null) || continue - if [ -z "${tmp_real}" ] || [[ "${resolved_output}" != "${tmp_real%/}/"* ]]; then - echo "Failed command output not kept: ${stream_path} is not under EASYBUILD_TMPDIR." - continue - fi - if [ "$(stat -c '%u' "${resolved_output}")" != "$(id -u)" ]; then - echo "Failed command output not kept: ${stream_path} belongs to another user." - continue - fi - dest="${logdir}/${name}.failed.command-${stream}.txt" - cp "${resolved_output}" "${dest}" || continue - chmod 600 "${dest}" - _list "${dest}" "${logdir}" - echo "Failed command output: ${dest}" - cmd_kept=$((cmd_kept + 1)) - kept_bytes=$(_add_u64 "${kept_bytes}" "$(stat -c %s "${dest}")") - done - fi - - if [ -n "${foreign}" ]; then - local reason="other-build" - [ "${cmd_kept}" -gt 0 ] && reason="kept" - _emit_failed_syslog "${syslog_target}" "${status}" "${name}" "${logdir}" 0 "${cmd_kept}" 0 "${reason}" - _update_metrics "${metrics_file}" "${cmd_kept}" "${kept_bytes}" "" - return 0 - fi - # A meson test step prints only the last 100 lines of a failing test; the - # full output is meson-logs/testlog.txt in the build directory. A testlog - # whose tests all passed is not the failure. - local meson_dir testlog - meson_dir=$(tr '\n' ' ' < "${src}" | grep -oP 'meson test -C\s+\K[^[:space:]]+' | tail -n 1) - testlog="${meson_dir}/meson-logs/testlog.txt" - if [ -n "${meson_dir}" ] && [ -f "${testlog}" ] && ! _meson_passed "${testlog}"; then - dest="${logdir}/${name}.failed.meson-testlog.txt" - cp "${testlog}" "${dest}" - _private "${dest}" "${logdir}" - echo "Failed meson test log: ${dest}" - meson_kept=1 - kept_bytes=$(_add_u64 "${kept_bytes}" "$(stat -c %s "${dest}")") - fi - local reason="no-log" - [ $((ebout_kept + cmd_kept + meson_kept)) -gt 0 ] && reason="kept" - _emit_failed_syslog "${syslog_target}" "${status}" "${name}" "${logdir}" "${ebout_kept}" "${cmd_kept}" "${meson_kept}" "${reason}" - _update_metrics "${metrics_file}" "$((ebout_kept + cmd_kept + meson_kept))" "${kept_bytes}" "" - return 0 -} - -# Days since a run directory's name, YYYYMMDD_HHMMSS; empty when the name is -# not a run directory. The name, not the mtime: compressing the run's logs -# moves the mtime of the directory they are in, where a chmod changes only -# the ctime. -_run_age_days() { - local base date now start - base=$(basename "$1") - [[ "${base}" =~ ^([0-9]{8})_[0-9]{6}$ ]] || return 1 - date="${BASH_REMATCH[1]}" - start=$(date -d "${date}" +%s 2>/dev/null) || return 1 - now=${EB_KEEP_LOGS_NOW:-$(date +%s)} - echo $(( (now - start) / 86400 )) -} - -# "/NAME" for each run directly under ROOT that this rotate writes into: the -# run holding its stdout or stderr when either is a file and, as srun passes -# the output on over a pipe, the run holding EB_PIPELINE_LOG_DIR, the log -# directory eb-pipeline exports. Such a run is still going. -_own_runs() { - local root fd - root=$(realpath -e -- "$1") || return 0 - root="${root%/}" - for fd in 1 2; do - [ -f "/proc/$$/fd/${fd}" ] && _run_of "${root}" "$(readlink -e -- "/proc/$$/fd/${fd}")" - done - [ -n "${EB_PIPELINE_LOG_DIR:-}" ] && _run_of "${root}" "$(readlink -e -- "${EB_PIPELINE_LOG_DIR}")" - return 0 -} - -# "/NAME" when PATH lies in NAME directly under ROOT. -_run_of() { - local rest - case "$2" in - "$1/"?*) rest="${2#"$1/"}"; printf '/%s' "${rest%%/*}" ;; - esac -} - -# "/NAME" for each run directly under ROOT that a process has a file in open -# for writing, of the processes whose descriptors this one may read in /proc: -# a build that is still going, whichever run it writes into. A link -# /proc/PID/fd/N has its owner's write bit when N is open for writing; for a -# file removed since, the link names the path it had, with " (deleted)" added. -_written_runs() { - local root target - root=$(realpath -e -- "$1") || return 0 - root="${root%/}" - while IFS= read -r -d '' target; do - _run_of "${root}" "${target}" - done < <(find /proc/[0-9]*/fd -mindepth 1 -maxdepth 1 -type l -perm -u=w -printf '%l\0' 2>/dev/null) - return 0 -} - -# Hold an exclusive flock on the lock file LOCK until this rotate exits, -# waiting up to SECONDS for another holder; exit 75 when it does not let go. -# Opened for reading when it cannot be opened for writing, by a user who may -# not write ROOT. On a file system that cannot lock, rotate without it. -_lock_rotate() { - local lock="$1" seconds="$2" fd rc=0 - if [ -L "${lock}" ] || { [ -e "${lock}" ] && [ ! -f "${lock}" ]; }; then - die "cannot lock ${lock}" - fi - { exec {fd}>>"${lock}"; } 2>/dev/null || { exec {fd}<"${lock}"; } 2>/dev/null || die "cannot lock ${lock}" - flock -w "${seconds}" -E 75 "${fd}" || rc=$? - case "${rc}" in - 0) ;; - 75) echo "eb-keep-logs: another rotate holds the lock ${lock}; gave up after ${seconds} s (--lock-timeout)" >&2 - exit 75 ;; - *) echo "eb-keep-logs: cannot lock ${lock}; rotating without the lock" >&2 ;; - esac -} - -cmd_rotate() { - local root="" compress_after="" delete_after="" lock_timeout="" syslog_opt="" have_syslog=0 dry_run=0 metrics_file="" have_metrics=0 - while [ $# -gt 0 ]; do - case "$1" in - --compress-after) compress_after="${2:-}"; shift 2 ;; - --compress-after=*) compress_after="${1#*=}"; shift ;; - --delete-after) delete_after="${2:-}"; shift 2 ;; - --delete-after=*) delete_after="${1#*=}"; shift ;; - --dry-run) dry_run=1; shift ;; - --lock-timeout) - [ $# -ge 2 ] || die "--lock-timeout needs a number of seconds" - lock_timeout="$2"; shift 2 ;; - --lock-timeout=*) lock_timeout="${1#*=}"; shift ;; - --syslog) - [ $# -ge 2 ] || die "--syslog needs a target" - syslog_opt="$2"; have_syslog=1; shift 2 ;; - --syslog=*) syslog_opt="${1#*=}"; have_syslog=1; shift ;; - --metrics-file) - [ $# -ge 2 ] || die "--metrics-file needs a path" - metrics_file="$2"; have_metrics=1; shift 2 ;; - --metrics-file=*) metrics_file="${1#*=}"; have_metrics=1; shift ;; - -*) die "unknown option $1" ;; - *) [ -z "${root}" ] || die "rotate takes one ROOT"; root="$1"; shift ;; - esac - done - [ -n "${root}" ] || die "rotate needs ROOT" - [ -d "${root}" ] || die "ROOT ${root} is not a directory" - [ "${have_metrics}" -eq 0 ] || [ -n "${metrics_file}" ] || die "--metrics-file needs a path" - [[ "${compress_after}" =~ ^[0-9]+$ ]] || die "--compress-after needs a number of days" - if [ -n "${delete_after}" ]; then - [[ "${delete_after}" =~ ^[0-9]+$ ]] || die "--delete-after needs a number of days" - [ "${delete_after}" -gt "${compress_after}" ] || die "--delete-after must be later than --compress-after" - fi - if [ -n "${lock_timeout}" ]; then - [[ "${lock_timeout}" =~ ^[0-9]+$ ]] || die "--lock-timeout needs a number of seconds" - lock_timeout="${lock_timeout#"${lock_timeout%%[!0]*}"}" - lock_timeout="${lock_timeout:-0}" - # flock(1) cannot set a timer for 10^19 seconds; this is 31 years. - [ "${#lock_timeout}" -le 9 ] || lock_timeout=999999999 - else - lock_timeout=600 - fi - local syslog_target="" - _resolve_syslog_pen - if [ "${have_syslog}" -eq 1 ]; then - _resolve_syslog "${syslog_opt}" - syslog_target="${SYSLOG_TARGET}" - elif [ -n "${EB_KEEP_LOGS_SYSLOG:-}" ]; then - _resolve_syslog "${EB_KEEP_LOGS_SYSLOG}" - syslog_target="${SYSLOG_TARGET}" - fi - [ "${dry_run}" -eq 1 ] || _lock_rotate "$(_joinable "${root}")/.eb-keep-logs-rotate.lock" "${lock_timeout}" - local run age file list tmp path compressed=0 deleted=0 live - live="$(_own_runs "${root}")$(_written_runs "${root}")/" - for run in "$(_joinable "${root}")"/*/; do - run="${run%/}" - [ -d "${run}" ] && [ ! -L "${run}" ] || continue - age=$(_run_age_days "${run}") || continue - # A later rotate takes a run that is still written into, by this - # rotate or by a build that is still going. - case "${live}" in *"/${run##*/}/"*) continue ;; esac - if [ -n "${delete_after}" ] && [ "${age}" -ge "${delete_after}" ]; then - if [ "${dry_run}" -eq 1 ]; then - echo "delete ${run}" - deleted=$((deleted + 1)) - continue - fi - rm -rf -- "${run}" - deleted=$((deleted + 1)) - continue - fi - [ "${age}" -ge "${compress_after}" ] || continue - if [ "${dry_run}" -eq 1 ]; then - while IFS= read -r -d '' file; do - if [ -e "${file}.gz" ] || [ -L "${file}.gz" ]; then continue; fi - if [ "$(stat -c '%h' -- "${file}" 2>/dev/null || echo 2)" -gt 1 ]; then continue; fi - echo "compress $(realpath "${file%/*}")/${file##*/}" - compressed=$((compressed + 1)) - done < <(find "${run}" -type f \( -name '*.log' -o -name '*.txt' \) -print0 | LC_ALL=C sort -z) - continue - fi - while IFS= read -r -d '' file; do - path="$(realpath "${file%/*}")/${file##*/}" - # gzip keeps the file's mode, so a closed log stays closed. - gzip -9 -- "${file}" || continue - compressed=$((compressed + 1)) - # A .licensed-logs in the run names the file by path; follow it. - # The new list is written beside the old one, under a name of its - # own, and renamed over it, so a reader sees one list or the other. - while IFS= read -r -d '' list; do - tmp=$(mktemp -- "${list%/*}/.licensed-logs.XXXXXXXX") || continue - { awk -v p="${path}" '$0 == p { $0 = p ".gz" } { print }' "${list}" > "${tmp}" && - chmod --reference="${list}" -- "${tmp}" && mv -f -- "${tmp}" "${list}"; } || - rm -f -- "${tmp}" - done < <(find "${run}" -name .licensed-logs -type f -print0) - done < <(find "${run}" -type f \( -name '*.log' -o -name '*.txt' \) -print0) - done - local summary - if [ "${dry_run}" -eq 1 ]; then - summary="eb-keep-logs rotate dry-run: $(_count "${compressed}" file) would be compressed, $(_count "${deleted}" run) would be deleted under ${root}" - else - summary="eb-keep-logs rotate: $(_count "${compressed}" file) compressed, $(_count "${deleted}" run) deleted under ${root}" - fi - echo "${summary}" - [ "${dry_run}" -eq 1 ] && return 0 - _emit_syslog "${syslog_target}" 6 "EB_ROTATE_DONE" "${summary}" \ - "P:cmd=rotate" "P:root=${root}" "P:compressed=${compressed}" "P:deleted=${deleted}" \ - "J:EB_KEEP_CMD=rotate" "J:EB_ROTATE_ROOT=${root}" "J:EB_ROTATE_COMPRESSED=${compressed}" "J:EB_ROTATE_DELETED=${deleted}" - _update_metrics "${metrics_file}" 0 0 "now" -} - -case "${1:-}" in - -h|--help) usage ;; - --version) echo "eb-keep-logs ${VERSION}" ;; - failed) shift; cmd_failed "$@" ;; - rotate) shift; cmd_rotate "$@" ;; - why | history | failures | loads | runs | used | usage | pending | test-bundle | test-compare | lifecycle) die "$1 is in the Zig build only" ;; - "") usage; exit 2 ;; - *) die "unknown command '$1' (failed, rotate, why, history, failures, loads, runs, used, usage, pending, test-bundle, test-compare, lifecycle, --help)" ;; -esac diff --git a/src/main.zig b/src/main.zig index 00d9557..0a65cee 100644 --- a/src/main.zig +++ b/src/main.zig @@ -32,8 +32,8 @@ const tool = "eb-keep-logs"; /// build.zig.zon names the same one, and a release changes both. pub const version = "0.3.1"; -/// What `-h`, `--help` and no arguments print. The shell script's `usage` -/// prints the same text: tests/differential.sh compares the two. +/// What `-h`, `--help` and no arguments print: the shell script's text, +/// which tests/test_cases.sh holds the binary to. const usage_text = \\eb-keep-logs: keep the logs of EasyBuild builds that a build pipeline would \\otherwise lose, and keep the pipeline's log tree bounded. @@ -994,8 +994,8 @@ fn parseDays(opt: []const u8, v: ?[]const u8) u64 { const rotate_lock = ".eb-keep-logs-rotate.lock"; /// How long rotate waits for the lock without --lock-timeout, in seconds. const default_lock_timeout: u64 = 600; -/// The longest wait --lock-timeout sets, over 31 years: the shell script's -/// flock(1) cannot set a timer for 10^19 seconds. +/// The longest wait --lock-timeout sets, over 31 years, the bound the shell +/// script had: flock(1) cannot set a timer for 10^19 seconds. const max_lock_timeout: u64 = 999_999_999; /// The exit status when another rotate holds the lock past --lock-timeout, /// EX_TEMPFAIL: run it again later. diff --git a/src/scan.zig b/src/scan.zig index 46cdd36..3b971f2 100644 --- a/src/scan.zig +++ b/src/scan.zig @@ -1,6 +1,6 @@ //! The searches eb-keep-logs runs over a log, written out instead of taken //! from a regular expression engine. Each path search returns the last -//! match, as the shell version's `grep -o ... | tail -n 1` does. +//! match, as `grep -o ... | tail -n 1` would. const std = @import("std"); /// The bytes POSIX [:space:] and PCRE \s match. @@ -132,7 +132,7 @@ pub fn lastMesonDir(text: []const u8, utf8_locale: bool) ?[]const u8 { /// Whether an EasyBuild log is another build's than easyconfig `name`'s: it /// shows EasyBuild processing an easyconfig ("processing EasyBuild /// easyconfig PATH") and never names `name`.eb, which a build's own log does -/// on its command line. As `grep -q` and `grep -qF` in the shell version. +/// on its command line. As `grep -q` and `grep -qF` would. pub fn otherBuild(text: []const u8, name: []const u8) bool { if (std.mem.find(u8, text, "processing EasyBuild easyconfig ") == null) return false; var pos: usize = 0; diff --git a/tests/golden/cases/--help b/tests/golden/cases/--help new file mode 100644 index 0000000..9b2957a --- /dev/null +++ b/tests/golden/cases/--help @@ -0,0 +1,331 @@ +exit 0 +--- stdout +eb-keep-logs: keep the logs of EasyBuild builds that a build pipeline would +otherwise lose, and keep the pipeline's log tree bounded. + + eb-keep-logs failed [--syslog TARGET] [--metrics-file PATH] STATUS NAME LOGDIR [TMP_LOGDIR] + After `eb` returned STATUS for easyconfig NAME: when STATUS is not 0, + copy the EasyBuild session log `eb --last-log` names, the failing + command's output and a meson testlog next to LOGDIR/NAME.stdout.log, + closed to others and listed in LOGDIR/.licensed-logs. TMP_LOGDIR is + the --tmp-logdir eb ran with; without it, the newest log in + EasyBuild's default place is used, unless it is another build's. + NAME.stdout.log and a TMP_LOGDIR below LOGDIR are closed to others too. + --syslog TARGET, --syslog=TARGET + Emit an RFC 5424 or native systemd-journald event when logs are + kept or none are found. Default: EB_KEEP_LOGS_SYSLOG, else none. + --metrics-file PATH, --metrics-file=PATH + Atomically update Prometheus counters for kept logs and bytes. + Default: none. + eb-keep-logs rotate ROOT --compress-after DAYS [--delete-after DAYS] + [--dry-run] [--lock-timeout SECONDS] + [--syslog TARGET] [--metrics-file PATH] + In the run directories directly under ROOT (named YYYYMMDD_HHMMSS), + gzip the *.log and *.txt files of old runs and remove older runs + whole, leaving alone a run that is still written into. A run's age is + in days from the local midnight of the date in its name. Permissions + and .licensed-logs follow. One rotate of ROOT runs at a time, holding + ROOT/.eb-keep-logs-rotate.lock. Options and ROOT come in any order. + --compress-after DAYS, --compress-after=DAYS + Gzip the files of runs at least DAYS old. Required; there is no + default. + --delete-after DAYS, --delete-after=DAYS + Remove whole runs at least DAYS old; DAYS must be larger than + that of --compress-after. Default: none; no run is removed. An + empty value is the default. + --dry-run + Print each file that would be compressed and run that would be + deleted, but change nothing, create no lock, emit no event and + write no metrics. + --lock-timeout SECONDS, --lock-timeout=SECONDS + While another rotate holds the lock, wait up to SECONDS for it, + then give up and exit 75. Default: 600; 0 does not wait. An empty + value is the default. + --syslog TARGET, --syslog=TARGET + Emit an RFC 5424 or native systemd-journald event with the + compressed and deleted counts. Default: EB_KEEP_LOGS_SYSLOG, + else none. + --metrics-file PATH, --metrics-file=PATH + Atomically record when this rotation completed, unless --dry-run + is given. Default: none. + eb-keep-logs why [RUN | --latest] [--target TARGET] [--package PACKAGE] + [--since DATE] [--until DATE] [--root ROOT] [--json] + Say why the builds of a run failed: for each failed easyconfig, its + package and easyconfig, the EasyBuild step it failed in, EasyBuild's + message, and the line of its kept log that shows the error: the first + compiler or linker error, else EasyBuild's own error line, with the + line number and three lines either side. Logs rotate compressed are + read as they are. Zig build only. RUN and the options come in any + order. + RUN + A run directory, as a path or as a name under ROOT. + --latest + The newest run under ROOT, or the newest with a directory + TARGET. The default when no RUN is given. + --target TARGET, --target=TARGET + Only the builds in the run's directory TARGET. Default: those in + the run's own directory and in every directory in it. + --package PACKAGE, --package=PACKAGE + Only builds matching PACKAGE (an easyconfig name without .eb, + a prefix up to a dash, or NAME/VERSION). Default: all builds. + --since DATE, --since=DATE + Only consider runs at or after DATE when picking --latest. + DATE is YYYY-MM-DD, YYYYMMDD, or YYYYMMDD_HHMMSS. + Default: none. + --until DATE, --until=DATE + Only consider runs at or before DATE when picking --latest. + DATE is YYYY-MM-DD, YYYYMMDD, or YYYYMMDD_HHMMSS. + Default: none. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs history PACKAGE [--target TARGET] [--since DATE] + [--until DATE] [--failed] [--root ROOT] [--json] + Say how each kept build of PACKAGE went, oldest run first: success, + failed or unknown, and how long EasyBuild took, from its output. + PACKAGE is an easyconfig's name or its start up to a dash, as hello + or hello-2.12.1 for hello-2.12.1-GCCcore-14.2.0, or a module name, as + hello/2.12.1; hello also takes hello-world-1.0. Zig build only. + PACKAGE and the options come in any order. + --target TARGET, --target=TARGET + Only the builds in each run's directory TARGET. Default: those in + each run's own directory and in every directory in it. + --since DATE, --since=DATE + Only read runs at or after DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --until DATE, --until=DATE + Only read runs at or before DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --failed + Only list failed builds. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs failures [--package PACKAGE] [--target TARGET] + [--since DATE] [--until DATE] [--root ROOT] [--json] + List failed builds across runs under --root, oldest run first. + Each row gives the run, target, failed step, duration and build + name. Zig build only. Options come in any order. + --package PACKAGE, --package=PACKAGE + Only failed builds matching PACKAGE (an easyconfig name + without .eb, a prefix up to a dash, or NAME/VERSION). Default: + all packages. + --target TARGET, --target=TARGET + Only the builds in each run's directory TARGET. Default: those + in each run's own directory and in every directory in it. + --since DATE, --since=DATE + Only read runs at or after DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --until DATE, --until=DATE + Only read runs at or before DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs loads --module NAME [--json] FILE + Print who loaded NAME, from Lmod's ModuleUsageTracking lines in FILE. + Each record is user=USER module=NAME path=PATH host=HOST time=TIME, + in any order, and a syslog prefix is left in place. Each load is + one line, user=USER host=HOST time=TIME path=PATH, in the file's + order. A file with no load of NAME prints no load of NAME. Zig + build only. + --module NAME, --module=NAME + The module's full name, as Lmod recorded it, such as + GROMACS/2024.1. Required. + --json + Print one line of JSON instead, with schema_version 1. + FILE + The log that holds the records. A line that is not one is + skipped. + eb-keep-logs used --prefix PREFIX [--json] [--require-none] FILE... + Print paths under PREFIX that appear in XALT or Lmod records in + FILE. A run record lists userT.exec_path (kind run) and each libA + path under PREFIX (kind run-lib) even when exec_path is outside. + A link record lists resultT.exec_path and each linkA path (kind + link). A package record lists package_path (kind pkg). An Lmod + tracking line lists path when it is under PREFIX (kind module-load). + Each line is path=PATH kind=KIND last=TIME count=N; last is the + newest time seen for that path. With no hit, nothing under PREFIX. + --json prints one JSON document with schema_version 1. --require-none + exits 2 when any hit is listed. Zig build only. + --prefix PREFIX, --prefix=PREFIX + The install tree to check. Required; a newline in it is refused. + --json + Print one line of JSON instead. + --require-none + Exit 2 when any path under PREFIX was found. + FILE + One or more files of concatenated XALT JSON objects and/or Lmod + ModuleUsageTracking lines. Required. + eb-keep-logs usage --software DIR --modules DIR [--since EPOCH] + [--unused | --active] [--json] FILE... + Compare installed DIR/Name/Version software with XALT and Lmod + records. XALT paths below the software directory and Lmod module + loads below the modules directory count as hits. By default, print + every installed Name/Version with its state, hit count and newest + time. --unused and --active print only Name/Version lines; + --active output is accepted by eb-stack stack gap --site. --since + ignores records older than EPOCH and records without a time. + --json prints one JSON document with schema_version 1. Zig build + only. + --software DIR, --software=DIR + The software install tree, with Name/Version directories. + Required. + --modules DIR, --modules=DIR + The module tree that Lmod record paths must be below. Required. + --since EPOCH, --since=EPOCH + Count records at or after this non-negative epoch time. + Default: all record times. + --unused + List installed Name/Version entries with no hit. + --active + List installed Name/Version entries with at least one hit. + --json + Print one line of JSON instead. + FILE + One or more files of concatenated XALT JSON objects and/or Lmod + ModuleUsageTracking lines. Required. + eb-keep-logs runs --exec PATH [--json] FILE + Print who ran PATH, from XALT run records in FILE. A run record is a + JSON object whose userT holds user, exec_path and, when present, + syshost and start_time. A link record is not a run and is skipped. + PATH matches exec_path in full or as its last component. Each run is + one line, user=USER host=HOST time=TIME path=PATH, in the file's + order. A file with no run of PATH prints no run of PATH. Zig build + only. It does not record runs. + --exec PATH, --exec=PATH + The executable, as a full path or its last component. Required. + --json + Print one line of JSON instead, with schema_version 1. + FILE + One or more JSON objects. An object that is not a run record is + skipped. + eb-keep-logs pending [--json] FILE + Print what an EasyBuild dry-run or missing-modules report still has + to build. A dry-run line is "* [ ] PATH (module: NAME)", and [F] and + [R] count as still to build; [x] is already installed and is not + printed. --terse prints "x PATH" or "- PATH". A missing-modules line + is "* NAME (FILE.eb)", or with --terse one easyconfig path on each + line. Each is one line, build NAME or missing NAME, in the file's + order. A report with nothing left prints nothing to build. Zig build + only. It does not run eb, and it does not resolve dependencies. + --json + Print one line of JSON instead, with schema_version 1. + FILE + The report, as eb --dry-run or eb --missing-modules printed it. + Required. + eb-keep-logs test-bundle --test-id ID --suite-revision REV --eessi-target TARGET + ... --stdout FILE --stderr FILE [--input FILE ...] + ... [--module NAME=PATH ...] --seed SEED + ... --allocation TEXT --binding TEXT --cpu TEXT --gpu TEXT + [--out FILE] + Write one flaky-test evidence bundle as JSON schema_version 1, with a + stable test identity (ID), normalized stdout and stderr, input and + seed hashes, full module list and module paths, EESSI target, + scheduler allocation and binding, CPU and GPU facts, and test-suite + revision. Without --out, print it on stdout. Zig build only. + --test-id ID, --test-id=ID + Stable test identity. Required. + --suite-revision REV, --suite-revision=REV + Test-suite revision. Required. + --eessi-target TARGET, --eessi-target=TARGET + EESSI target of the run. Required. + --stdout FILE, --stdout=FILE + Captured stdout, normalized and hashed. Required. + --stderr FILE, --stderr=FILE + Captured stderr, normalized and hashed. Required. + --input FILE, --input=FILE + Input file to hash. Optional; may be repeated. Default: none. + --module NAME=PATH, --module=NAME=PATH + Loaded module and its modulefile path. Optional; may be + repeated. Default: none. + --seed SEED, --seed=SEED + Seed value to hash. Required. + --allocation TEXT, --allocation=TEXT + Scheduler allocation summary. Required. + --binding TEXT, --binding=TEXT + Scheduler binding summary. Required. + --cpu TEXT, --cpu=TEXT + CPU facts. Required. + --gpu TEXT, --gpu=TEXT + GPU facts, or none. Required. + --out FILE, --out=FILE + Write JSON to FILE. Default: stdout. + eb-keep-logs test-compare [--json] BUNDLE... + Summarize which evidence fields differ across two or more + test-bundle JSON files, without deciding pass or fail. --json prints + schema_version 1. Zig build only. + --json + Print one line of JSON instead of text. Default: text. + BUNDLE + Two or more test-bundle JSON files. Required. + eb-keep-logs lifecycle --policy FILE [--modulerc-out FILE] + [--easyconfigs DIR ...] [--easystack FILE ...] + [--eb-stack PATH] [--rebuild-set FILE] + [--now EPOCH] [--json] FILE + Generate a reversible lifecycle plan and Lmod .modulerc.lua + warnings/forbids from usage --json output and a TOML policy. Never + deletes software or modulefiles. Requires a minimum observation + window and checks installed dependents via eb-stack rebuild-set + before allowing candidate-remove. Zig build only. + --policy FILE, --policy=FILE + TOML lifecycle policy file. Required. + --modulerc-out FILE, --modulerc-out=FILE + Write the generated Lmod .modulerc.lua warnings and forbids + durably to FILE. Default: none; no file is written. + --easyconfigs DIR, --easyconfigs=DIR + Easyconfig tree passed to eb-stack rebuild-set to identify + dependents of candidate removals. Repeatable. Default: none. + --easystack FILE, --easystack=FILE + Deployed easystack YAML passed to eb-stack rebuild-set. + Repeatable. Default: none. + --eb-stack PATH, --eb-stack=PATH + Path to the eb-stack executable. Default: eb-stack on PATH. + --rebuild-set FILE, --rebuild-set=FILE + Precomputed eb-stack rebuild-set.json report instead of + running eb-stack. Default: none. + --now EPOCH, --now=EPOCH + Reference epoch time in seconds for idle age and observation + window checks. Default: the environment time override, else + the current time. + --json + Print one line of JSON instead, with schema_version 1. + FILE + JSON output produced by eb-keep-logs usage --json (with + selection "all"). Required. + eb-keep-logs -h | --help + Print this help on stdout and exit 0. + eb-keep-logs --version + Print the version line on stdout and exit 0. + +Environment: + PATH Where failed looks up eb. + EASYBUILD_TMPDIR failed copies a command's output only from below it; + unset or empty, it copies none. + EB_KEEP_LOGS_NOW The time rotate and lifecycle take as now, in seconds + since the epoch; unset or empty, the current time. + EB_PIPELINE_LOG_DIR rotate leaves alone the run that holds this path. + EB_KEEP_LOGS_SYSLOG Default --syslog target (journald, syslog, unix:///..., + journal+unix:///..., udp://host:port, tcp://host:port). + EB_KEEP_LOGS_SYSLOG_PEN + IANA Private Enterprise Number for RFC 5424 SD-ID + ebKeepLogs@. Default: 32473 (RFC 5398 placeholder). + TZ, TZDIR The time zone of the local midnights, and the + directory of zone files. + +Exit status: + 0 -h, --help or --version, or a failed, rotate, why, history, failures, loads, runs, used, usage, pending, test-bundle, test-compare or lifecycle that + accepted its arguments, whatever it could keep, compress, remove or + read: what it could not do is reported on stderr. used with + --require-none also exits 2 when any path was listed. + 2 The invocation was refused, with eb-keep-logs: MESSAGE on stderr; or + no command was given, and this help is on stdout. + 75 rotate waited --lock-timeout seconds for the lock another rotate + held, then gave up and changed nothing; run it again later. +--- stderr diff --git a/tests/golden/cases/-h b/tests/golden/cases/-h new file mode 100644 index 0000000..9b2957a --- /dev/null +++ b/tests/golden/cases/-h @@ -0,0 +1,331 @@ +exit 0 +--- stdout +eb-keep-logs: keep the logs of EasyBuild builds that a build pipeline would +otherwise lose, and keep the pipeline's log tree bounded. + + eb-keep-logs failed [--syslog TARGET] [--metrics-file PATH] STATUS NAME LOGDIR [TMP_LOGDIR] + After `eb` returned STATUS for easyconfig NAME: when STATUS is not 0, + copy the EasyBuild session log `eb --last-log` names, the failing + command's output and a meson testlog next to LOGDIR/NAME.stdout.log, + closed to others and listed in LOGDIR/.licensed-logs. TMP_LOGDIR is + the --tmp-logdir eb ran with; without it, the newest log in + EasyBuild's default place is used, unless it is another build's. + NAME.stdout.log and a TMP_LOGDIR below LOGDIR are closed to others too. + --syslog TARGET, --syslog=TARGET + Emit an RFC 5424 or native systemd-journald event when logs are + kept or none are found. Default: EB_KEEP_LOGS_SYSLOG, else none. + --metrics-file PATH, --metrics-file=PATH + Atomically update Prometheus counters for kept logs and bytes. + Default: none. + eb-keep-logs rotate ROOT --compress-after DAYS [--delete-after DAYS] + [--dry-run] [--lock-timeout SECONDS] + [--syslog TARGET] [--metrics-file PATH] + In the run directories directly under ROOT (named YYYYMMDD_HHMMSS), + gzip the *.log and *.txt files of old runs and remove older runs + whole, leaving alone a run that is still written into. A run's age is + in days from the local midnight of the date in its name. Permissions + and .licensed-logs follow. One rotate of ROOT runs at a time, holding + ROOT/.eb-keep-logs-rotate.lock. Options and ROOT come in any order. + --compress-after DAYS, --compress-after=DAYS + Gzip the files of runs at least DAYS old. Required; there is no + default. + --delete-after DAYS, --delete-after=DAYS + Remove whole runs at least DAYS old; DAYS must be larger than + that of --compress-after. Default: none; no run is removed. An + empty value is the default. + --dry-run + Print each file that would be compressed and run that would be + deleted, but change nothing, create no lock, emit no event and + write no metrics. + --lock-timeout SECONDS, --lock-timeout=SECONDS + While another rotate holds the lock, wait up to SECONDS for it, + then give up and exit 75. Default: 600; 0 does not wait. An empty + value is the default. + --syslog TARGET, --syslog=TARGET + Emit an RFC 5424 or native systemd-journald event with the + compressed and deleted counts. Default: EB_KEEP_LOGS_SYSLOG, + else none. + --metrics-file PATH, --metrics-file=PATH + Atomically record when this rotation completed, unless --dry-run + is given. Default: none. + eb-keep-logs why [RUN | --latest] [--target TARGET] [--package PACKAGE] + [--since DATE] [--until DATE] [--root ROOT] [--json] + Say why the builds of a run failed: for each failed easyconfig, its + package and easyconfig, the EasyBuild step it failed in, EasyBuild's + message, and the line of its kept log that shows the error: the first + compiler or linker error, else EasyBuild's own error line, with the + line number and three lines either side. Logs rotate compressed are + read as they are. Zig build only. RUN and the options come in any + order. + RUN + A run directory, as a path or as a name under ROOT. + --latest + The newest run under ROOT, or the newest with a directory + TARGET. The default when no RUN is given. + --target TARGET, --target=TARGET + Only the builds in the run's directory TARGET. Default: those in + the run's own directory and in every directory in it. + --package PACKAGE, --package=PACKAGE + Only builds matching PACKAGE (an easyconfig name without .eb, + a prefix up to a dash, or NAME/VERSION). Default: all builds. + --since DATE, --since=DATE + Only consider runs at or after DATE when picking --latest. + DATE is YYYY-MM-DD, YYYYMMDD, or YYYYMMDD_HHMMSS. + Default: none. + --until DATE, --until=DATE + Only consider runs at or before DATE when picking --latest. + DATE is YYYY-MM-DD, YYYYMMDD, or YYYYMMDD_HHMMSS. + Default: none. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs history PACKAGE [--target TARGET] [--since DATE] + [--until DATE] [--failed] [--root ROOT] [--json] + Say how each kept build of PACKAGE went, oldest run first: success, + failed or unknown, and how long EasyBuild took, from its output. + PACKAGE is an easyconfig's name or its start up to a dash, as hello + or hello-2.12.1 for hello-2.12.1-GCCcore-14.2.0, or a module name, as + hello/2.12.1; hello also takes hello-world-1.0. Zig build only. + PACKAGE and the options come in any order. + --target TARGET, --target=TARGET + Only the builds in each run's directory TARGET. Default: those in + each run's own directory and in every directory in it. + --since DATE, --since=DATE + Only read runs at or after DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --until DATE, --until=DATE + Only read runs at or before DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --failed + Only list failed builds. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs failures [--package PACKAGE] [--target TARGET] + [--since DATE] [--until DATE] [--root ROOT] [--json] + List failed builds across runs under --root, oldest run first. + Each row gives the run, target, failed step, duration and build + name. Zig build only. Options come in any order. + --package PACKAGE, --package=PACKAGE + Only failed builds matching PACKAGE (an easyconfig name + without .eb, a prefix up to a dash, or NAME/VERSION). Default: + all packages. + --target TARGET, --target=TARGET + Only the builds in each run's directory TARGET. Default: those + in each run's own directory and in every directory in it. + --since DATE, --since=DATE + Only read runs at or after DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --until DATE, --until=DATE + Only read runs at or before DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs loads --module NAME [--json] FILE + Print who loaded NAME, from Lmod's ModuleUsageTracking lines in FILE. + Each record is user=USER module=NAME path=PATH host=HOST time=TIME, + in any order, and a syslog prefix is left in place. Each load is + one line, user=USER host=HOST time=TIME path=PATH, in the file's + order. A file with no load of NAME prints no load of NAME. Zig + build only. + --module NAME, --module=NAME + The module's full name, as Lmod recorded it, such as + GROMACS/2024.1. Required. + --json + Print one line of JSON instead, with schema_version 1. + FILE + The log that holds the records. A line that is not one is + skipped. + eb-keep-logs used --prefix PREFIX [--json] [--require-none] FILE... + Print paths under PREFIX that appear in XALT or Lmod records in + FILE. A run record lists userT.exec_path (kind run) and each libA + path under PREFIX (kind run-lib) even when exec_path is outside. + A link record lists resultT.exec_path and each linkA path (kind + link). A package record lists package_path (kind pkg). An Lmod + tracking line lists path when it is under PREFIX (kind module-load). + Each line is path=PATH kind=KIND last=TIME count=N; last is the + newest time seen for that path. With no hit, nothing under PREFIX. + --json prints one JSON document with schema_version 1. --require-none + exits 2 when any hit is listed. Zig build only. + --prefix PREFIX, --prefix=PREFIX + The install tree to check. Required; a newline in it is refused. + --json + Print one line of JSON instead. + --require-none + Exit 2 when any path under PREFIX was found. + FILE + One or more files of concatenated XALT JSON objects and/or Lmod + ModuleUsageTracking lines. Required. + eb-keep-logs usage --software DIR --modules DIR [--since EPOCH] + [--unused | --active] [--json] FILE... + Compare installed DIR/Name/Version software with XALT and Lmod + records. XALT paths below the software directory and Lmod module + loads below the modules directory count as hits. By default, print + every installed Name/Version with its state, hit count and newest + time. --unused and --active print only Name/Version lines; + --active output is accepted by eb-stack stack gap --site. --since + ignores records older than EPOCH and records without a time. + --json prints one JSON document with schema_version 1. Zig build + only. + --software DIR, --software=DIR + The software install tree, with Name/Version directories. + Required. + --modules DIR, --modules=DIR + The module tree that Lmod record paths must be below. Required. + --since EPOCH, --since=EPOCH + Count records at or after this non-negative epoch time. + Default: all record times. + --unused + List installed Name/Version entries with no hit. + --active + List installed Name/Version entries with at least one hit. + --json + Print one line of JSON instead. + FILE + One or more files of concatenated XALT JSON objects and/or Lmod + ModuleUsageTracking lines. Required. + eb-keep-logs runs --exec PATH [--json] FILE + Print who ran PATH, from XALT run records in FILE. A run record is a + JSON object whose userT holds user, exec_path and, when present, + syshost and start_time. A link record is not a run and is skipped. + PATH matches exec_path in full or as its last component. Each run is + one line, user=USER host=HOST time=TIME path=PATH, in the file's + order. A file with no run of PATH prints no run of PATH. Zig build + only. It does not record runs. + --exec PATH, --exec=PATH + The executable, as a full path or its last component. Required. + --json + Print one line of JSON instead, with schema_version 1. + FILE + One or more JSON objects. An object that is not a run record is + skipped. + eb-keep-logs pending [--json] FILE + Print what an EasyBuild dry-run or missing-modules report still has + to build. A dry-run line is "* [ ] PATH (module: NAME)", and [F] and + [R] count as still to build; [x] is already installed and is not + printed. --terse prints "x PATH" or "- PATH". A missing-modules line + is "* NAME (FILE.eb)", or with --terse one easyconfig path on each + line. Each is one line, build NAME or missing NAME, in the file's + order. A report with nothing left prints nothing to build. Zig build + only. It does not run eb, and it does not resolve dependencies. + --json + Print one line of JSON instead, with schema_version 1. + FILE + The report, as eb --dry-run or eb --missing-modules printed it. + Required. + eb-keep-logs test-bundle --test-id ID --suite-revision REV --eessi-target TARGET + ... --stdout FILE --stderr FILE [--input FILE ...] + ... [--module NAME=PATH ...] --seed SEED + ... --allocation TEXT --binding TEXT --cpu TEXT --gpu TEXT + [--out FILE] + Write one flaky-test evidence bundle as JSON schema_version 1, with a + stable test identity (ID), normalized stdout and stderr, input and + seed hashes, full module list and module paths, EESSI target, + scheduler allocation and binding, CPU and GPU facts, and test-suite + revision. Without --out, print it on stdout. Zig build only. + --test-id ID, --test-id=ID + Stable test identity. Required. + --suite-revision REV, --suite-revision=REV + Test-suite revision. Required. + --eessi-target TARGET, --eessi-target=TARGET + EESSI target of the run. Required. + --stdout FILE, --stdout=FILE + Captured stdout, normalized and hashed. Required. + --stderr FILE, --stderr=FILE + Captured stderr, normalized and hashed. Required. + --input FILE, --input=FILE + Input file to hash. Optional; may be repeated. Default: none. + --module NAME=PATH, --module=NAME=PATH + Loaded module and its modulefile path. Optional; may be + repeated. Default: none. + --seed SEED, --seed=SEED + Seed value to hash. Required. + --allocation TEXT, --allocation=TEXT + Scheduler allocation summary. Required. + --binding TEXT, --binding=TEXT + Scheduler binding summary. Required. + --cpu TEXT, --cpu=TEXT + CPU facts. Required. + --gpu TEXT, --gpu=TEXT + GPU facts, or none. Required. + --out FILE, --out=FILE + Write JSON to FILE. Default: stdout. + eb-keep-logs test-compare [--json] BUNDLE... + Summarize which evidence fields differ across two or more + test-bundle JSON files, without deciding pass or fail. --json prints + schema_version 1. Zig build only. + --json + Print one line of JSON instead of text. Default: text. + BUNDLE + Two or more test-bundle JSON files. Required. + eb-keep-logs lifecycle --policy FILE [--modulerc-out FILE] + [--easyconfigs DIR ...] [--easystack FILE ...] + [--eb-stack PATH] [--rebuild-set FILE] + [--now EPOCH] [--json] FILE + Generate a reversible lifecycle plan and Lmod .modulerc.lua + warnings/forbids from usage --json output and a TOML policy. Never + deletes software or modulefiles. Requires a minimum observation + window and checks installed dependents via eb-stack rebuild-set + before allowing candidate-remove. Zig build only. + --policy FILE, --policy=FILE + TOML lifecycle policy file. Required. + --modulerc-out FILE, --modulerc-out=FILE + Write the generated Lmod .modulerc.lua warnings and forbids + durably to FILE. Default: none; no file is written. + --easyconfigs DIR, --easyconfigs=DIR + Easyconfig tree passed to eb-stack rebuild-set to identify + dependents of candidate removals. Repeatable. Default: none. + --easystack FILE, --easystack=FILE + Deployed easystack YAML passed to eb-stack rebuild-set. + Repeatable. Default: none. + --eb-stack PATH, --eb-stack=PATH + Path to the eb-stack executable. Default: eb-stack on PATH. + --rebuild-set FILE, --rebuild-set=FILE + Precomputed eb-stack rebuild-set.json report instead of + running eb-stack. Default: none. + --now EPOCH, --now=EPOCH + Reference epoch time in seconds for idle age and observation + window checks. Default: the environment time override, else + the current time. + --json + Print one line of JSON instead, with schema_version 1. + FILE + JSON output produced by eb-keep-logs usage --json (with + selection "all"). Required. + eb-keep-logs -h | --help + Print this help on stdout and exit 0. + eb-keep-logs --version + Print the version line on stdout and exit 0. + +Environment: + PATH Where failed looks up eb. + EASYBUILD_TMPDIR failed copies a command's output only from below it; + unset or empty, it copies none. + EB_KEEP_LOGS_NOW The time rotate and lifecycle take as now, in seconds + since the epoch; unset or empty, the current time. + EB_PIPELINE_LOG_DIR rotate leaves alone the run that holds this path. + EB_KEEP_LOGS_SYSLOG Default --syslog target (journald, syslog, unix:///..., + journal+unix:///..., udp://host:port, tcp://host:port). + EB_KEEP_LOGS_SYSLOG_PEN + IANA Private Enterprise Number for RFC 5424 SD-ID + ebKeepLogs@. Default: 32473 (RFC 5398 placeholder). + TZ, TZDIR The time zone of the local midnights, and the + directory of zone files. + +Exit status: + 0 -h, --help or --version, or a failed, rotate, why, history, failures, loads, runs, used, usage, pending, test-bundle, test-compare or lifecycle that + accepted its arguments, whatever it could keep, compress, remove or + read: what it could not do is reported on stderr. used with + --require-none also exits 2 when any path was listed. + 2 The invocation was refused, with eb-keep-logs: MESSAGE on stderr; or + no command was given, and this help is on stdout. + 75 rotate waited --lock-timeout seconds for the lock another rotate + held, then gave up and changed nothing; run it again later. +--- stderr diff --git a/tests/golden/cases/failed__EASYBUILD_TMPDIR_unset b/tests/golden/cases/failed__EASYBUILD_TMPDIR_unset new file mode 100644 index 0000000..ae935e9 --- /dev/null +++ b/tests/golden/cases/failed__EASYBUILD_TMPDIR_unset @@ -0,0 +1,5 @@ +exit 0 +--- stdout +Failed build log: @WORK@/logs/Cmd.failed.ebout.log +Failed command output not kept: EASYBUILD_TMPDIR is not set. +--- stderr diff --git a/tests/golden/cases/failed__LOGDIR_with_trailing_slashes b/tests/golden/cases/failed__LOGDIR_with_trailing_slashes new file mode 100644 index 0000000..e462fcf --- /dev/null +++ b/tests/golden/cases/failed__LOGDIR_with_trailing_slashes @@ -0,0 +1,4 @@ +exit 0 +--- stdout +Failed build log: @WORK@/logs/Slash.failed.ebout.log +--- stderr diff --git a/tests/golden/cases/failed__another_build_s_log b/tests/golden/cases/failed__another_build_s_log new file mode 100644 index 0000000..813880c --- /dev/null +++ b/tests/golden/cases/failed__another_build_s_log @@ -0,0 +1,4 @@ +exit 0 +--- stdout +No EasyBuild log to keep for Calc-1.0: @WORK@/easybuild-ring.log is another build's log. +--- stderr diff --git a/tests/golden/cases/failed__bad_status b/tests/golden/cases/failed__bad_status new file mode 100644 index 0000000..cb05f61 --- /dev/null +++ b/tests/golden/cases/failed__bad_status @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: STATUS must be a number, not 'x' diff --git a/tests/golden/cases/failed__bad_syslog_pen b/tests/golden/cases/failed__bad_syslog_pen new file mode 100644 index 0000000..647a32b --- /dev/null +++ b/tests/golden/cases/failed__bad_syslog_pen @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: EB_KEEP_LOGS_SYSLOG_PEN must be a positive integer, not '0' diff --git a/tests/golden/cases/failed__bad_syslog_target b/tests/golden/cases/failed__bad_syslog_target new file mode 100644 index 0000000..9afac6e --- /dev/null +++ b/tests/golden/cases/failed__bad_syslog_target @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: invalid syslog target 'bogus://x' diff --git a/tests/golden/cases/failed__eb_--last-log_fails b/tests/golden/cases/failed__eb_--last-log_fails new file mode 100644 index 0000000..6ef2278 --- /dev/null +++ b/tests/golden/cases/failed__eb_--last-log_fails @@ -0,0 +1,4 @@ +exit 0 +--- stdout +No EasyBuild log to keep for Foo: eb --last-log exited 4. +--- stderr diff --git a/tests/golden/cases/failed__empty_tmp_logdir b/tests/golden/cases/failed__empty_tmp_logdir new file mode 100644 index 0000000..8a1ccb6 --- /dev/null +++ b/tests/golden/cases/failed__empty_tmp_logdir @@ -0,0 +1,4 @@ +exit 0 +--- stdout +No EasyBuild log to keep for Foo. +--- stderr diff --git a/tests/golden/cases/failed__failing_meson_test b/tests/golden/cases/failed__failing_meson_test new file mode 100644 index 0000000..ed63fc1 --- /dev/null +++ b/tests/golden/cases/failed__failing_meson_test @@ -0,0 +1,6 @@ +exit 0 +--- stdout +Failed build log: @WORK@/logs/Tests.failed.ebout.log +Failed command output: @WORK@/logs/Tests.failed.command-out.txt +Failed meson test log: @WORK@/logs/Tests.failed.meson-testlog.txt +--- stderr diff --git a/tests/golden/cases/failed__linked_EASYBUILD_TMPDIR b/tests/golden/cases/failed__linked_EASYBUILD_TMPDIR new file mode 100644 index 0000000..855f2d8 --- /dev/null +++ b/tests/golden/cases/failed__linked_EASYBUILD_TMPDIR @@ -0,0 +1,5 @@ +exit 0 +--- stdout +Failed build log: @WORK@/logs/Cmd.failed.ebout.log +Failed command output: @WORK@/logs/Cmd.failed.command-out.txt +--- stderr diff --git a/tests/golden/cases/failed__missing_logdir b/tests/golden/cases/failed__missing_logdir new file mode 100644 index 0000000..d6bff95 --- /dev/null +++ b/tests/golden/cases/failed__missing_logdir @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: LOGDIR @WORK@/nope is not a directory diff --git a/tests/golden/cases/failed__no_eb_log b/tests/golden/cases/failed__no_eb_log new file mode 100644 index 0000000..8a1ccb6 --- /dev/null +++ b/tests/golden/cases/failed__no_eb_log @@ -0,0 +1,4 @@ +exit 0 +--- stdout +No EasyBuild log to keep for Foo. +--- stderr diff --git a/tests/golden/cases/failed__no_eb_on_PATH b/tests/golden/cases/failed__no_eb_on_PATH new file mode 100644 index 0000000..2a5c566 --- /dev/null +++ b/tests/golden/cases/failed__no_eb_on_PATH @@ -0,0 +1,4 @@ +exit 0 +--- stdout +No EasyBuild log to keep for Foo: eb is not on PATH. +--- stderr diff --git a/tests/golden/cases/failed__output_outside_EASYBUILD_TMPDIR b/tests/golden/cases/failed__output_outside_EASYBUILD_TMPDIR new file mode 100644 index 0000000..0df9dcb --- /dev/null +++ b/tests/golden/cases/failed__output_outside_EASYBUILD_TMPDIR @@ -0,0 +1,5 @@ +exit 0 +--- stdout +Failed build log: @WORK@/logs/Cmd.failed.ebout.log +Failed command output not kept: @WORK@/ebtmp-link/eb-1/run-shell-cmd-output/make-1/out.txt is not under EASYBUILD_TMPDIR. +--- stderr diff --git a/tests/golden/cases/failed__own_log b/tests/golden/cases/failed__own_log new file mode 100644 index 0000000..d11e47c --- /dev/null +++ b/tests/golden/cases/failed__own_log @@ -0,0 +1,4 @@ +exit 0 +--- stdout +Failed build log: @WORK@/logs/Ring-1.0.failed.ebout.log +--- stderr diff --git a/tests/golden/cases/failed__sanity_check_after_passing_tests b/tests/golden/cases/failed__sanity_check_after_passing_tests new file mode 100644 index 0000000..87adbae --- /dev/null +++ b/tests/golden/cases/failed__sanity_check_after_passing_tests @@ -0,0 +1,4 @@ +exit 0 +--- stdout +Failed build log: @WORK@/logs/Sanity.failed.ebout.log +--- stderr diff --git a/tests/golden/cases/failed__success b/tests/golden/cases/failed__success new file mode 100644 index 0000000..3fab7b2 --- /dev/null +++ b/tests/golden/cases/failed__success @@ -0,0 +1,3 @@ +exit 0 +--- stdout +--- stderr diff --git a/tests/golden/cases/failed__too_few b/tests/golden/cases/failed__too_few new file mode 100644 index 0000000..2f268ad --- /dev/null +++ b/tests/golden/cases/failed__too_few @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: failed needs STATUS NAME LOGDIR [TMP_LOGDIR] diff --git a/tests/golden/cases/failed__wrapped_last-log b/tests/golden/cases/failed__wrapped_last-log new file mode 100644 index 0000000..693ca07 --- /dev/null +++ b/tests/golden/cases/failed__wrapped_last-log @@ -0,0 +1,4 @@ +exit 0 +--- stdout +Failed build log: @WORK@/logs/Foo.failed.ebout.log +--- stderr diff --git a/tests/golden/cases/failed__zeros_are_success b/tests/golden/cases/failed__zeros_are_success new file mode 100644 index 0000000..3fab7b2 --- /dev/null +++ b/tests/golden/cases/failed__zeros_are_success @@ -0,0 +1,3 @@ +exit 0 +--- stdout +--- stderr diff --git a/tests/golden/cases/no_arguments b/tests/golden/cases/no_arguments new file mode 100644 index 0000000..9732274 --- /dev/null +++ b/tests/golden/cases/no_arguments @@ -0,0 +1,331 @@ +exit 2 +--- stdout +eb-keep-logs: keep the logs of EasyBuild builds that a build pipeline would +otherwise lose, and keep the pipeline's log tree bounded. + + eb-keep-logs failed [--syslog TARGET] [--metrics-file PATH] STATUS NAME LOGDIR [TMP_LOGDIR] + After `eb` returned STATUS for easyconfig NAME: when STATUS is not 0, + copy the EasyBuild session log `eb --last-log` names, the failing + command's output and a meson testlog next to LOGDIR/NAME.stdout.log, + closed to others and listed in LOGDIR/.licensed-logs. TMP_LOGDIR is + the --tmp-logdir eb ran with; without it, the newest log in + EasyBuild's default place is used, unless it is another build's. + NAME.stdout.log and a TMP_LOGDIR below LOGDIR are closed to others too. + --syslog TARGET, --syslog=TARGET + Emit an RFC 5424 or native systemd-journald event when logs are + kept or none are found. Default: EB_KEEP_LOGS_SYSLOG, else none. + --metrics-file PATH, --metrics-file=PATH + Atomically update Prometheus counters for kept logs and bytes. + Default: none. + eb-keep-logs rotate ROOT --compress-after DAYS [--delete-after DAYS] + [--dry-run] [--lock-timeout SECONDS] + [--syslog TARGET] [--metrics-file PATH] + In the run directories directly under ROOT (named YYYYMMDD_HHMMSS), + gzip the *.log and *.txt files of old runs and remove older runs + whole, leaving alone a run that is still written into. A run's age is + in days from the local midnight of the date in its name. Permissions + and .licensed-logs follow. One rotate of ROOT runs at a time, holding + ROOT/.eb-keep-logs-rotate.lock. Options and ROOT come in any order. + --compress-after DAYS, --compress-after=DAYS + Gzip the files of runs at least DAYS old. Required; there is no + default. + --delete-after DAYS, --delete-after=DAYS + Remove whole runs at least DAYS old; DAYS must be larger than + that of --compress-after. Default: none; no run is removed. An + empty value is the default. + --dry-run + Print each file that would be compressed and run that would be + deleted, but change nothing, create no lock, emit no event and + write no metrics. + --lock-timeout SECONDS, --lock-timeout=SECONDS + While another rotate holds the lock, wait up to SECONDS for it, + then give up and exit 75. Default: 600; 0 does not wait. An empty + value is the default. + --syslog TARGET, --syslog=TARGET + Emit an RFC 5424 or native systemd-journald event with the + compressed and deleted counts. Default: EB_KEEP_LOGS_SYSLOG, + else none. + --metrics-file PATH, --metrics-file=PATH + Atomically record when this rotation completed, unless --dry-run + is given. Default: none. + eb-keep-logs why [RUN | --latest] [--target TARGET] [--package PACKAGE] + [--since DATE] [--until DATE] [--root ROOT] [--json] + Say why the builds of a run failed: for each failed easyconfig, its + package and easyconfig, the EasyBuild step it failed in, EasyBuild's + message, and the line of its kept log that shows the error: the first + compiler or linker error, else EasyBuild's own error line, with the + line number and three lines either side. Logs rotate compressed are + read as they are. Zig build only. RUN and the options come in any + order. + RUN + A run directory, as a path or as a name under ROOT. + --latest + The newest run under ROOT, or the newest with a directory + TARGET. The default when no RUN is given. + --target TARGET, --target=TARGET + Only the builds in the run's directory TARGET. Default: those in + the run's own directory and in every directory in it. + --package PACKAGE, --package=PACKAGE + Only builds matching PACKAGE (an easyconfig name without .eb, + a prefix up to a dash, or NAME/VERSION). Default: all builds. + --since DATE, --since=DATE + Only consider runs at or after DATE when picking --latest. + DATE is YYYY-MM-DD, YYYYMMDD, or YYYYMMDD_HHMMSS. + Default: none. + --until DATE, --until=DATE + Only consider runs at or before DATE when picking --latest. + DATE is YYYY-MM-DD, YYYYMMDD, or YYYYMMDD_HHMMSS. + Default: none. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs history PACKAGE [--target TARGET] [--since DATE] + [--until DATE] [--failed] [--root ROOT] [--json] + Say how each kept build of PACKAGE went, oldest run first: success, + failed or unknown, and how long EasyBuild took, from its output. + PACKAGE is an easyconfig's name or its start up to a dash, as hello + or hello-2.12.1 for hello-2.12.1-GCCcore-14.2.0, or a module name, as + hello/2.12.1; hello also takes hello-world-1.0. Zig build only. + PACKAGE and the options come in any order. + --target TARGET, --target=TARGET + Only the builds in each run's directory TARGET. Default: those in + each run's own directory and in every directory in it. + --since DATE, --since=DATE + Only read runs at or after DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --until DATE, --until=DATE + Only read runs at or before DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --failed + Only list failed builds. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs failures [--package PACKAGE] [--target TARGET] + [--since DATE] [--until DATE] [--root ROOT] [--json] + List failed builds across runs under --root, oldest run first. + Each row gives the run, target, failed step, duration and build + name. Zig build only. Options come in any order. + --package PACKAGE, --package=PACKAGE + Only failed builds matching PACKAGE (an easyconfig name + without .eb, a prefix up to a dash, or NAME/VERSION). Default: + all packages. + --target TARGET, --target=TARGET + Only the builds in each run's directory TARGET. Default: those + in each run's own directory and in every directory in it. + --since DATE, --since=DATE + Only read runs at or after DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --until DATE, --until=DATE + Only read runs at or before DATE (YYYY-MM-DD, YYYYMMDD, or + YYYYMMDD_HHMMSS). Default: none. + --root ROOT, --root=ROOT + The directory that holds the runs. Default: the current + directory. + --json + Print one line of JSON instead, with schema_version 1. + eb-keep-logs loads --module NAME [--json] FILE + Print who loaded NAME, from Lmod's ModuleUsageTracking lines in FILE. + Each record is user=USER module=NAME path=PATH host=HOST time=TIME, + in any order, and a syslog prefix is left in place. Each load is + one line, user=USER host=HOST time=TIME path=PATH, in the file's + order. A file with no load of NAME prints no load of NAME. Zig + build only. + --module NAME, --module=NAME + The module's full name, as Lmod recorded it, such as + GROMACS/2024.1. Required. + --json + Print one line of JSON instead, with schema_version 1. + FILE + The log that holds the records. A line that is not one is + skipped. + eb-keep-logs used --prefix PREFIX [--json] [--require-none] FILE... + Print paths under PREFIX that appear in XALT or Lmod records in + FILE. A run record lists userT.exec_path (kind run) and each libA + path under PREFIX (kind run-lib) even when exec_path is outside. + A link record lists resultT.exec_path and each linkA path (kind + link). A package record lists package_path (kind pkg). An Lmod + tracking line lists path when it is under PREFIX (kind module-load). + Each line is path=PATH kind=KIND last=TIME count=N; last is the + newest time seen for that path. With no hit, nothing under PREFIX. + --json prints one JSON document with schema_version 1. --require-none + exits 2 when any hit is listed. Zig build only. + --prefix PREFIX, --prefix=PREFIX + The install tree to check. Required; a newline in it is refused. + --json + Print one line of JSON instead. + --require-none + Exit 2 when any path under PREFIX was found. + FILE + One or more files of concatenated XALT JSON objects and/or Lmod + ModuleUsageTracking lines. Required. + eb-keep-logs usage --software DIR --modules DIR [--since EPOCH] + [--unused | --active] [--json] FILE... + Compare installed DIR/Name/Version software with XALT and Lmod + records. XALT paths below the software directory and Lmod module + loads below the modules directory count as hits. By default, print + every installed Name/Version with its state, hit count and newest + time. --unused and --active print only Name/Version lines; + --active output is accepted by eb-stack stack gap --site. --since + ignores records older than EPOCH and records without a time. + --json prints one JSON document with schema_version 1. Zig build + only. + --software DIR, --software=DIR + The software install tree, with Name/Version directories. + Required. + --modules DIR, --modules=DIR + The module tree that Lmod record paths must be below. Required. + --since EPOCH, --since=EPOCH + Count records at or after this non-negative epoch time. + Default: all record times. + --unused + List installed Name/Version entries with no hit. + --active + List installed Name/Version entries with at least one hit. + --json + Print one line of JSON instead. + FILE + One or more files of concatenated XALT JSON objects and/or Lmod + ModuleUsageTracking lines. Required. + eb-keep-logs runs --exec PATH [--json] FILE + Print who ran PATH, from XALT run records in FILE. A run record is a + JSON object whose userT holds user, exec_path and, when present, + syshost and start_time. A link record is not a run and is skipped. + PATH matches exec_path in full or as its last component. Each run is + one line, user=USER host=HOST time=TIME path=PATH, in the file's + order. A file with no run of PATH prints no run of PATH. Zig build + only. It does not record runs. + --exec PATH, --exec=PATH + The executable, as a full path or its last component. Required. + --json + Print one line of JSON instead, with schema_version 1. + FILE + One or more JSON objects. An object that is not a run record is + skipped. + eb-keep-logs pending [--json] FILE + Print what an EasyBuild dry-run or missing-modules report still has + to build. A dry-run line is "* [ ] PATH (module: NAME)", and [F] and + [R] count as still to build; [x] is already installed and is not + printed. --terse prints "x PATH" or "- PATH". A missing-modules line + is "* NAME (FILE.eb)", or with --terse one easyconfig path on each + line. Each is one line, build NAME or missing NAME, in the file's + order. A report with nothing left prints nothing to build. Zig build + only. It does not run eb, and it does not resolve dependencies. + --json + Print one line of JSON instead, with schema_version 1. + FILE + The report, as eb --dry-run or eb --missing-modules printed it. + Required. + eb-keep-logs test-bundle --test-id ID --suite-revision REV --eessi-target TARGET + ... --stdout FILE --stderr FILE [--input FILE ...] + ... [--module NAME=PATH ...] --seed SEED + ... --allocation TEXT --binding TEXT --cpu TEXT --gpu TEXT + [--out FILE] + Write one flaky-test evidence bundle as JSON schema_version 1, with a + stable test identity (ID), normalized stdout and stderr, input and + seed hashes, full module list and module paths, EESSI target, + scheduler allocation and binding, CPU and GPU facts, and test-suite + revision. Without --out, print it on stdout. Zig build only. + --test-id ID, --test-id=ID + Stable test identity. Required. + --suite-revision REV, --suite-revision=REV + Test-suite revision. Required. + --eessi-target TARGET, --eessi-target=TARGET + EESSI target of the run. Required. + --stdout FILE, --stdout=FILE + Captured stdout, normalized and hashed. Required. + --stderr FILE, --stderr=FILE + Captured stderr, normalized and hashed. Required. + --input FILE, --input=FILE + Input file to hash. Optional; may be repeated. Default: none. + --module NAME=PATH, --module=NAME=PATH + Loaded module and its modulefile path. Optional; may be + repeated. Default: none. + --seed SEED, --seed=SEED + Seed value to hash. Required. + --allocation TEXT, --allocation=TEXT + Scheduler allocation summary. Required. + --binding TEXT, --binding=TEXT + Scheduler binding summary. Required. + --cpu TEXT, --cpu=TEXT + CPU facts. Required. + --gpu TEXT, --gpu=TEXT + GPU facts, or none. Required. + --out FILE, --out=FILE + Write JSON to FILE. Default: stdout. + eb-keep-logs test-compare [--json] BUNDLE... + Summarize which evidence fields differ across two or more + test-bundle JSON files, without deciding pass or fail. --json prints + schema_version 1. Zig build only. + --json + Print one line of JSON instead of text. Default: text. + BUNDLE + Two or more test-bundle JSON files. Required. + eb-keep-logs lifecycle --policy FILE [--modulerc-out FILE] + [--easyconfigs DIR ...] [--easystack FILE ...] + [--eb-stack PATH] [--rebuild-set FILE] + [--now EPOCH] [--json] FILE + Generate a reversible lifecycle plan and Lmod .modulerc.lua + warnings/forbids from usage --json output and a TOML policy. Never + deletes software or modulefiles. Requires a minimum observation + window and checks installed dependents via eb-stack rebuild-set + before allowing candidate-remove. Zig build only. + --policy FILE, --policy=FILE + TOML lifecycle policy file. Required. + --modulerc-out FILE, --modulerc-out=FILE + Write the generated Lmod .modulerc.lua warnings and forbids + durably to FILE. Default: none; no file is written. + --easyconfigs DIR, --easyconfigs=DIR + Easyconfig tree passed to eb-stack rebuild-set to identify + dependents of candidate removals. Repeatable. Default: none. + --easystack FILE, --easystack=FILE + Deployed easystack YAML passed to eb-stack rebuild-set. + Repeatable. Default: none. + --eb-stack PATH, --eb-stack=PATH + Path to the eb-stack executable. Default: eb-stack on PATH. + --rebuild-set FILE, --rebuild-set=FILE + Precomputed eb-stack rebuild-set.json report instead of + running eb-stack. Default: none. + --now EPOCH, --now=EPOCH + Reference epoch time in seconds for idle age and observation + window checks. Default: the environment time override, else + the current time. + --json + Print one line of JSON instead, with schema_version 1. + FILE + JSON output produced by eb-keep-logs usage --json (with + selection "all"). Required. + eb-keep-logs -h | --help + Print this help on stdout and exit 0. + eb-keep-logs --version + Print the version line on stdout and exit 0. + +Environment: + PATH Where failed looks up eb. + EASYBUILD_TMPDIR failed copies a command's output only from below it; + unset or empty, it copies none. + EB_KEEP_LOGS_NOW The time rotate and lifecycle take as now, in seconds + since the epoch; unset or empty, the current time. + EB_PIPELINE_LOG_DIR rotate leaves alone the run that holds this path. + EB_KEEP_LOGS_SYSLOG Default --syslog target (journald, syslog, unix:///..., + journal+unix:///..., udp://host:port, tcp://host:port). + EB_KEEP_LOGS_SYSLOG_PEN + IANA Private Enterprise Number for RFC 5424 SD-ID + ebKeepLogs@. Default: 32473 (RFC 5398 placeholder). + TZ, TZDIR The time zone of the local midnights, and the + directory of zone files. + +Exit status: + 0 -h, --help or --version, or a failed, rotate, why, history, failures, loads, runs, used, usage, pending, test-bundle, test-compare or lifecycle that + accepted its arguments, whatever it could keep, compress, remove or + read: what it could not do is reported on stderr. used with + --require-none also exits 2 when any path was listed. + 2 The invocation was refused, with eb-keep-logs: MESSAGE on stderr; or + no command was given, and this help is on stdout. + 75 rotate waited --lock-timeout seconds for the lock another rotate + held, then gave up and changed nothing; run it again later. +--- stderr diff --git a/tests/golden/cases/rotate__EB_KEEP_LOGS_NOW_far_above_a_run b/tests/golden/cases/rotate__EB_KEEP_LOGS_NOW_far_above_a_run new file mode 100644 index 0000000..83b4ba9 --- /dev/null +++ b/tests/golden/cases/rotate__EB_KEEP_LOGS_NOW_far_above_a_run @@ -0,0 +1,5 @@ +exit 0 +--- stdout +compress @WORK@/now-overflow-early/00010101_120000/a.log +eb-keep-logs rotate dry-run: 1 file would be compressed, 0 runs would be deleted under @WORK@/now-overflow-early +--- stderr diff --git a/tests/golden/cases/rotate__EB_KEEP_LOGS_NOW_far_below_a_run b/tests/golden/cases/rotate__EB_KEEP_LOGS_NOW_far_below_a_run new file mode 100644 index 0000000..e8967b4 --- /dev/null +++ b/tests/golden/cases/rotate__EB_KEEP_LOGS_NOW_far_below_a_run @@ -0,0 +1,4 @@ +exit 0 +--- stdout +eb-keep-logs rotate dry-run: 0 files would be compressed, 0 runs would be deleted under @WORK@/now-overflow +--- stderr diff --git a/tests/golden/cases/rotate__a_run_still_written_into b/tests/golden/cases/rotate__a_run_still_written_into new file mode 100644 index 0000000..35ed2a9 --- /dev/null +++ b/tests/golden/cases/rotate__a_run_still_written_into @@ -0,0 +1,4 @@ +exit 0 +--- stdout +eb-keep-logs rotate: 0 files compressed, 0 runs deleted under @WORK@/live +--- stderr diff --git a/tests/golden/cases/rotate__bad_compress b/tests/golden/cases/rotate__bad_compress new file mode 100644 index 0000000..9338748 --- /dev/null +++ b/tests/golden/cases/rotate__bad_compress @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: --compress-after needs a number of days diff --git a/tests/golden/cases/rotate__bad_lock_timeout b/tests/golden/cases/rotate__bad_lock_timeout new file mode 100644 index 0000000..3c9574c --- /dev/null +++ b/tests/golden/cases/rotate__bad_lock_timeout @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: --lock-timeout needs a number of seconds diff --git a/tests/golden/cases/rotate__bad_syslog_pen b/tests/golden/cases/rotate__bad_syslog_pen new file mode 100644 index 0000000..dc9d1ea --- /dev/null +++ b/tests/golden/cases/rotate__bad_syslog_pen @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: EB_KEEP_LOGS_SYSLOG_PEN must be a positive integer, not 'abc' diff --git a/tests/golden/cases/rotate__bad_syslog_target b/tests/golden/cases/rotate__bad_syslog_target new file mode 100644 index 0000000..9afac6e --- /dev/null +++ b/tests/golden/cases/rotate__bad_syslog_target @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: invalid syslog target 'bogus://x' diff --git a/tests/golden/cases/rotate__compress-after_overflow b/tests/golden/cases/rotate__compress-after_overflow new file mode 100644 index 0000000..9338748 --- /dev/null +++ b/tests/golden/cases/rotate__compress-after_overflow @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: --compress-after needs a number of days diff --git a/tests/golden/cases/rotate__compress-after_past_a_signed_64-bit_integer b/tests/golden/cases/rotate__compress-after_past_a_signed_64-bit_integer new file mode 100644 index 0000000..e43c2fe --- /dev/null +++ b/tests/golden/cases/rotate__compress-after_past_a_signed_64-bit_integer @@ -0,0 +1,4 @@ +exit 0 +--- stdout +eb-keep-logs rotate: 0 files compressed, 0 runs deleted under @WORK@/compress-overflow +--- stderr diff --git a/tests/golden/cases/rotate__delete-after_overflow b/tests/golden/cases/rotate__delete-after_overflow new file mode 100644 index 0000000..0cace04 --- /dev/null +++ b/tests/golden/cases/rotate__delete-after_overflow @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: --delete-after needs a number of days diff --git a/tests/golden/cases/rotate__delete-after_past_a_signed_64-bit_integer b/tests/golden/cases/rotate__delete-after_past_a_signed_64-bit_integer new file mode 100644 index 0000000..a3b134d --- /dev/null +++ b/tests/golden/cases/rotate__delete-after_past_a_signed_64-bit_integer @@ -0,0 +1,4 @@ +exit 0 +--- stdout +eb-keep-logs rotate: 0 files compressed, 0 runs deleted under @WORK@/logs +--- stderr diff --git a/tests/golden/cases/rotate__delete_not_later b/tests/golden/cases/rotate__delete_not_later new file mode 100644 index 0000000..e5a0fb6 --- /dev/null +++ b/tests/golden/cases/rotate__delete_not_later @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: --delete-after must be later than --compress-after diff --git a/tests/golden/cases/rotate__dry-run_preview b/tests/golden/cases/rotate__dry-run_preview new file mode 100644 index 0000000..5637d10 --- /dev/null +++ b/tests/golden/cases/rotate__dry-run_preview @@ -0,0 +1,6 @@ +--- stdout +compress @WORK@/preview/20261001_120000/a.log +compress @WORK@/preview/20261001_120000/sub/b.log +compress @WORK@/preview/20261001_120000/z.log +eb-keep-logs rotate dry-run: 3 files would be compressed, 0 runs would be deleted under @WORK@/preview +--- stderr diff --git a/tests/golden/cases/rotate__dry_run b/tests/golden/cases/rotate__dry_run new file mode 100644 index 0000000..1ea3082 --- /dev/null +++ b/tests/golden/cases/rotate__dry_run @@ -0,0 +1,7 @@ +exit 0 +--- stdout +compress @WORK@/preview/20261001_120000/a.log +compress @WORK@/preview/20261001_120000/sub/b.log +compress @WORK@/preview/20261001_120000/z.log +eb-keep-logs rotate dry-run: 3 files would be compressed, 0 runs would be deleted under @WORK@/preview +--- stderr diff --git a/tests/golden/cases/rotate__dry_run_with_empty_metrics-file b/tests/golden/cases/rotate__dry_run_with_empty_metrics-file new file mode 100644 index 0000000..76606d4 --- /dev/null +++ b/tests/golden/cases/rotate__dry_run_with_empty_metrics-file @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: --metrics-file needs a path diff --git a/tests/golden/cases/rotate__dry_run_with_metrics-file b/tests/golden/cases/rotate__dry_run_with_metrics-file new file mode 100644 index 0000000..1ea3082 --- /dev/null +++ b/tests/golden/cases/rotate__dry_run_with_metrics-file @@ -0,0 +1,7 @@ +exit 0 +--- stdout +compress @WORK@/preview/20261001_120000/a.log +compress @WORK@/preview/20261001_120000/sub/b.log +compress @WORK@/preview/20261001_120000/z.log +eb-keep-logs rotate dry-run: 3 files would be compressed, 0 runs would be deleted under @WORK@/preview +--- stderr diff --git a/tests/golden/cases/rotate__empty_EB_KEEP_LOGS_NOW b/tests/golden/cases/rotate__empty_EB_KEEP_LOGS_NOW new file mode 100644 index 0000000..a3b134d --- /dev/null +++ b/tests/golden/cases/rotate__empty_EB_KEEP_LOGS_NOW @@ -0,0 +1,4 @@ +exit 0 +--- stdout +eb-keep-logs rotate: 0 files compressed, 0 runs deleted under @WORK@/logs +--- stderr diff --git a/tests/golden/cases/rotate__empty_delete b/tests/golden/cases/rotate__empty_delete new file mode 100644 index 0000000..a3b134d --- /dev/null +++ b/tests/golden/cases/rotate__empty_delete @@ -0,0 +1,4 @@ +exit 0 +--- stdout +eb-keep-logs rotate: 0 files compressed, 0 runs deleted under @WORK@/logs +--- stderr diff --git a/tests/golden/cases/rotate__empty_lock_timeout b/tests/golden/cases/rotate__empty_lock_timeout new file mode 100644 index 0000000..a3b134d --- /dev/null +++ b/tests/golden/cases/rotate__empty_lock_timeout @@ -0,0 +1,4 @@ +exit 0 +--- stdout +eb-keep-logs rotate: 0 files compressed, 0 runs deleted under @WORK@/logs +--- stderr diff --git a/tests/golden/cases/rotate__killed_mid-compress b/tests/golden/cases/rotate__killed_mid-compress new file mode 100644 index 0000000..ad0f5fa --- /dev/null +++ b/tests/golden/cases/rotate__killed_mid-compress @@ -0,0 +1,2 @@ +compressed by the second rotate: 1 +a.log left behind: no diff --git a/tests/golden/cases/rotate__lock_held b/tests/golden/cases/rotate__lock_held new file mode 100644 index 0000000..8d4f539 --- /dev/null +++ b/tests/golden/cases/rotate__lock_held @@ -0,0 +1,4 @@ +exit 75 +--- stdout +--- stderr +eb-keep-logs: another rotate holds the lock @WORK@/logs/.eb-keep-logs-rotate.lock; gave up after 0 s (--lock-timeout) diff --git a/tests/golden/cases/rotate__lock_held__zeros b/tests/golden/cases/rotate__lock_held__zeros new file mode 100644 index 0000000..8d4f539 --- /dev/null +++ b/tests/golden/cases/rotate__lock_held__zeros @@ -0,0 +1,4 @@ +exit 75 +--- stdout +--- stderr +eb-keep-logs: another rotate holds the lock @WORK@/logs/.eb-keep-logs-rotate.lock; gave up after 0 s (--lock-timeout) diff --git a/tests/golden/cases/rotate__lock_is_a_symbolic_link b/tests/golden/cases/rotate__lock_is_a_symbolic_link new file mode 100644 index 0000000..1aafa8d --- /dev/null +++ b/tests/golden/cases/rotate__lock_is_a_symbolic_link @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: cannot lock @WORK@/symlock/.eb-keep-logs-rotate.lock: SymLink diff --git a/tests/golden/cases/rotate__lock_timeout_without_a_value b/tests/golden/cases/rotate__lock_timeout_without_a_value new file mode 100644 index 0000000..3c9574c --- /dev/null +++ b/tests/golden/cases/rotate__lock_timeout_without_a_value @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: --lock-timeout needs a number of seconds diff --git a/tests/golden/cases/rotate__missing_root b/tests/golden/cases/rotate__missing_root new file mode 100644 index 0000000..e30edea --- /dev/null +++ b/tests/golden/cases/rotate__missing_root @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: ROOT @WORK@/nope is not a directory diff --git a/tests/golden/cases/rotate__no_compress b/tests/golden/cases/rotate__no_compress new file mode 100644 index 0000000..9338748 --- /dev/null +++ b/tests/golden/cases/rotate__no_compress @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: --compress-after needs a number of days diff --git a/tests/golden/cases/rotate__no_root b/tests/golden/cases/rotate__no_root new file mode 100644 index 0000000..bf9a93b --- /dev/null +++ b/tests/golden/cases/rotate__no_root @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: rotate needs ROOT diff --git a/tests/golden/cases/rotate__nothing_to_do b/tests/golden/cases/rotate__nothing_to_do new file mode 100644 index 0000000..a3b134d --- /dev/null +++ b/tests/golden/cases/rotate__nothing_to_do @@ -0,0 +1,4 @@ +exit 0 +--- stdout +eb-keep-logs rotate: 0 files compressed, 0 runs deleted under @WORK@/logs +--- stderr diff --git a/tests/golden/cases/rotate__two_roots b/tests/golden/cases/rotate__two_roots new file mode 100644 index 0000000..e4fdf8d --- /dev/null +++ b/tests/golden/cases/rotate__two_roots @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: rotate takes one ROOT diff --git a/tests/golden/cases/rotate__unknown_option b/tests/golden/cases/rotate__unknown_option new file mode 100644 index 0000000..2d4ea3e --- /dev/null +++ b/tests/golden/cases/rotate__unknown_option @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: unknown option --bogus diff --git a/tests/golden/cases/unknown_command b/tests/golden/cases/unknown_command new file mode 100644 index 0000000..a6b3f84 --- /dev/null +++ b/tests/golden/cases/unknown_command @@ -0,0 +1,4 @@ +exit 2 +--- stdout +--- stderr +eb-keep-logs: unknown command 'bogus' (failed, rotate, why, history, failures, loads, runs, used, usage, pending, test-bundle, test-compare, lifecycle, --help) diff --git a/tests/golden/stability/failed.kept b/tests/golden/stability/failed.kept new file mode 100644 index 0000000..7cc5534 --- /dev/null +++ b/tests/golden/stability/failed.kept @@ -0,0 +1,2 @@ +== processing EasyBuild easyconfig /ec/Foo-1.0.eb +error: bad diff --git a/tests/differential.sh b/tests/test_cases.sh similarity index 65% rename from tests/differential.sh rename to tests/test_cases.sh index f44bdb2..75269f6 100644 --- a/tests/differential.sh +++ b/tests/test_cases.sh @@ -1,69 +1,53 @@ #!/bin/bash -# Run the shell implementation (OLD_BIN, default ./eb-keep-logs) and the Zig -# build (TOOL_BIN) on the same invocations and compare exit code, stdout and -# stderr. A difference COMPAT.md lists as deliberate is reported and allowed; -# any other fails the run. -# TOOL_BIN=zig-out/bin/eb-keep-logs bash tests/differential.sh +# Run the binary (TOOL_BIN) on fixed invocations and compare exit code, +# stdout and stderr with the expected output under tests/golden/cases, one +# file per case. The work directory shows as @WORK@, this checkout as +# @REPO@. The expected files are the shell implementation's output wherever +# the two implementations agreed, and the binary's where they differed by +# design. +# TOOL_BIN=zig-out/bin/eb-keep-logs bash tests/test_cases.sh +# RECORD=1 rewrites the expected files from TOOL_BIN instead of comparing. set -u repo_root=$(cd "$(dirname "$0")/.." && pwd) -OLD_BIN="${OLD_BIN:-${repo_root}/eb-keep-logs}" : "${TOOL_BIN:?}" -work=$(mktemp -d "${TMPDIR:-/tmp}/ekl-diff.XXXXXX") +golden="${repo_root}/tests/golden/cases" +work=$(mktemp -d "${TMPDIR:-/tmp}/ekl-cases.XXXXXX") trap 'rm -rf -- "${work}"' EXIT -mkdir -p "${work}/logs" "${work}/bin" +real_work=$(realpath "${work}") +mkdir -p "${work}/logs" "${work}/bin" "${golden}" printf '#!/bin/bash\nexit 0\n' > "${work}/bin/eb" chmod +x "${work}/bin/eb" export PATH="${work}/bin:${PATH}" diffs=0 -# Labels whose difference is deliberate, each with its case in COMPAT.md. A -# difference passes only while COMPAT.md lists that case among the -# deliberate differences. -declare -A deliberate=( - ["rotate, lock is a symbolic link"]="\`rotate\`'s lock file cannot be opened, or is a symbolic link or not a regular file" - ["rotate, compress-after overflow"]="\`--compress-after\` or \`--delete-after\` naming more days than an unsigned 64-bit integer holds" - ["rotate, delete-after overflow"]="\`--compress-after\` or \`--delete-after\` naming more days than an unsigned 64-bit integer holds" - ["rotate, delete-after past a signed 64-bit integer"]="\`--delete-after\` naming more days than a signed 64-bit integer holds, together with a \`--compress-after\` it is genuinely later than" - ["rotate, compress-after past a signed 64-bit integer"]="\`--compress-after\` naming more days than a signed 64-bit integer holds, without a \`--delete-after\` of its own" - ["rotate, EB_KEEP_LOGS_NOW far below a run"]="\`EB_KEEP_LOGS_NOW\` so far below a run's local midnight that the difference overflows a signed 64-bit integer" - ["rotate, EB_KEEP_LOGS_NOW far above a run"]="\`EB_KEEP_LOGS_NOW\` so far above a run's local midnight that the difference overflows a signed 64-bit integer" - ["why"]="\`why\`" - ["history"]="\`history\`" - ["failures"]="\`failures\`" - ["loads"]="\`loads\`" - ["runs"]="\`runs\`" - ["used"]="\`used\`" - ["usage"]="\`usage\`" - ["pending"]="\`pending\`" - ["lifecycle"]="\`lifecycle\`" - ["rotate, killed mid-compress"]="a \`rotate\` killed while compressing a file" -) -compat_deliberate=$(sed -n '/^## Deliberate differences$/,/^## /p' "${repo_root}/COMPAT.md") -# The environment both runs get, as env(1) takes it. +# The environment each run gets, as env(1) takes it. run_env=(PATH="${PATH}") -# compare LABEL ARGS...: run both with the same arguments. -compare() { - local label=$1; shift - env "${run_env[@]}" "${OLD_BIN}" "$@" > "${work}/o.out" 2> "${work}/o.err"; local oc=$? - env "${run_env[@]}" "${TOOL_BIN}" "$@" > "${work}/n.out" 2> "${work}/n.err"; local nc=$? - if [ "${oc}" != "${nc}" ] || ! cmp -s "${work}/o.out" "${work}/n.out" || ! cmp -s "${work}/o.err" "${work}/n.err"; then - local compat_case="${deliberate[${label}]:-}" - if [ -n "${compat_case}" ] && grep -qF -- "| ${compat_case} |" <<< "${compat_deliberate}"; then - echo "deliberate ${label}" - return - fi - # On stderr: zig build test shows a script's stderr, not stdout. +# expect LABEL FILE: compare FILE, with the work directory as @WORK@, against +# the expected file of LABEL, or write it under RECORD=1. +expect() { + local label=$1 got=$2 want + want="${golden}/$(printf '%s' "${label}" | tr -c 'A-Za-z0-9_-' '_')" + sed -e "s|${real_work}|@WORK@|g" -e "s|${work}|@WORK@|g" -e "s|${repo_root}|@REPO@|g" "${got}" > "${work}/got.norm" + if [ -n "${RECORD:-}" ]; then + cp "${work}/got.norm" "${want}" + echo "recorded ${label}" + elif cmp -s "${want}" "${work}/got.norm"; then + echo "same ${label}" + else { - echo "DIFF ${label}: exit ${oc} vs ${nc}" - [ -z "${compat_case}" ] || echo " COMPAT.md lists no deliberate difference: ${compat_case}" - diff "${work}/o.out" "${work}/n.out" | sed 's/^/ out /' - diff "${work}/o.err" "${work}/n.err" | sed 's/^/ err /' + echo "DIFF ${label}" + diff "${want}" "${work}/got.norm" | sed 's/^/ /' } >&2 diffs=$((diffs + 1)) - else - echo "same ${label}" fi } +# compare LABEL ARGS...: run the binary with ARGS and check what it printed. +compare() { + local label=$1; shift + env "${run_env[@]}" "${TOOL_BIN}" "$@" > "${work}/n.out" 2> "${work}/n.err"; local nc=$? + { echo "exit ${nc}"; echo "--- stdout"; cat "${work}/n.out"; echo "--- stderr"; cat "${work}/n.err"; } > "${work}/n.all" + expect "${label}" "${work}/n.all" +} compare "no arguments" compare "--help" --help @@ -173,13 +157,10 @@ if [ -e "${work}/dry.prom" ] || [ -e "${work}/.dry.prom.lock" ]; then diffs=$((diffs + 1)) fi compare "rotate, dry run with empty metrics-file" rotate "${work}/preview" --compress-after 5 --dry-run --metrics-file "" -EB_KEEP_LOGS_NOW="$(date -d 2026-11-13 +%s)" "${OLD_BIN}" rotate "${work}/preview" --compress-after 5 --dry-run > "${work}/dry-parity-old.out" 2> "${work}/dry-parity-old.err" EB_KEEP_LOGS_NOW="$(date -d 2026-11-13 +%s)" "${TOOL_BIN}" rotate "${work}/preview" --compress-after 5 --dry-run > "${work}/dry-parity-new.out" 2> "${work}/dry-parity-new.err" -if ! cmp -s "${work}/dry-parity-old.out" "${work}/dry-parity-new.out" || ! cmp -s "${work}/dry-parity-old.err" "${work}/dry-parity-new.err"; then - echo "DIFF rotate, dry-run raw bytes differ between shell and Zig" >&2 - diffs=$((diffs + 1)) -fi -dry_count=$(sed -nE 's/^eb-keep-logs rotate dry-run: ([0-9]+) files? would be compressed.*/\1/p' "${work}/dry-parity-old.out") +{ echo "--- stdout"; cat "${work}/dry-parity-new.out"; echo "--- stderr"; cat "${work}/dry-parity-new.err"; } > "${work}/dry-parity.all" +expect "rotate, dry-run preview" "${work}/dry-parity.all" +dry_count=$(sed -nE 's/^eb-keep-logs rotate dry-run: ([0-9]+) files? would be compressed.*/\1/p' "${work}/dry-parity-new.out") rot_out=$(EB_KEEP_LOGS_NOW="$(date -d 2026-11-13 +%s)" "${TOOL_BIN}" rotate "${work}/preview" --compress-after 5 2>/dev/null) rot_count=$(sed -nE 's/^eb-keep-logs rotate: ([0-9]+) files? compressed.*/\1/p' <<< "${rot_out}") if [ "${dry_count}" != "3" ] || [ "${dry_count}" != "${rot_count}" ]; then @@ -198,52 +179,17 @@ exec {held}>&- mkdir -p "${work}/symlock" ln -s "${work}/nowhere" "${work}/symlock/.eb-keep-logs-rotate.lock" compare "rotate, lock is a symbolic link" rotate "${work}/symlock" --compress-after 5 -# A kill while compressing is not a race on a filename. The shell side's -# gzip reads its input and dies when that stream closes, before it -# publishes a member. The Zig side is the test-ops binary, which -# `EB_KEEP_LOGS_TEST_KILL_AT=mid-copy` already kills at that step. -mkdir -p "${work}/die-gzip" "${work}/crash-old/20261001_120000" "${work}/crash-new/20261001_120000" -cat > "${work}/die-gzip/gzip" << 'EOF' -#!/bin/bash -file= -prev= -for arg in "$@"; do - if [ "${prev}" = "--" ]; then file=${arg}; fi - prev=${arg} -done -if [ -n "${file}" ]; then - cat -- "${file}" >/dev/null -else - cat >/dev/null -fi -kill -KILL $$ -EOF -chmod +x "${work}/die-gzip/gzip" -printf 'log line\n' > "${work}/crash-old/20261001_120000/a.log" +# A kill while compressing is not a race on a filename. The test-ops +# binary dies at EB_KEEP_LOGS_TEST_KILL_AT=mid-copy, before the compressed +# member is published. A second rotate then compresses the file. +mkdir -p "${work}/crash-new/20261001_120000" printf 'log line\n' > "${work}/crash-new/20261001_120000/a.log" -PATH="${work}/die-gzip:${PATH}" "${OLD_BIN}" rotate "${work}/crash-old" --compress-after 5 >/dev/null 2>&1 || true EB_KEEP_LOGS_TEST_KILL_AT=mid-copy "${TEST_OPS_BIN:?TEST_OPS_BIN names the test-ops binary}" rotate "${work}/crash-new" --compress-after 5 >/dev/null 2>&1 || true -old_rerun=$("${OLD_BIN}" rotate "${work}/crash-old" --compress-after 5 2>/dev/null) new_rerun=$("${TOOL_BIN}" rotate "${work}/crash-new" --compress-after 5 2>/dev/null) -old_count=$(sed -nE 's/^eb-keep-logs rotate: ([0-9]+) files? compressed.*/\1/p' <<< "${old_rerun}") new_count=$(sed -nE 's/^eb-keep-logs rotate: ([0-9]+) files? compressed.*/\1/p' <<< "${new_rerun}") -old_left=no; [ -e "${work}/crash-old/20261001_120000/a.log" ] && old_left=yes new_left=no; [ -e "${work}/crash-new/20261001_120000/a.log" ] && new_left=yes -label="rotate, killed mid-compress" -if [ "${old_count}" != "${new_count}" ] || [ "${old_left}" != "${new_left}" ]; then - compat_case="${deliberate[${label}]:-}" - if [ -n "${compat_case}" ] && grep -qF -- "| ${compat_case} |" <<< "${compat_deliberate}"; then - echo "deliberate ${label}" - else - { - echo "DIFF ${label}: a second rotate compressed ${old_count} (shell) vs ${new_count} (Zig) file(s), a.log left behind: ${old_left} vs ${new_left}" - [ -z "${compat_case}" ] || echo " COMPAT.md lists no deliberate difference: ${compat_case}" - } >&2 - diffs=$((diffs + 1)) - fi -else - echo "same ${label}" -fi +printf 'compressed by the second rotate: %s\na.log left behind: %s\n' "${new_count}" "${new_left}" > "${work}/crash.all" +expect "rotate, killed mid-compress" "${work}/crash.all" # The one run is past --delete-after, and another process writes into it. mkdir -p "${work}/live/20261001_120000" echo build > "${work}/live/20261001_120000/B.stdout.log" diff --git a/tests/test_eb_keep_logs.sh b/tests/test_eb_keep_logs.sh index 1ec5155..3ffbec3 100755 --- a/tests/test_eb_keep_logs.sh +++ b/tests/test_eb_keep_logs.sh @@ -6,7 +6,7 @@ set -u repo_root=$(cd "$(dirname "$0")/.." && pwd) # TOOL_BIN runs the suite against another build of the tool. -tool="${TOOL_BIN:-${repo_root}/eb-keep-logs}" +tool="${TOOL_BIN:?TOOL_BIN names the eb-keep-logs binary}" unset EB_PIPELINE_LOG_DIR fails=0 @@ -363,7 +363,7 @@ check "a list elsewhere in the run names the archive" \ "$(cat "${nest}/20261001_120000/later/.licensed-logs")" \ "${nested_log}.gz" # The new list is written to a file of its own beside the old one, not -# through a symbolic link at the fixed name the shell script used to write to. +# through a symbolic link planted at a fixed name. planted="${work}/planted/20261001_120000/site-zen4" mkdir -p "${planted}" echo log > "${planted}/P.stdout.log" @@ -621,8 +621,8 @@ ln -s "${work}/nowhere" "${work}/symlock/.eb-keep-logs-rotate.lock" "${tool}" rotate "${work}/symlock" --compress-after 30 >/dev/null 2>&1 check "a symbolic link at the lock: refused" "$?" "2" check "a symbolic link at the lock: not followed" "$(find "${work}" -maxdepth 1 -name nowhere | wc -l)" "0" -# A file system that cannot lock, as flock(1) reports it to the shell script; -# the Zig build calls flock(2), which locks here. +# A flock(1) on PATH that reports a file system that cannot lock; the +# binary calls flock(2), which locks here. mkdir -p "${work}/nolock-bin" "${work}/nolock/20261001_120000" printf '#!/bin/sh\necho "flock: 3: Function not implemented" >&2\nexit 65\n' > "${work}/nolock-bin/flock" chmod +x "${work}/nolock-bin/flock" @@ -678,10 +678,9 @@ race_out="${s1} ${s2} $(cat "${work}/race1" "${work}/race2" | sed 's/ under .*// check "two rotations at once: every list whole" "${race_lists}" "" check "two rotations at once: one rotates, the other then finds nothing" "${race_out}" \ "0 0 eb-keep-logs rotate: 0 files compressed, 0 runs deleted eb-keep-logs rotate: 12 files compressed, 0 runs deleted " -# Without the lock, as the shell script rotates where the file system cannot -# lock, two rotations at once can each list a file by the name it had when -# they read the list; but each list is one of the lists they wrote, whole: -# every line names one of the run's logs, each log once. +# Two rotations at once can each list a file by the name it had when they +# read the list; but each list is one of the lists they wrote, whole: every +# line names one of the run's logs, each log once. race_torn="" for round in 1 2; do rm -rf "${race}" diff --git a/tests/test_metrics.sh b/tests/test_metrics.sh index affb73e..a9b15ec 100755 --- a/tests/test_metrics.sh +++ b/tests/test_metrics.sh @@ -2,8 +2,7 @@ # Exercise the opt-in Prometheus textfile output. set -u -repo_root=$(cd "$(dirname "$0")/.." && pwd) -tool="${TOOL_BIN:-${repo_root}/eb-keep-logs}" +tool="${TOOL_BIN:?TOOL_BIN names the eb-keep-logs binary}" command -v promtool >/dev/null || { echo "promtool is required for tests/test_metrics.sh" >&2 exit 1 @@ -95,30 +94,13 @@ wait "${rotate_a}" "${rotate_b}" promtool check metrics < "${metrics}" grep -qx "eb_keep_logs_last_prune_timestamp_seconds ${future}" "${metrics}" -# The shell implementation must not publish a temporary file when restoring -# its mode fails. The Zig implementation performs the equivalent fchmod -# before rename and its unit tests exercise that path's ordering. -if [ "$(head -c 2 "${tool}")" = '#!' ]; then - mkdir -p "${work}/no-chmod" - cat > "${work}/no-chmod/chmod" <<'EOF' -#!/bin/sh -exit 1 -EOF - /bin/chmod +x "${work}/no-chmod/chmod" - before=$(sha256sum "${metrics}") - mode_error=$(PATH="${work}/no-chmod:${PATH}" "${tool}" failed --metrics-file "${metrics}" 0 ModeFailure "${work}/logs" 2>&1 >/dev/null) - case "${mode_error}" in *"cannot set temporary file mode"*) ;; *) exit 1 ;; esac - [ "$(sha256sum "${metrics}")" = "${before}" ] - [ "$(find "${work}/collector" -maxdepth 1 -name '*.tmp' -print | wc -l)" -eq 0 ] -fi - # A malformed prior file is preserved instead of resetting the counters. printf 'eb_keep_logs_logs_kept_total NaN\n' > "${metrics}" before=$(sha256sum "${metrics}") PATH="${work}/bin:${PATH}" "${tool}" failed --metrics-file "${metrics}" 0 Third "${work}/logs" >/dev/null 2>&1 [ "$(sha256sum "${metrics}")" = "${before}" ] -# Both implementations accept the full u64 counter range and preserve the +# The full u64 counter range is accepted, and the # previous exposition when one more keep would overflow it. cat > "${metrics}" <<'EOF' # HELP eb_keep_logs_logs_kept_total Log files kept by eb-keep-logs. diff --git a/tests/test_output_stability.sh b/tests/test_output_stability.sh index 3fedb5e..fad344a 100755 --- a/tests/test_output_stability.sh +++ b/tests/test_output_stability.sh @@ -6,7 +6,7 @@ set -u repo_root=$(cd "$(dirname "$0")/.." && pwd) tool="${TOOL_BIN:?TOOL_BIN names the Zig build}" case "${tool}" in /*) ;; *) tool="${PWD}/${tool}" ;; esac -old_bin="${repo_root}/eb-keep-logs" +golden="${repo_root}/tests/golden/stability" fails=0 # shellcheck source=tests/lib/check.sh @@ -15,7 +15,8 @@ fails=0 work=$(mktemp -d "${TMPDIR:-/tmp}/eb-keep-logs-stability.XXXXXX") trap 'rm -rf -- "${work}"' EXIT -mkdir -p "${work}/bin" "${work}/logs-o" "${work}/logs-n" +# The kept log is the one tests/golden/stability holds. +mkdir -p "${work}/bin" "${work}/logs-n" printf '== processing EasyBuild easyconfig /ec/Foo-1.0.eb\nerror: bad\n' > "${work}/eb.log" cat > "${work}/bin/eb" < "${work}/failed-o.out" 2> "${work}/failed-o.err" PATH="${work}/bin:${PATH}" "${tool}" failed 1 Foo-1.0 "${work}/logs-n" > "${work}/failed-n.out" 2> "${work}/failed-n.err" -check "failed kept log byte-identical" "$(cmp -s "${work}/logs-o/Foo-1.0.failed.ebout.log" "${work}/logs-n/Foo-1.0.failed.ebout.log" && echo ok)" "ok" +check "failed kept log byte-identical" "$(cmp -s "${golden}/failed.kept" "${work}/logs-n/Foo-1.0.failed.ebout.log" && echo ok)" "ok" echo "${fails} failed" [ "${fails}" -eq 0 ] diff --git a/tests/test_tutorial_which.sh b/tests/test_tutorial_which.sh index 16c0f90..4ec2b7f 100644 --- a/tests/test_tutorial_which.sh +++ b/tests/test_tutorial_which.sh @@ -1,13 +1,9 @@ #!/bin/bash -# The tutorial installs the shell script. It has to say that why and history -# are in the Zig build only, and how to build that program. +# The tutorial has to say how to build the program, and link the how-to of +# why. set -eu cd "$(dirname -- "$0")/.." page=docs/orgmode/tutorials/keep-a-failed-build-log.org -grep -F 'in the Zig build only' "$page" >/dev/null || { - echo "the tutorial does not say why and history are in the Zig build only" >&2 - exit 1 -} grep -F 'zig build -Drelease=true' "$page" >/dev/null || { echo "the tutorial does not say how to build the Zig program" >&2 exit 1 diff --git a/tools/release-prepare b/tools/release-prepare index d978419..6397acb 100755 --- a/tools/release-prepare +++ b/tools/release-prepare @@ -16,8 +16,7 @@ # Not done here, because it is prose: the README sentence on what `main` has # that the latest release lacks, the "Release X.Y.Z runs ..." rows of # install.org, the `--version` example with a commit in -# docs/orgmode/reference/cli.org, and a COMPAT.md row for each new deliberate -# difference from the shell script. Edit those in a commit before the bump. +# docs/orgmode/reference/cli.org. Edit those in a commit before the bump. # # Needs: towncrier (or uvx). A refused run can leave # edited files behind; `git checkout -- .` puts the tree back.