Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Mar 11, 2022
1 parent d7152e8 commit 5aee41b
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 245 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"dockerImage/submit-api" = pkgs.submitApiDockerImage;
membenches = membench.outputs.packages.x86_64-linux.batch-report;
snapshot = membench.outputs.packages.x86_64-linux.snapshot;
workbench-smoke-test = pkgs.clusterNix.profile-run-supervisord { profileName = "smoke-alzo"; };
workbench-smoke-test = pkgs.clusterNix.profile-run-supervisord { profileName = "smoke-alzo";trace = true; };
workbench-smoke-analysis = workbench-smoke-test.analysis;
workbench-ci-test = pkgs.clusterNix.profile-run-supervisord { profileName = "ci-light-alzo"; };
workbench-ci-analysis = workbench-ci-test.analysis;
Expand Down
32 changes: 22 additions & 10 deletions nix/supervisord-cluster/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ with lib;
let
backend =
rec
{ ## Generic Nix bits:
{ name = "supervisor";
## Generic Nix bits:
topologyForNodeSpec =
{ profile, nodeSpec }:
let inherit (nodeSpec) name i; in
Expand Down Expand Up @@ -181,7 +182,8 @@ let
'';

profile-run-supervisord =
{ profileName }:
{ profileName
, trace ? false }:
let
inherit
(with-supervisord-profile
Expand All @@ -207,21 +209,31 @@ let
mkdir -p $out/cache
cd $out
${workbench.shellHook}
# ''${workbench.shellHook}
export WORKBENCH_BACKEND=supervisor
export CARDANO_NODE_SOCKET_PATH=$(wb backend get-node-socket-path ${stateDir})
wb start \
--batch-name smoke-test \
--profile-name ${profileName} \
--profile ${profile} \
--cache-dir ./cache \
--base-port ${toString basePort} \
cmd=(
wb
${pkgs.lib.optionalString trace "--trace"}
start
--profile-name ${profileName}
--profile ${profile}
--topology ${topology}
--genesis-cache-entry ${genesis}
--batch-name smoke-test
--base-port ${toString basePort}
--cache-dir ./cache
)
echo "''${cmd[*]}" > $out/wb-start.sh
"''${cmd[@]}" 2>&1 |
tee $out/wb-start.log
## Convert structure from $out/run/RUN-ID/* to $out/*:
rm -rf cache
rm -f run/{current,-current}
mv run/env.json .
tag=$(cd run; ls)
echo "workbench-test: completed run $tag"
Expand Down
10 changes: 6 additions & 4 deletions nix/workbench/analyse.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ pkgs.runCommand "workbench-run-analysis-${profileNix.name}"
ln -s ${run} $out/run
args=(
cmd=(
wb
${pkgs.lib.optionalString trace "--trace"}
analyse
# --filters size-full
--outdir $out
standard
${run}
)
echo "wb ''${args[*]}" > $out/wb-invocation.sh
)
echo "''${cmd[*]}" > $out/wb-analyse.sh
wb ''${args[@]}
''${cmd[@]} 2>&1 |
tee $out/wb-analyse.log
cat > $out/nix-support/hydra-build-products <<EOF
report block-propagation $out block-propagation.txt
Expand Down
4 changes: 0 additions & 4 deletions nix/workbench/backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ usage_backend() {
Given a run directory, print the node socket path
for 'cardano-cli'
record-extended-env-config ENV-JSON [ENV-CONFIG-OPTS..]
Extend the environment JSON file with backend-specific
environment config
allocate-run RUNDIR
describe-run RUNDIR
start-cluster RUNDIR
Expand Down
33 changes: 16 additions & 17 deletions nix/workbench/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ let
profile-names =
__fromJSON (__readFile profile-names-json);

environment =
## IMPORTANT: keep in sync with envArgs in 'supervisord-cluster/default.nix/envArgs'.
with envArgs; rec {
inherit cardanoLib stateDir;

JSON = runWorkbenchJqOnly "environment.json"
''env compute-config \
--cache-dir "${cacheDir}" \
--base-port ${toString basePort} \
${optionalString staggerPorts "--stagger-ports"} \
'';
value = __fromJSON (__readFile JSON);
};
# environment =
# ## IMPORTANT: keep in sync with envArgs in 'supervisord-cluster/default.nix/envArgs'.
# with envArgs; rec {
# inherit cardanoLib stateDir;
#
# JSON = runWorkbenchJqOnly "environment.json"
# ''env compute-config \
# --cache-dir "${cacheDir}" \
# --base-port ${toString basePort} \
# ${optionalString staggerPorts "--stagger-ports"} \
# '';
# value = __fromJSON (__readFile JSON);
# };

mkProfile =
profileName:
Expand All @@ -150,7 +150,6 @@ let
pkgs
runWorkbenchJqOnly runJq workbench
backend
environment
profileName;
};

Expand All @@ -177,14 +176,14 @@ let
or (throw "No such profile: ${profileName}; Known profiles: ${toString (__attrNames ps.profiles)}");

profile = materialise-profile
{ inherit profileNix;
{ inherit profileNix workbench;
backendProfile =
backend.materialise-profile { inherit profileNix; };
};

topology = profile-topology { inherit profileNix; };
topology = profile-topology { inherit profileNix profile workbench; };

genesis = profile-topology-genesis { inherit profileNix topology; };
genesis = profile-topology-genesis { inherit profileNix profile topology workbench; };
in {
inherit
profileNix profile
Expand Down
54 changes: 17 additions & 37 deletions nix/workbench/env.sh
Original file line number Diff line number Diff line change
@@ -1,44 +1,24 @@
default_cacheDir="$HOME"/.cache/cardano-workbench
default_basePort=30000
WORKBENCH_ENV_DEFAULT='
{ "type": "supervisor"
, "cacheDir": "'$HOME'/.cache/cardano-workbench"
, "basePort": 30000
, "staggerPorts": true
}'

usage_env() {
usage "env" "Environment setup" <<EOF
compute-config [ENV-OPTS..]
Compute the environment configuration JSON.
The following environment config options are defined:
export WORKBENCH_ENV=$WORKBENCH_ENV_DEFAULT

--cache-dir DIR Set the cache directory; Defaults to $default_cachedir
--base-port PORTNO Set base port number; Defaults to $default_basePort
--stagger-ports Whether to allocate different ports for each node;
Defaults to no port staggering
EOF
envjq() {
jq ".$1" <<<$WORKBENCH_ENV
}

env() {
local op=${1:---help)}; shift

case "${op}" in
compute-config )
local usage="USAGE: wb run OPTS.. print-env-config"

local v=(
--arg cacheDir "$default_cacheDir"
--argjson basePort "$default_basePort"
--argjson staggerPorts 'false'
)

while test $# -gt 0; do case "$1" in
--cache-dir ) v=(--arg cacheDir "$2" "${v[@]}"); shift;;
--base-port ) v=(--argjson basePort $2 "${v[@]}"); shift;;
--stagger-ports ) v=(--argjson staggerPorts true "${v[@]}");;
* ) fatal "wb run print-env-config: unknown args: $*";; esac
shift; done
envjqr() {
jq -r ".$1" <<<$WORKBENCH_ENV
}

jq '{ cacheDir: $cacheDir
, basePort: $basePort
, staggerPorts: $staggerPorts
}' --null-input "${v[@]}";;
setenvjq() {
export WORKBENCH_ENV=$(jq ". * { $1: $2 }" <<<$WORKBENCH_ENV)
}

