Skip to content

Commit f4b48b2

Browse files
committed
Merge branch 'jeanschmidt/userdata_metrics' of https://github.com/pytorch/test-infra into jeanschmidt/userdata_metrics
2 parents 1adfa40 + 46b0db9 commit f4b48b2

File tree

1 file changed

+37
-0
lines changed
  • terraform-aws-github-runner/modules/runners-instances/templates

1 file changed

+37
-0
lines changed

terraform-aws-github-runner/modules/runners-instances/templates/user-data.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,43 @@ function err_report () {
3939

4040
trap 'err_report $LINENO' ERR
4141

42+
function metric_report () {
43+
local metric_name=$1
44+
local value=$2
45+
46+
# it is useful to not have a namespace and send all errors here, in case we can't get the environment for some reason
47+
# this should not be the case, as this environment variable is set externally
48+
# 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
49+
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "GHARunners/all" --value $value || true
50+
51+
local namespace="GHARunners/all"
52+
if [ ! -z "$environment"]; then
53+
namespace="GHARunners/$environment"
54+
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "GHARunners/all" --value $value || true
55+
fi
56+
57+
if [ ! -z "$INSTANCE_ID" ]; then
58+
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "$namespace" --value $value --dimensions "InstanceId=$INSTANCE_ID" || true
59+
fi
60+
if [ ! -z "$REGION" ]; then
61+
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "$namespace" --value $value --dimensions "Region=$REGION" || true
62+
fi
63+
if [ ! -z "$OS_ID" ]; then
64+
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "$namespace" --value $value --dimensions "os=$OS_ID" || true
65+
fi
66+
if [ ! -z "$OS_ID" ]; then
67+
aws cloudwatch put-metric-data --metric-name "$metric_name" --namespace "$namespace" --value $value --dimensions GHRunnerId=$GH_RUNNER_ID || true
68+
fi
69+
}
70+
71+
function err_report () {
72+
echo "Error on line $1"
73+
metric_report "linux_userdata.error" 1
74+
exit 1
75+
}
76+
77+
trap 'err_report $LINENO' ERR
78+
4279
function retry {
4380
local retries=7
4481
local count=0

0 commit comments

Comments
 (0)