-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ethan Langevin
committed
May 14, 2020
1 parent
7e1f00d
commit 1597200
Showing
10 changed files
with
109 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
echo "--- :datadog: Recording step start time" | ||
|
||
BUILDKITE_PLUGIN_DATADOG_STATS_STEP_START_TIME_MS=$(date +%s%3N) | ||
|
||
export BUILDKITE_PLUGIN_DATADOG_STATS_STEP_START_TIME_MS | ||
|
||
echo "Step started at ${BUILDKITE_PLUGIN_DATADOG_STATS_STEP_START_TIME_MS}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
basedir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" | ||
|
||
# shellcheck source=lib/get-tags.sh | ||
. "$basedir/lib/get-tags.sh" | ||
# shellcheck source=lib/report-to-datadog.sh | ||
. "$basedir/lib/report-to-datadog.sh" | ||
# shellcheck source=lib/time-diff.sh | ||
. "$basedir/lib/time-diff.sh" | ||
# shellcheck source=lib/get-metric-name.sh | ||
. "$basedir/lib/get-metric-name.sh" | ||
|
||
NOW=$(date +%s%3N) | ||
|
||
echo "--- :datadog: Recording step run time" | ||
|
||
METRIC_NAME=$(getMetricName "step.duration") | ||
METRIC_VALUE=$(timeDiff "$BUILDKITE_PLUGIN_DATADOG_STATS_STEP_START_TIME_MS") | ||
TAGS=$(getTags) | ||
|
||
reportToDatadog "${METRIC_NAME}" "${METRIC_VALUE}" d "${TAGS}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "$BATS_PATH/load.bash" | ||
|
||
@test "Records the start time of the step" { | ||
run "$PWD/hooks/environment" | ||
|
||
assert_success | ||
assert_output --partial "Step started at $(date +%s)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "$BATS_PATH/load.bash" | ||
|
||
@test "Sets the correct tags and runtime for the master branch" { | ||
NOW=$(date +%s%3N) | ||
export BUILDKITE_PLUGIN_DATADOG_STATS_CHECKOUT_START_TIME_MS=$((NOW-900)) | ||
export BUILDKITE_BRANCH=master | ||
export BUILDKITE_PIPELINE_SLUG=monorepo | ||
export BUILDKITE_COMMAND="cd somewhere && make do-something" | ||
export BUILDKITE_LABEL=":shipit: deploy-prod" | ||
|
||
run "$PWD/hooks/post-checkout" | ||
|
||
assert_success | ||
assert_output --partial "Reporting buildkite.steps.checkout.duration with value=90" | ||
assert_output --partial "tags=is_master:true,pipeline_slug:monorepo,step_command:cd somewhere && make do-something,step_label::shipit: deploy-prod,retry_count:0" | ||
|
||
unset BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS | ||
unset BUILDKITE_BRANCH | ||
unset BUILDKITE_PIPELINE_SLUG | ||
unset BUILDKITE_COMMAND | ||
unset BUILDKITE_LABEL | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "$BATS_PATH/load.bash" | ||
|
||
@test "Records the start time of the checkout" { | ||
run "$PWD/hooks/pre-checkout" | ||
|
||
assert_success | ||
assert_output --partial "Checkout started at $(date +%s)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "$BATS_PATH/load.bash" | ||
|
||
@test "Sets the correct tags and runtime for the master branch" { | ||
NOW=$(date +%s%3N) | ||
export BUILDKITE_PLUGIN_DATADOG_STATS_STEP_START_TIME_MS=$((NOW-900)) | ||
export BUILDKITE_BRANCH=master | ||
export BUILDKITE_PIPELINE_SLUG=monorepo | ||
export BUILDKITE_COMMAND="cd somewhere && make do-something" | ||
export BUILDKITE_LABEL=":shipit: deploy-prod" | ||
|
||
run "$PWD/hooks/pre-exit" | ||
|
||
assert_success | ||
assert_output --partial "Reporting buildkite.steps.step.duration with value=90" | ||
assert_output --partial "tags=is_master:true,pipeline_slug:monorepo,step_command:cd somewhere && make do-something,step_label::shipit: deploy-prod,retry_count:0" | ||
|
||
unset BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS | ||
unset BUILDKITE_BRANCH | ||
unset BUILDKITE_PIPELINE_SLUG | ||
unset BUILDKITE_COMMAND | ||
unset BUILDKITE_LABEL | ||
} |