@@ -39,6 +39,43 @@ function err_report () {
39
39
40
40
trap ' err_report $LINENO' ERR
41
41
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
+
42
79
function retry {
43
80
local retries=7
44
81
local count=0
0 commit comments