diff --git a/tools/block-generator/Makefile b/tools/block-generator/Makefile index 496a7fc99a..fdb5754210 100644 --- a/tools/block-generator/Makefile +++ b/tools/block-generator/Makefile @@ -12,7 +12,7 @@ clean-generator: rm -f block-generator debug-blockgen: - python run_runner.py \ + python scripts/run_runner.py \ --conduit-binary ./conduit \ --scenario $(SCENARIO) \ --report-directory $(REPORTS) \ @@ -38,7 +38,7 @@ run-runner: block-generator --report-directory $(REPORTS) clean-reports: - rm -rf $(REPORTS) + rm -rf $(REPORTS) pre-git-push: mv _go.mod go.mod diff --git a/tools/block-generator/README.md b/tools/block-generator/README.md index 544dc80091..a26328ec43 100644 --- a/tools/block-generator/README.md +++ b/tools/block-generator/README.md @@ -170,7 +170,7 @@ Flags: -v, --verbose If set the runner will print debugging information from the generator and ledger. ``` -## Example Run using Conduit and Postgres in **bash** via `run_runner.sh` +## Example Run using Conduit and Postgres A typical **runner** scenario involves: @@ -179,30 +179,30 @@ A typical **runner** scenario involves: * a datastore -such as a postgres database- to collect `conduit`'s output * a `conduit` config file to define its import/export behavior -`run_runner.sh` makes the following choices for the previous bullet points: - -* it can accept any scenario as its second argument, but defaults to [test_config.yml](./test_config.yml) when this isn't provided (this is a scenario with a lifetime of ~30 seconds) -* knows how to import through a mock Algod running on port 11112 (which is the port the runner avails) -* sets up a dockerized postgres database to receive conduit's output -* configures `conduit` for these specs using [this config template](./runner/template/conduit.yml.tmpl) +The `block-generator runner` subcommand has a number of options to configure behavion. ### Sample Run First you'll need to get a `conduit` binary. For example you can follow the [developer portal's instructions](https://developer.algorand.org/docs/get-details/conduit/GettingStarted/#installation) or run `go build .` inside of the directory `cmd/conduit` after downloading the `conduit` repo. -Assume you've navigated to the `tools/block-generator` directory of -the `go-algorand` repo, and: +Run `make install` from the `go-algorand` root, this should add `block-generator` to your path. -* saved the conduit binary to `tools/block-generator/conduit` -* created a block generator scenario config at `tools/block-generator/scenario.yml` +Start a postgres container using `scripts/run_postgres.sh`. This starts a container on port 15432 a database named generator_db and a user with credentials algorand/algorand. -Then you can execute the following command to run the scenario: +Now run `block-generator runner` to run the test: ```sh -./run_runner.sh ./conduit scenario.yml +block-generator runner \ + --conduit-binary "$CONDUIT_BINARY" \ + --report-directory reports \ + --test-duration 30s \ + --conduit-log-level trace \ + --postgres-connection-string "host=localhost user=algorand password=algorand dbname=generator_db port=15432 sslmode=disable" \ + --scenario generator/test_scenario.yml \ + --reset-db ``` ### Scenario Report -If all goes well, the run will generate a directory `../../tmp/OUTPUT_RUN_RUNNER_TEST` -and in that directory you can see the statistics of the run in `scenario.report`. +If all goes well, the run will generate a directory named reports. +In that directory you can see the statistics of the run in the file ending with `.report`. diff --git a/tools/block-generator/generator/config_test.go b/tools/block-generator/generator/config_test.go index bfdc695951..a595ad6d69 100644 --- a/tools/block-generator/generator/config_test.go +++ b/tools/block-generator/generator/config_test.go @@ -27,7 +27,7 @@ import ( func TestInitConfigFile(t *testing.T) { partitiontest.PartitionTest(t) - config, err := initializeConfigFile("../test_config.yml") + config, err := initializeConfigFile("test_scenario.yml") require.NoError(t, err) require.Equal(t, uint64(10), config.NumGenesisAccounts) require.Equal(t, float32(0.25), config.AssetCloseFraction) diff --git a/tools/block-generator/test_config.yml b/tools/block-generator/generator/test_scenario.yml similarity index 100% rename from tools/block-generator/test_config.yml rename to tools/block-generator/generator/test_scenario.yml diff --git a/tools/block-generator/run_tests.sh b/tools/block-generator/run_tests.sh deleted file mode 100755 index 48c1490b40..0000000000 --- a/tools/block-generator/run_tests.sh +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bash - -CONNECTION_STRING="" -CONDUIT_BINARY="" -REPORT_DIR="" -DURATION="1h" -LOG_LEVEL="error" -SCENARIOS="" - -help() { - echo "Usage:" - echo " -v|--verbose enable verbose script output." - echo " -c|--connection-string" - echo " PostgreSQL connection string." - echo " -i|--conduit path to conduit binary." - echo " -s|--scenarios path to conduit test scenarios." - echo " -r|--report-dir directory where the report should be written." - echo " -d|--duration test duration." - echo " -l|--level log level to pass to conduit." - echo " -g|--generator block-generator binary to run the generator." - exit -} - -while :; do - case "${1-}" in - -h | --help) help ;; - -v | --verbose) set -x ;; - -c | --connection-string) - CONNECTION_STRING="${2-}" - shift - ;; - -g | --generator) - GENERATOR_BINARY="${2-}" - shift - ;; - -i | --conduit) - CONDUIT_BINARY="${2-}" - shift - ;; - -r | --report-dir) - REPORT_DIR="${2-}" - shift - ;; - -s | --scenarios) - SCENARIOS="${2-}" - shift - ;; - -d | --duration) - DURATION="${2-}" - shift - ;; - -l | --level) - LOG_LEVEL="${2-}" - shift - ;; - -?*) echo "Unknown option: $1" && exit 1;; - *) break ;; - esac - shift -done - -args=("$@") - -if [ -z "$CONNECTION_STRING" ]; then - echo "Missing required connection string parameter (-c / --connection-string)." - exit 1 -fi - -if [ -z "$CONDUIT_BINARY" ]; then - echo "Missing required conduit binary parameter (-i / --conduit)." - exit 1 -fi - -if [ -z "$SCENARIOS" ]; then - echo "Missing required conduit test scenario parameter (-s / --scenarios)." - exit 1 -fi - -if [ -z "$GENERATOR_BINARY" ]; then - echo "path to block-generator binary is required" - exit 1 -fi - -echo "Running with binary: $CONDUIT_BINARY" -echo "Report directory: $REPORT_DIR" -echo "Duration: $DURATION" -echo "Log Level: $LOG_LEVEL" - -"$GENERATOR_BINARY" runner \ - -i "$CONDUIT_BINARY" \ - -s "$SCENARIOS" \ - -d "$DURATION" \ - -c "$CONNECTION_STRING" \ - --report-directory "$REPORT_DIR" \ - --conduit-log-level "$LOG_LEVEL" \ - --reset-report-dir - diff --git a/tools/block-generator/print_tps.py b/tools/block-generator/scripts/print_tps.py similarity index 100% rename from tools/block-generator/print_tps.py rename to tools/block-generator/scripts/print_tps.py diff --git a/tools/block-generator/run_postgres.sh b/tools/block-generator/scripts/run_postgres.sh similarity index 94% rename from tools/block-generator/run_postgres.sh rename to tools/block-generator/scripts/run_postgres.sh index 2c8175bb9c..490404aff3 100755 --- a/tools/block-generator/run_postgres.sh +++ b/tools/block-generator/scripts/run_postgres.sh @@ -14,8 +14,6 @@ set -e POSTGRES_CONTAINER=generator-test-container POSTGRES_PORT=15432 POSTGRES_DATABASE=generator_db -CONFIG=${1:-"$(dirname $0)/test_config.yml"} -echo "Using config file: $CONFIG" function start_postgres() { docker rm -f $POSTGRES_CONTAINER > /dev/null 2>&1 || true diff --git a/tools/block-generator/run_runner.py b/tools/block-generator/scripts/run_runner.py similarity index 98% rename from tools/block-generator/run_runner.py rename to tools/block-generator/scripts/run_runner.py index 914a38d467..5f0753930b 100644 --- a/tools/block-generator/run_runner.py +++ b/tools/block-generator/scripts/run_runner.py @@ -82,7 +82,7 @@ def parse_args(): parser.add_argument("--conduit-binary", help="Path to conduit binary") parser.add_argument( "--scenario", - default=(default := CWD / "test_config.yml"), + default=(default := CWD.parents[1] / "test_scenario.yml"), help=f"Scenario configuration file ({default=!s})", ) parser.add_argument( diff --git a/tools/block-generator/run_runner.sh b/tools/block-generator/scripts/run_runner.sh similarity index 77% rename from tools/block-generator/run_runner.sh rename to tools/block-generator/scripts/run_runner.sh index 236d7b2bbb..5643ab9c86 100755 --- a/tools/block-generator/run_runner.sh +++ b/tools/block-generator/scripts/run_runner.sh @@ -15,7 +15,7 @@ fi POSTGRES_CONTAINER=generator-test-container POSTGRES_PORT=15432 POSTGRES_DATABASE=generator_db -SCENARIO=${2:-"$(dirname $0)/test_config.yml"} +SCENARIO=${2:-"$(dirname $0)/../test_scenario.yml"} echo "Using scenario config file: $SCENARIO" function start_postgres() { @@ -51,10 +51,10 @@ echo "Starting postgres container." start_postgres echo "Starting test runner" $(dirname "$0")/block-generator runner \ - --conduit-binary "$CONDUIT_BINARY" \ - --report-directory $OUTPUT \ - --test-duration 30s \ - --conduit-log-level trace \ - --postgres-connection-string "host=localhost user=algorand password=algorand dbname=generator_db port=15432 sslmode=disable" \ - --scenario ${SCENARIO} \ + --conduit-binary "$CONDUIT_BINARY" \ + --report-directory $OUTPUT \ + --test-duration 30s \ + --conduit-log-level trace \ + --postgres-connection-string "host=localhost user=algorand password=algorand dbname=generator_db port=15432 sslmode=disable" \ + --scenario ${SCENARIO} \ --reset-db