-
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.
Merge pull request #2 from better/feature/support-additional-vars
- Loading branch information
Showing
20 changed files
with
314 additions
and
57 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
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,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
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 checkout run time" | ||
|
||
METRIC_NAME=$(getMetricName "checkout.duration") | ||
METRIC_VALUE=$(timeDiff "$BUILDKITE_PLUGIN_DATADOG_STATS_CHECKOUT_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 |
---|---|---|
@@ -1,21 +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) | ||
START_TIME=$BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS | ||
BASE_METRIC_PATH=${BUILDKITE_PLUGIN_DATADOG_STATS_METRIC_PREFIX:-buildkite.steps} | ||
|
||
echo "--- :datadog: Recording command run time" | ||
|
||
METRIC_NAME=${BASE_METRIC_PATH}.duration | ||
METRIC_VALUE=$(($NOW-$START_TIME)) | ||
METRIC_NAME=$(getMetricName "command.duration") | ||
METRIC_VALUE=$(timeDiff "$BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS") | ||
TAGS=$(getTags) | ||
|
||
echo "Reporting ${METRIC_NAME} as ${METRIC_VALUE} with tags ${TAGS} to datadog" | ||
|
||
reportToDatadog $METRIC_NAME $METRIC_VALUE d "${TAGS}" | ||
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,11 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
echo "--- :datadog: Recording checkout start time" | ||
|
||
BUILDKITE_PLUGIN_DATADOG_STATS_CHECKOUT_START_TIME_MS=$(date +%s%3N) | ||
|
||
export BUILDKITE_PLUGIN_DATADOG_STATS_CHECKOUT_START_TIME_MS | ||
|
||
echo "Checkout started at ${BUILDKITE_PLUGIN_DATADOG_STATS_CHECKOUT_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
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,6 @@ | ||
#!/bin/bash | ||
|
||
function getMetricName() { | ||
local BASE_METRIC_PATH=${BUILDKITE_PLUGIN_DATADOG_STATS_METRIC_PREFIX:-buildkite.steps} | ||
echo -n "${BASE_METRIC_PATH}.${1}" | ||
} |
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,8 @@ | ||
#!/bin/bash | ||
|
||
function timeDiff() { | ||
START_TIME=$1 | ||
NOW=$(date +%s%3N) | ||
|
||
echo -n $((NOW-START_TIME)) | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/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_COMMAND_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-command" | ||
|
||
assert_success | ||
assert_output --partial "Reporting buildkite.steps.command.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 | ||
} | ||
|
||
@test "Sets the correct tags and runtime for a non-master branch" { | ||
NOW=$(date +%s%3N) | ||
export BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS=$((NOW-900)) | ||
export BUILDKITE_BRANCH=some-branch | ||
export BUILDKITE_PIPELINE_SLUG=monorepo | ||
export BUILDKITE_COMMAND="cd somewhere && make do-something" | ||
export BUILDKITE_LABEL=":shipit: deploy-prod" | ||
|
||
run "$PWD/hooks/post-command" | ||
|
||
assert_success | ||
assert_output --partial "Reporting buildkite.steps.command.duration with value=90" | ||
assert_output --partial "tags=is_master:false,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 | ||
} | ||
|
||
@test "It supports specifying additional tags by value and env var" { | ||
NOW=$(date +%s%3N) | ||
export BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS=$((NOW-900)) | ||
export BUILDKITE_BRANCH=some-branch | ||
export BUILDKITE_PIPELINE_SLUG=monorepo | ||
export BUILDKITE_COMMAND="cd somewhere && make do-something" | ||
export BUILDKITE_LABEL=":shipit: deploy-prod" | ||
export BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_0_TAG="my-tag" | ||
export BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_0_ENV_VAR="MY_ENV_VAR" | ||
export MY_ENV_VAR="my-tag-value" | ||
export BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_1_TAG="my-other-tag" | ||
export BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_1_VALUE="my-other-tag-value" | ||
|
||
run "$PWD/hooks/post-command" | ||
|
||
assert_success | ||
assert_output --partial "Reporting buildkite.steps.command.duration with value=90" | ||
assert_output --partial "tags=is_master:false,pipeline_slug:monorepo,step_command:cd somewhere && make do-something,step_label::shipit: deploy-prod,retry_count:0,my-tag:my-tag-value,my-other-tag:my-other-tag-value" | ||
|
||
unset BUILDKITE_PLUGIN_DATADOG_STATS_COMMAND_START_TIME_MS | ||
unset BUILDKITE_BRANCH | ||
unset BUILDKITE_PIPELINE_SLUG | ||
unset BUILDKITE_COMMAND | ||
unset BUILDKITE_LABEL | ||
unset BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_0_TAG | ||
unset BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_0_ENV_VAR | ||
unset MY_ENV_VAR | ||
unset BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_1_TAG | ||
unset BUILDKITE_PLUGIN_DATADOG_STATS_ADDITIONAL_TAGS_1_VALUE | ||
} |
Oops, something went wrong.