From 5768c8acda0d7b7960a34eeeca36760117df36af Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 14 Aug 2023 15:30:13 -0400 Subject: [PATCH 1/4] Add a script to run compare using the docker image. --- Makefile | 5 +++ scripts/run_docker_compare.bash | 46 ++++++++++++++++++++++++ scripts/run_docker_integration_test.bash | 3 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100755 scripts/run_docker_compare.bash diff --git a/Makefile b/Makefile index 2eb2466..dcfb540 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,11 @@ dockertest: > $(MAKE) -C docker/organic_test > docker run --rm -i -t -v "$$(readlink -f ./):/.source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry -w / organic-test sh -c "cp -r /.source /source && cd /source && cargo test --no-fail-fast --lib --test test_loader" +.PHONY: dockerclean +dockerclean: +# Delete volumes created for running the tests in docker. This does not touch anything related to the jaeger docker container. +> docker volume rm cargo-cache rust-cache + .PHONY: integrationtest integrationtest: > cargo test --no-fail-fast --test test_loader -- --test-threads $(TESTJOBS) diff --git a/scripts/run_docker_compare.bash b/scripts/run_docker_compare.bash new file mode 100755 index 0000000..a36f428 --- /dev/null +++ b/scripts/run_docker_compare.bash @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +# +set -euo pipefail +IFS=$'\n\t' +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +: ${SHELL:="NO"} # or YES to launch a shell instead of running the test + +cd "$DIR/../" +REALPATH=$(command -v uu-realpath || command -v realpath) +MAKE=$(command -v gmake || command -v make) + +function main { + local org_file="$($REALPATH "$1")" + build_container + launch_container "$org_file" +} + +function build_container { + $MAKE -C "$DIR/../docker/organic_test" +} + +function launch_container { + local org_file="$1" + local additional_flags=() + local additional_args=() + + local init_script=$(cat < Date: Mon, 14 Aug 2023 15:50:05 -0400 Subject: [PATCH 2/4] Clean up run_docker_integration_test.bash --- scripts/run_docker_compare.bash | 6 ++- scripts/run_docker_integration_test.bash | 48 ++++++++++++++++++------ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/scripts/run_docker_compare.bash b/scripts/run_docker_compare.bash index a36f428..a4f1236 100755 --- a/scripts/run_docker_compare.bash +++ b/scripts/run_docker_compare.bash @@ -29,7 +29,6 @@ function launch_container { set -euo pipefail IFS=\$'\n\t' -cd /source export CARGO_TARGET_DIR=/target cargo run -- /input.org EOF @@ -40,7 +39,10 @@ EOF else additional_flags+=(-i -t) fi - docker run "${additional_flags[@]}" --rm -v "${org_file}:/input.org:ro" -v "$($REALPATH ./):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target -w / organic-test "${additional_args[@]}" + + # TODO: add support for reporting to jaeger with RUST_BACKTRACE=1 RUST_LOG=debug + + docker run "${additional_flags[@]}" --rm -v "${org_file}:/input.org:ro" -v "$($REALPATH ./):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target -w /source organic-test "${additional_args[@]}" } main "${@}" diff --git a/scripts/run_docker_integration_test.bash b/scripts/run_docker_integration_test.bash index 549923e..4285fcc 100755 --- a/scripts/run_docker_integration_test.bash +++ b/scripts/run_docker_integration_test.bash @@ -4,17 +4,33 @@ set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$DIR/../" REALPATH=$(command -v uu-realpath || command -v realpath) +MAKE=$(command -v gmake || command -v make) -samples_dir=$(readlink -f "$DIR/../org_mode_samples") +function main { + local test_names=$(get_test_names "${@}") + build_container + + local test + while read test; do + launch_container "$test" + done<<<"$test_names" +} + +function build_container { + $MAKE -C "$DIR/../docker/organic_test" +} function get_test_names { + local test_file + local samples_dir=$($REALPATH "$DIR/../org_mode_samples") for test_file in "$@" do if [ -e "$test_file" ]; then - test_file_full_path=$(readlink -f "$test_file") - relative_to_samples=$($REALPATH --relative-to "$samples_dir" "$test_file_full_path") - without_extension="${relative_to_samples%.org}" + local test_file_full_path=$($REALPATH "$test_file") + local relative_to_samples=$($REALPATH --relative-to "$samples_dir" "$test_file_full_path") + local without_extension="${relative_to_samples%.org}" echo "${without_extension/\//_}" | tr '[:upper:]' '[:lower:]' else echo "$test_file" | tr '[:upper:]' '[:lower:]' @@ -22,11 +38,21 @@ function get_test_names { done } -make -C "$DIR/../docker/organic_test" +function launch_container { + local test="$1" + local additional_args=() -get_test_names "$@" | while read test; do - ( - cd "$DIR/../" - docker run --rm -v "$(readlink -f ./):/.source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry -w / organic-test sh -c "cp -r /.source /source && cd /source && cargo test --no-fail-fast --lib --test test_loader \"$test\" -- --show-output" - ) -done + local init_script=$(cat < Date: Mon, 14 Aug 2023 15:53:17 -0400 Subject: [PATCH 3/4] Clean up run_integration_test.bash. --- scripts/run_integration_test.bash | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/scripts/run_integration_test.bash b/scripts/run_integration_test.bash index 7a96aab..a8899f6 100755 --- a/scripts/run_integration_test.bash +++ b/scripts/run_integration_test.bash @@ -4,17 +4,27 @@ set -euo pipefail IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +cd "$DIR/../" REALPATH=$(command -v uu-realpath || command -v realpath) -samples_dir=$(readlink -f "$DIR/../org_mode_samples") +function main { + local test_names=$(get_test_names "${@}") + + local test + while read test; do + cargo test --no-fail-fast --test test_loader "$test" -- --show-output + done<<<"$test_names" +} function get_test_names { + local test_file + local samples_dir=$($REALPATH "$DIR/../org_mode_samples") for test_file in "$@" do if [ -e "$test_file" ]; then - test_file_full_path=$(readlink -f "$test_file") - relative_to_samples=$($REALPATH --relative-to "$samples_dir" "$test_file_full_path") - without_extension="${relative_to_samples%.org}" + local test_file_full_path=$($REALPATH "$test_file") + local relative_to_samples=$($REALPATH --relative-to "$samples_dir" "$test_file_full_path") + local without_extension="${relative_to_samples%.org}" echo "${without_extension/\//_}" | tr '[:upper:]' '[:lower:]' else echo "$test_file" | tr '[:upper:]' '[:lower:]' @@ -22,6 +32,4 @@ function get_test_names { done } -get_test_names "$@" | while read test; do - (cd "$DIR/../" && cargo test --no-fail-fast --test test_loader "$test" -- --show-output) -done +main "${@}" From 72b8fec1bef5494758bfc8d8bc051a6a55fe2792 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 14 Aug 2023 16:11:28 -0400 Subject: [PATCH 4/4] Add support for tracing in run_docker_compare.bash. --- scripts/run_docker_compare.bash | 14 +++++++++++--- scripts/run_docker_integration_test.bash | 3 +-- src/init_tracing.rs | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/run_docker_compare.bash b/scripts/run_docker_compare.bash index a4f1236..f316406 100755 --- a/scripts/run_docker_compare.bash +++ b/scripts/run_docker_compare.bash @@ -5,6 +5,8 @@ IFS=$'\n\t' DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" : ${SHELL:="NO"} # or YES to launch a shell instead of running the test +: ${TRACE:="NO"} # or YES to send traces to jaeger +: ${BACKTRACE:="NO"} # or YES to print a rust backtrace when panicking cd "$DIR/../" REALPATH=$(command -v uu-realpath || command -v realpath) @@ -29,7 +31,6 @@ function launch_container { set -euo pipefail IFS=\$'\n\t' -export CARGO_TARGET_DIR=/target cargo run -- /input.org EOF ) @@ -40,9 +41,16 @@ EOF additional_flags+=(-i -t) fi - # TODO: add support for reporting to jaeger with RUST_BACKTRACE=1 RUST_LOG=debug + if [ "$TRACE" = "YES" ]; then + # We use the host network so it can talk to jaeger hosted at 127.0.0.1 + additional_flags+=(--network=host --env RUST_LOG=debug) + fi - docker run "${additional_flags[@]}" --rm -v "${org_file}:/input.org:ro" -v "$($REALPATH ./):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target -w /source organic-test "${additional_args[@]}" + if [ "$BACKTRACE" = "YES" ]; then + additional_flags+=(--env RUST_BACKTRACE=full) + fi + + docker run "${additional_flags[@]}" --rm -v "${org_file}:/input.org:ro" -v "$($REALPATH ./):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test "${additional_args[@]}" } main "${@}" diff --git a/scripts/run_docker_integration_test.bash b/scripts/run_docker_integration_test.bash index 4285fcc..0f66eae 100755 --- a/scripts/run_docker_integration_test.bash +++ b/scripts/run_docker_integration_test.bash @@ -46,12 +46,11 @@ function launch_container { set -euo pipefail IFS=\$'\n\t' -export CARGO_TARGET_DIR=/target cargo test --no-fail-fast --lib --test test_loader "$test" -- --show-output EOF ) - docker run --rm -v "$($REALPATH ./):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target -w /source organic-test sh -c "$init_script" + docker run --rm -v "$($REALPATH ./):/source:ro" --mount source=cargo-cache,target=/usr/local/cargo/registry --mount source=rust-cache,target=/target --env CARGO_TARGET_DIR=/target -w /source organic-test sh -c "$init_script" } diff --git a/src/init_tracing.rs b/src/init_tracing.rs index 17b71f4..9b72926 100644 --- a/src/init_tracing.rs +++ b/src/init_tracing.rs @@ -15,7 +15,8 @@ pub fn init_telemetry() -> Result<(), Box> { // TODO: I think the endpoint can be controlled by the OTEL_EXPORTER_OTLP_TRACES_ENDPOINT env variable instead of hard-coded into this code base. Regardless, I am the only developer right now so I am not too concerned. let exporter = opentelemetry_otlp::new_exporter() .tonic() - .with_endpoint("http://localhost:4317/v1/traces"); + // Using "localhost" is broken inside the docker container when tracing + .with_endpoint("http://127.0.0.1:4317/v1/traces"); let tracer = opentelemetry_otlp::new_pipeline() .tracing()