Skip to content

Commit

Permalink
workbench: further cardano-tracer integration & RTView
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed May 23, 2022
1 parent ecebefe commit ab3da99
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 33 deletions.
13 changes: 9 additions & 4 deletions nix/nixos/cardano-tracer-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pkgs:
let serviceConfigToJSON =
cfg:
{
networkMagic = 764824073; ## Mainnet
inherit (cfg) networkMagic;
# loRequestNum = 100;
network =
if cfg.acceptingSocket != null
Expand All @@ -28,6 +28,10 @@ let serviceConfigToJSON =
rpMaxAgeHours = 24;
};

hasRTView = {
epHost = "127.0.0.1";
epPort = 3300;
};
hasEKG = [
{ epHost = "127.0.0.1";
epPort = 3100; ## supervisord.portShiftPrometheus
Expand Down Expand Up @@ -58,9 +62,10 @@ in pkgs.commonLib.defServiceModule

extraOptionDecls = {
### You can actually change those!
acceptingSocket = mayOpt str "Socket path: as acceptor.";
connectToSocket = mayOpt str "Socket path: connect to.";
logRoot = opt str null "Log storage root directory.";
networkMagic = opt int 764824073 "Network magic (764824073 for Cardano mainnet).";
acceptingSocket = mayOpt str "Socket path: as acceptor.";
connectToSocket = mayOpt str "Socket path: connect to.";
logRoot = opt str null "Log storage root directory.";

### Here be dragons, on the other hand..
configFile = mayOpt str
Expand Down
7 changes: 4 additions & 3 deletions nix/workbench/backend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ usage_backend() {
allocate-run RUNDIR
describe-run RUNDIR
start-cluster RUNDIR
Start the cluster nodes
start RUNDIR Start the backend
start-nodes RUNDIR
start-node RUNDIR NODE-NAME
stop-node RUNDIR NODE-NAME
wait-node RUNDIR NODE-NAME
Expand Down Expand Up @@ -43,7 +43,8 @@ case "${op}" in
setenv-defaults ) backend_$WORKBENCH_BACKEND "$@";;
allocate-run ) backend_$WORKBENCH_BACKEND "$@";;
describe-run ) backend_$WORKBENCH_BACKEND "$@";;
start-cluster ) backend_$WORKBENCH_BACKEND "$@";;
start ) backend_$WORKBENCH_BACKEND "$@";;
start-nodes ) backend_$WORKBENCH_BACKEND "$@";;
start-node ) backend_$WORKBENCH_BACKEND "$@";;
stop-node ) backend_$WORKBENCH_BACKEND "$@";;
wait-node ) backend_$WORKBENCH_BACKEND "$@";;
Expand Down
8 changes: 6 additions & 2 deletions nix/workbench/lib-cabal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function workbench-prebuild-executables()

echo "workbench: prebuilding executables (because of useCabalRun)"
unset NIX_ENFORCE_PURITY
for exe in cardano-node cardano-cli cardano-topology tx-generator locli
for exe in cardano-node cardano-cli cardano-topology cardano-tracer tx-generator locli
do echo "workbench: $(with_color blue prebuilding) $(with_color red $exe)"
cabal -v0 build -- exe:$exe 2>&1 >/dev/null |
{ grep -v 'exprType TYPE'; true; } || return 1
Expand All @@ -30,6 +30,10 @@ function cardano-topology() {
cabal -v0 run exe:cardano-topology -- "$@"
}

function cardano-tracer() {
cabal -v0 run exe:cardano-tracer -- "$@"
}

function locli() {
cabal -v0 build exe:locli
set-git-rev \
Expand All @@ -44,4 +48,4 @@ function tx-generator() {

export WORKBENCH_CABAL_MODE=t

export -f cardano-cli cardano-node cardano-topology locli tx-generator
export -f cardano-cli cardano-node cardano-topology cardano-tracer locli tx-generator
16 changes: 12 additions & 4 deletions nix/workbench/profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ case "$op" in
' --exit-status --arg name "$name" >/dev/null
;;

## XXX: does not respect overlays!!
compose )
local profile_names="$@"

Expand All @@ -64,10 +65,17 @@ case "$op" in
local usage="USAGE: wb profile $op [NAME=<current-shell-profile>"
local name=${1:-${WORKBENCH_SHELL_PROFILE:?variable unset, no profile name to use as a default.}}

if test -f "$name"
then jq '.' "$name"
else profile generate-all |
jq '.["'$name'"]'
local json=$(if test -f "$name"
then jq '.' "$name"
else profile generate-all |
jq '.["'$name'"]'
fi)

local preset=$(jq -r '.preset // ""' <<<$json)
local preset_overlay=$global_basedir/profiles/presets/$preset/overlay.json
if test -z "$preset" -o ! -f $preset_overlay
then echo "$json"
else jq '. * $overlay[0]' <<<$json --slurpfile overlay $preset_overlay
fi;;

describe )
Expand Down
4 changes: 4 additions & 0 deletions nix/workbench/profiles/presets/mainnet/overlay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{ "genesis":
{ "network_magic": 764824073
}
}
2 changes: 2 additions & 0 deletions nix/workbench/profiles/tracer-service.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ let
## In both the local and remote scenarios, it's most frequently convenient to act as an acceptor.
acceptingSocket = "tracer.socket";

