Skip to content

Commit

Permalink
Collect timing metrics for CI jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Jul 4, 2018
1 parent 4b07772 commit 72ab83c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .buildkite/hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CI_BUILD_START=$(date +%s)
export CI_BUILD_START
1 change: 1 addition & 0 deletions .buildkite/hooks/post-checkout.sh
54 changes: 45 additions & 9 deletions .buildkite/hooks/post-command
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .buildkite/hooks/post-command.sh
4 changes: 2 additions & 2 deletions .buildkite/hooks/pre-command
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
)
1 change: 1 addition & 0 deletions .buildkite/hooks/pre-command.sh

0 comments on commit 72ab83c

Please sign in to comment.