feat: add default options to Codex, enable metrics on experiment scope

This commit is contained in:
gmega 2025-06-23 15:40:21 -03:00
parent 75ee562d2f
commit c678ba6de2
No known key found for this signature in database
GPG Key ID: 6290D34EAD824B18
5 changed files with 57 additions and 13 deletions

View File

@ -40,6 +40,8 @@ _cdx_timing_prefix=""
# Log file where timings are aggregated
_cdx_timing_log="/dev/null"
_cdx_defaultopts=()
# Base ports and timeouts
_cdx_base_api_port=8080
_cdx_base_disc_port=8190
@ -64,28 +66,39 @@ _cdx_metrics_port() {
echo $((_cdx_base_metrics_port + node_index))
}
cdx_add_defaultopts() {
_cdx_defaultopts+=("$@")
}
cdx_clear_defaultopts() {
_cdx_defaultopts=()
}
cdx_cmdline() {
local node_index spr cdx_cmd="${_cdx_binary} --nat:none"
local node_index spr cdx_cmd="${_cdx_binary} --nat:none" opts=("$@")
node_index="$1"
shift
opts+=("${_cdx_defaultopts[@]}")
while [[ "$#" -gt 0 ]]; do
case "$1" in
node_index="${opts[0]}"
shift_arr opts
while [[ "${#opts[@]}" -gt 0 ]]; do
opt="${opts[0]}"
case "$opt" in
--bootstrap-node)
shift
spr="$1"
shift_arr opts
spr="${opts[0]}"
cdx_cmd="${cdx_cmd} --bootstrap-node=$spr"
;;
--metrics)
cdx_cmd="${cdx_cmd} --metrics --metrics-port=$(_cdx_metrics_port "$node_index") --metrics-address=0.0.0.0"
;;
*)
echoerr "Error: unknown option $1"
echoerr "Error: unknown option $opt"
return 1
;;
esac
shift
shift_arr opts
done
if [[ "$node_index" -gt 0 && -z "$spr" ]]; then

View File

@ -1,12 +1,21 @@
#!/usr/bin/env bash
set -o pipefail
LIB_SRC=${LIB_SRC:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}
# shellcheck source=./src/utils.bash
source "${LIB_SRC}/utils.bash"
# shellcheck source=./src/codex.bash
source "${LIB_SRC}/codex.bash"
_experiment_type=""
_experiment_id=""
exp_start() {
_experiment_type="$1"
local experiment_id experiment_type="$1"
experiment_id="${experiment_type}-$(date +%s)-${RANDOM}" || return 1
# FIXME: this is pretty clumsy/confusing. We're "initing" the
# harness just so it sets the base output folder, and then
# "initing" it again.
@ -14,5 +23,9 @@ exp_start() {
clh_init
fi
clh_init "${_clh_output}/${_experiment_type}-$(date +%s)-${RANDOM}" || return 1
_experiment_id="${experiment_id}"
_experiment_type="${experiment_type}"
clh_init "${_clh_output}/${_experiment_id}" || return 1
cdx_add_defaultopts "--metrics"
}

View File

@ -25,6 +25,11 @@ echoerr() {
echo "$@" >&2
}
shift_arr () {
local -n arr_ref="$1"
arr_ref=("${arr_ref[@]:1}")
}
sha1() {
sha1sum "$1" | cut -d ' ' -f 1 || return 1
}

View File

@ -38,6 +38,18 @@ setup() {
" --api-port=8080 --disc-port=8190 --log-level=INFO"
}
@test "should allow setting of global default options" {
! [[ "$(cdx_cmdline 0)" =~ "--metrics --metrics-port=8290 --metrics-address=0.0.0.0" ]]
cdx_add_defaultopts "--metrics"
[[ "$(cdx_cmdline 0)" =~ "--metrics --metrics-port=8290 --metrics-address=0.0.0.0" ]]
cdx_clear_defaultopts
! [[ "$(cdx_cmdline 0)" =~ "--metrics --metrics-port=8290 --metrics-address=0.0.0.0" ]]
}
@test "should fail readiness check if node is not running" {
refute cdx_ensure_ready 0 1
}

View File

@ -5,7 +5,8 @@ common_setup() {
export LIB_SRC="${BATS_TEST_DIRNAME}/../src"
# shellcheck source=./src/clh
source "${LIB_SRC}/clh"
# shellcheck source=./src/utils.bash
source "${LIB_SRC}/utils.bash"
clh_init "${LIB_SRC}/../test_outputs"
}