networkMagic = profile.value.genesis.network_magic;

## logRoot = ## ..really depends on context -- available in backend.finaliseTracerService

dsmPassthrough = {
Expand Down
33 changes: 20 additions & 13 deletions nix/workbench/scenario.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,38 @@ local p=$dir/profile.json
progress "run | scenario" "starting $(yellow $op)"
case "$op" in
idle | default )
backend start-cluster "$dir"
backend start "$dir"
backend start-nodes "$dir"
;;

fixed )
backend start-cluster "$dir"
backend start "$dir"

scenario_setup_termination "$dir"
backend wait-pools-stopped "$dir"
scenario_setup_termination "$dir"
backend start-nodes "$dir"
backend wait-pools-stopped "$dir"
scenario_cleanup_termination

backend stop-cluster "$dir"
backend stop-cluster "$dir"
;;

loaded )
backend start-cluster "$dir"
backend start-generator "$dir"
backend start "$dir"
backend start-nodes "$dir"
backend start-generator "$dir"
;;

fixed-loaded )
backend start-cluster "$dir"
backend start-generator "$dir"
backend start "$dir"

scenario_setup_termination "$dir"
backend wait-pools-stopped "$dir"
backend start-nodes "$dir"
backend start-generator "$dir"

scenario_setup_termination "$dir"
backend wait-pools-stopped "$dir"
scenario_cleanup_termination

backend stop-cluster "$dir"
backend stop-cluster "$dir"
;;

chainsync )
Expand All @@ -73,8 +78,10 @@ case "$op" in
progress "scenario" "preparing ChainDB for the $(green server node)"
chaindb "${chaindb_server[@]}"

backend start "$dir"

progress "scenario" "starting the $(yellow ChainDB server node)"
backend start-cluster "$dir"
backend start-node "$dir" 'node-0'

progress "scenario" "starting the $(yellow fetcher node)"
backend start-node "$dir" 'node-1'
Expand Down
3 changes: 1 addition & 2 deletions nix/workbench/supervisor-conf.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ let
stdout_logfile = "${service.value.stateDir}/stdout";
stderr_logfile = "${service.value.stateDir}/stderr";
startretries = 0;
autostart = nodeSpec.value.autostart
or true; ## Backward compatibility for profiles coming from old pinned workbench.
autostart = false;
autorestart = false;
};

Expand Down
33 changes: 28 additions & 5 deletions nix/workbench/supervisor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ case "$op" in

setenvjq 'port_shift_ekg' 100
setenvjq 'port_shift_prometheus' 200
setenvjq 'port_shift_rtview' 300
setenvjqstr 'supervisor_conf' "$profile_dir"/supervisor.conf
;;

Expand All @@ -51,8 +52,10 @@ case "$op" in
local basePort=$( envjq 'basePort')
local port_ekg=$(( basePort+$(envjq 'port_shift_ekg')))
local port_prometheus=$((basePort+$(envjq 'port_shift_prometheus')))
local port_rtview=$(( basePort+$(envjq 'port_shift_rtview')))

cat <<EOF
- RTView URL: http://localhost:$port_rtview
- EKG URL (node-0): http://localhost:$port_ekg/
- Prometheus URL (node-0): http://localhost:$port_prometheus/metrics
EOF
Expand Down Expand Up @@ -98,13 +101,20 @@ EOF
echo " $node up (${i}s)" >&2
;;

start-cluster )
local usage="USAGE: wb supervisor $op RUN-DIR"
start-nodes )
local usage="USAGE: wb supervisor $op RUN-DIR [HONOR_AUTOSTART=]"
local dir=${1:?$usage}; shift
local honor_autostart=${1:-}

supervisord --config "$dir"/supervisor/supervisord.conf $@
local nodes=($(jq_tolist keys "$dir"/node-specs.json))

for node in $(jq_tolist keys "$dir"/node-specs.json)
if test -n "$honor_autostart"
then for node in ${nodes[*]}
do jqtest ".\"$node\".autostart" "$dir"/node-specs.json &&
supervisorctl start $node; done;
else supervisorctl start ${nodes[*]}; fi

for node in ${nodes[*]}
do jqtest ".\"$node\".autostart" "$dir"/node-specs.json &&
backend_supervisor wait-node "$dir" $node; done

Expand All @@ -113,7 +123,20 @@ EOF
fi

backend_supervisor save-child-pids "$dir"
backend_supervisor save-pid-maps "$dir";;
backend_supervisor save-pid-maps "$dir"
;;

start )
local usage="USAGE: wb supervisor $op RUN-DIR"
local dir=${1:?$usage}; shift

supervisord --config "$dir"/supervisor/supervisord.conf $@

if jqtest ".node.tracer" "$dir"/profile.json
then progress_ne "supervisor" "waiting for $(yellow cardano-tracer) to create socket: "
while test ! -e "$dir"/tracer/tracer.socket; do sleep 1; done
echo $(green ' OK') >&2
fi;;

get-node-socket-path )
local usage="USAGE: wb supervisor $op STATE-DIR NODE-NAME"
Expand Down

0 comments on commit ab3da99

Please sign in to comment.