From 1446f11222e3dfad0318d377901424807246a116 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sun, 21 Jun 2026 17:32:51 +0200 Subject: [PATCH] nix(loadtest): refactor genTargets argument Instead of passing a path to the output target file, just pass the directory in which to create the file. This allows the script to create multiple files later. --- nix/tools/generate_targets.py | 13 ++++++++----- nix/tools/loadtest.nix | 6 +++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/nix/tools/generate_targets.py b/nix/tools/generate_targets.py index 75ddd597c..e43e9e4a0 100644 --- a/nix/tools/generate_targets.py +++ b/nix/tools/generate_targets.py @@ -58,9 +58,10 @@ def main(): description="Generate Vegeta targets with unique JWTs" ) parser.add_argument( - "targets_path", - metavar="TARGETS_PATH", - help="Path to write the generated targets file", + "generated_path", + metavar="GENERATED_PATH", + help="Path to write the generated files", + type=Path, ) parser.add_argument( "--private-key", @@ -79,6 +80,8 @@ def main(): args = parser.parse_args() + targets_path = args.generated_path / "gen_targets.http" + rsa_private_key: Optional[jwt.algorithms.RSAAlgorithm] = None nsamples = 500 # per algorithm @@ -134,10 +137,10 @@ def main(): lines.extend(target) try: - with open(args.targets_path, "w") as f: + with open(targets_path, "w") as f: f.write("\n".join(lines)) except IOError as e: - print(f"Error writing to {args.targets_path}: {e}", file=sys.stderr) + print(f"Error writing to {targets_path}: {e}", file=sys.stderr) sys.exit(1) print(f"Created {ntargets} targets", end=" ") diff --git a/nix/tools/loadtest.nix b/nix/tools/loadtest.nix index 2bd5d49ea..fda3cdbe0 100644 --- a/nix/tools/loadtest.nix +++ b/nix/tools/loadtest.nix @@ -70,7 +70,7 @@ let ${genKeyMaterials} --jwks="$_arg_testdir"/gen_jwks.json --private-key="$_arg_testdir"/gen_private.json export PGRST_JWT_SECRET="@$_arg_testdir/gen_jwks.json" - ${genTargets} --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir"/gen_targets.http + ${genTargets} --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir" # shellcheck disable=SC2145 ${withTools.withPg} -f "$_arg_testdir"/fixtures.sql \ @@ -83,7 +83,7 @@ let ${genKeyMaterials} --jwks="$_arg_testdir"/gen_jwks.json --private-key="$_arg_testdir"/gen_private.json export PGRST_JWT_SECRET="@$_arg_testdir/gen_jwks.json" - ${genTargets} --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir"/gen_targets.http + ${genTargets} --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir" # shellcheck disable=SC2145 ${withTools.withPg} -f "$_arg_testdir"/fixtures.sql \ @@ -96,7 +96,7 @@ let ${genKeyMaterials} --jwks="$_arg_testdir"/gen_jwks.json --private-key="$_arg_testdir"/gen_private.json export PGRST_JWT_SECRET="@$_arg_testdir/gen_jwks.json" - ${libfaketime}/bin/faketime '2000-01-01 00:00:00' ${genTargets} --worst --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir"/gen_targets.http + ${libfaketime}/bin/faketime '2000-01-01 00:00:00' ${genTargets} --worst --private-key="$_arg_testdir"/gen_private.json "$_arg_testdir" # shellcheck disable=SC2145 ${withTools.withPg} -f "$_arg_testdir"/fixtures.sql \