* ) usage_env;; esac
setenvjqstr() {
setenvjq "$1" "\"$2\""
}
4 changes: 2 additions & 2 deletions nix/workbench/genesis.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ pkgs }:

{ profileNix, topology }:
{ profileNix, profile, topology, workbench }:
pkgs.runCommand "workbench-profile-genesis-cache-${profileNix.name}"
{ requiredSystemFeatures = [ "benchmark" ];
nativeBuildInputs = with pkgs.haskellPackages; with pkgs;
Expand All @@ -12,7 +12,7 @@ pkgs.runCommand "workbench-profile-genesis-cache-${profileNix.name}"
genesis actually-genesis
${profileNix.JSON}
${topology}
${out}
$out
)
time wb ''${args[@]}
Expand Down
33 changes: 33 additions & 0 deletions nix/workbench/genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,39 @@ case "$op" in
## TODO: try to get rid of this step:
Massage_the_key_file_layout_to_match_AWS "$profile_json" "$topo_dir" "$dir";;

derive-from-cache )
local usage="USAGE: wb genesis $op PROFILE-JSON CACHE-ENTRY-DIR OUTDIR"
local profile_json=${1:?$usage}
local cache_entry=${2:?$usage}
local outdir=${3:?$usage}

msg "genesis | derive-from-cache: $cache_entry -> $outdir"
ls -l $cache_entry

