Skip to content

Commit

Permalink
Merge branch 'jeanschmidt/userdata_metrics' of https://github.com/pyt…
Browse files Browse the repository at this point in the history
…orch/test-infra into jeanschmidt/userdata_metrics
  • Loading branch information
jeanschmidt committed Jul 4, 2024
2 parents 1adfa40 + 46b0db9 commit f4b48b2
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,43 @@ function err_report () {

trap 'err_report $LINENO' ERR

function metric_report () {
local metric_name=$1
local value=$2

# it is useful to not have a namespace and send all errors here, in case we can't get the environment for some reason
# this should not be the case, as this environment variable is set externally
# it is important to have the || true at the end, as we dont want to interrupt the scritp at failure and trigger an infinite loop
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "GHARunners/all" --value $value || true

local namespace="GHARunners/all"
if [ ! -z "$environment"]; then
namespace="GHARunners/$environment"
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "GHARunners/all" --value $value || true
fi

if [ ! -z "$INSTANCE_ID" ]; then
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "$namespace" --value $value --dimensions "InstanceId=$INSTANCE_ID" || true
fi
if [ ! -z "$REGION" ]; then
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "$namespace" --value $value --dimensions "Region=$REGION" || true
fi
if [ ! -z "$OS_ID" ]; then
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "$namespace" --value $value --dimensions "os=$OS_ID" || true
fi
if [ ! -z "$OS_ID" ]; then
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "$namespace" --value $value --dimensions GHRunnerId=$GH_RUNNER_ID || true
fi
}

function err_report () {
echo "Error on line $1"
metric_report "linux_userdata.error" 1
exit 1
}

trap 'err_report $LINENO' ERR

function retry {
local retries=7
local count=0
Expand Down

0 comments on commit f4b48b2

Please sign in to comment.