From 72ab83cd455c8745fe02731c07c0bf9a8e34d4ac Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Wed, 4 Jul 2018 10:26:32 -0700 Subject: [PATCH] Collect timing metrics for CI jobs --- .buildkite/hooks/post-checkout | 2 ++ .buildkite/hooks/post-checkout.sh | 1 + .buildkite/hooks/post-command | 54 +++++++++++++++++++++++++------ .buildkite/hooks/post-command.sh | 1 + .buildkite/hooks/pre-command | 4 +-- .buildkite/hooks/pre-command.sh | 1 + 6 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 .buildkite/hooks/post-checkout create mode 120000 .buildkite/hooks/post-checkout.sh mode change 100755 => 100644 .buildkite/hooks/post-command create mode 120000 .buildkite/hooks/post-command.sh mode change 100755 => 100644 .buildkite/hooks/pre-command create mode 120000 .buildkite/hooks/pre-command.sh diff --git a/.buildkite/hooks/post-checkout b/.buildkite/hooks/post-checkout new file mode 100644 index 00000000000000..32d88815f55764 --- /dev/null +++ b/.buildkite/hooks/post-checkout @@ -0,0 +1,2 @@ +CI_BUILD_START=$(date +%s) +export CI_BUILD_START diff --git a/.buildkite/hooks/post-checkout.sh b/.buildkite/hooks/post-checkout.sh new file mode 120000 index 00000000000000..5513d1deed309e --- /dev/null +++ b/.buildkite/hooks/post-checkout.sh @@ -0,0 +1 @@ +post-checkout \ No newline at end of file diff --git a/.buildkite/hooks/post-command b/.buildkite/hooks/post-command old mode 100755 new mode 100644 index d847b1bf36b610..9babfaf6600405 --- a/.buildkite/hooks/post-command +++ b/.buildkite/hooks/post-command @@ -1,14 +1,50 @@ #!/bin/bash -e -[[ -n "$CARGO_TARGET_CACHE_NAME" ]] || exit 0 - # # Save target/ for the next CI build on this machine # -( - d=$HOME/cargo-target-cache/"$CARGO_TARGET_CACHE_NAME" - mkdir -p $d - set -x - rsync -a --delete --link-dest=$PWD target $d - du -hs $d -) +if [[ -n $CARGO_TARGET_CACHE_NAME ]]; then + ( + d=$HOME/cargo-target-cache/"$CARGO_TARGET_CACHE_NAME" + mkdir -p "$d" + set -x + rsync -a --delete --link-dest="$PWD" target "$d" + du -hs "$d" + ) +fi + +# +# Add job_stats data point +# +if [[ -z $CI_BUILD_START ]]; then + echo Error: CI_BUILD_START empty +else + CI_BUILD_DURATION=$(( $(date +%s) - CI_BUILD_START + 1 )) + + CI_LABEL=${BUILDKITE_LABEL:-build label missing} + + PR=false + if [[ $BUILDKITE_BRANCH =~ pull/* ]]; then + PR=true + fi + + SUCCESS=true + if [[ $BUILDKITE_COMMAND_EXIT_STATUS != 0 ]]; then + SUCCESS=false + fi + + point_tags="pipeline=$BUILDKITE_PIPELINE_SLUG,job=$CI_LABEL,pr=$PR,success=$SUCCESS" + point_tags="${point_tags// /\\ }" # Escape spaces + + point_fields="duration=$CI_BUILD_DURATION" + point_fields="${point_fields// /\\ }" # Escape spaces + + point="job_stats,$point_tags $point_fields" + echo "Influx data point: $point" + if [[ -n $INFLUX_USERNAME && -n $INFLUX_PASSWORD ]]; then + echo "https://metrics.solana.com:8086/write?db=ci&u=${INFLUX_USERNAME}&p=${INFLUX_PASSWORD}" \ + | xargs curl -XPOST --data-binary "$point" + else + echo Influx user credentials not found + fi +fi diff --git a/.buildkite/hooks/post-command.sh b/.buildkite/hooks/post-command.sh new file mode 120000 index 00000000000000..0f24e303107028 --- /dev/null +++ b/.buildkite/hooks/post-command.sh @@ -0,0 +1 @@ +post-command \ No newline at end of file diff --git a/.buildkite/hooks/pre-command b/.buildkite/hooks/pre-command old mode 100755 new mode 100644 index 55d249850eec42..bed5503fa58abb --- a/.buildkite/hooks/pre-command +++ b/.buildkite/hooks/pre-command @@ -7,7 +7,7 @@ # ( d=$HOME/cargo-target-cache/"$CARGO_TARGET_CACHE_NAME" - mkdir -p $d/target + mkdir -p "$d"/target set -x - rsync -a --delete --link-dest=$d $d/target . + rsync -a --delete --link-dest="$d" "$d"/target . ) diff --git a/.buildkite/hooks/pre-command.sh b/.buildkite/hooks/pre-command.sh new file mode 120000 index 00000000000000..25964dd4a6d9ef --- /dev/null +++ b/.buildkite/hooks/pre-command.sh @@ -0,0 +1 @@ +pre-command \ No newline at end of file