mkdir -p "$outdir"
( cd $outdir
ln -s $cache_entry cache-entry
ln -s $profile_json
ln -s $cache_entry/cache.key
ln -s $cache_entry/cache.key.input
ln -s $cache_entry/layout.version
## keys
ln -s $cache_entry/delegate-keys
ln -s $cache_entry/genesis-keys
cp $cache_entry/node-keys . -a
chmod -R go-rwx node-keys
ln -s $cache_entry/pools
ln -s $cache_entry/stake-delegator-keys
ln -s $cache_entry/utxo-keys
## JSON
cp -v $cache_entry/genesis*.json .
chmod u+w genesis*.json
)
genesis finalise-cache-entry $profile_json $outdir

ls -l $outdir/node-keys
;;

finalise-cache-entry )
local usage="USAGE: wb genesis $op PROFILE-JSON DIR"
local profile_json=${1:?$usage}
Expand Down
8 changes: 6 additions & 2 deletions nix/workbench/profile.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ with lib;

{ profileNix
, backendProfile ## Backend-specific results for forwarding
, workbench
}:
pkgs.runCommand "workbench-profile-output-${profileNix.name}"
{ buildInputs = [];
{ buildInputs = with pkgs; [ jq workbench ];
nodeServices =
__toJSON
(flip mapAttrs profileNix.node-services
Expand All @@ -29,7 +30,10 @@ pkgs.runCommand "workbench-profile-output-${profileNix.name}"
}
''
mkdir $out
cp ${backendProfile}/* $out
cp ${profileNix.JSON} $out/profile.json
cp ${backendProfile}/* $out
cp $nodeServicesPath $out/node-services.json
cp $generatorServicePath $out/generator-service.json
wb profile node-specs $out/profile.json > $out/node-specs.json
''
24 changes: 11 additions & 13 deletions nix/workbench/profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ usage_profile() {
compose NAME.. Create a profile composed from named profiles
get NAME Get contents of either named profile, or profile JSON desc
describe NAME Print a human description of a profile
node-specs PROFILE-NAME/JSON [ENV-JSON=$global_rundir_def/env.json]
node-specs PROFILE-NAME/JSON
Print node specs JSON for the given profile and environment
EOF
}
Expand Down Expand Up @@ -58,22 +58,21 @@ case "$op" in
| add
';;

get )
json-by-name )
local usage="USAGE: wb profile $op NAME"
local name=${1:?$usage}

if test -f "$name"
then jq '.' "$name"
else profile generate-all |
jq '.["'$name'"]'
fi
;;
fi;;

describe )
local usage="USAGE: wb profile $op NAME"
local name=${1:?$usage}

profile get $name |
profile json-by-name $name |
(cd "$global_basedir/profiles";

echo -n "workbench: "
Expand All @@ -85,7 +84,7 @@ case "$op" in
has-preset )
local usage="USAGE: wb profile $op NAME"
local profile=${1:?$usage}
profile get "$profile" | jqtest ".preset != null";;
profile json-by-name "$profile" | jqtest ".preset != null";;

preset-get-file )
local usage="USAGE: wb profile $op PRESET-NAME DESC FILE"
Expand All @@ -101,16 +100,15 @@ case "$op" in
fi;;

node-specs )
local usage="USAGE: wb profile $op PROFILE-NAME/JSON [ENV-JSON=$global_rundir_def/env.json]"
local usage="USAGE: wb profile $op PROFILE-NAME/JSON"
local profile=${1:?$usage}
local env_json=${2:-$global_rundir_def/env.json}

local args=(
--slurpfile env "$env_json"
--argjson env "$WORKBENCH_ENV"
)
## WARNING: this is structured in correspondence
## with the output generated by cardano-topology
profile get "$profile" | jq '. as $prof
profile json-by-name "$profile" | jq '. as $prof
| $prof.composition.n_bft_hosts as $n_bfts
| $prof.composition.n_pool_hosts as $n_pools
| ([range(0;
Expand Down Expand Up @@ -146,9 +144,9 @@ case "$op" in
{ name: "node-\(.["i"])"
, isProducer: ([.kind == "bft", .kind == "pool"] | any)
, port:
(if $env[0].staggerPorts
then $env[0].basePort + .i
else $env[0].basePort
(if $env.staggerPorts
then $env.basePort + .i
else $env.basePort
end)
}))
| map({ key: .name, value: .})
Expand Down
Loading

0 comments on commit 5aee41b

Please sign in to comment.