Skip to content

Commit 0412b6d

Browse files
scampkayman-mk
andauthored
feat: use Amazon Linux 2023 for runner manager instance (#1138)
## Description Adds support for Amazon Linux 2023 and removes the `dmesg` logs from Cloudwatch as it wasn't useful at all. Closes #1137 - [x] GitlabRunner is operating - [x] Cloudwatch logs are populated - [x] jobs form GitLab are processed - [x] no errors in log files found - [x] also works with the old default AMI (Amazon Linux 1 and 2) --------- Co-authored-by: Matthias Kay <[email protected]>
1 parent a6a2caf commit 0412b6d

File tree

2 files changed

+47
-42
lines changed

2 files changed

+47
-42
lines changed

template/logging.tftpl

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,53 @@ echo 'installing additional software for logging'
33
for i in {1..7}
44
do
55
echo "Attempt: ---- " $i
6-
yum install -y aws-cli awslogs jq && break || sleep 60
6+
yum install -y aws-cli rsyslog amazon-cloudwatch-agent jq && break || sleep 60
77
done
88

9-
# Inject the CloudWatch Logs configuration file contents
10-
cat > /etc/awslogs/awslogs.conf <<- EOF
11-
[general]
12-
state_file = /var/lib/awslogs/agent-state
13-
14-
[/var/log/dmesg]
15-
file = /var/log/dmesg
16-
log_stream_name = {instanceId}/dmesg
17-
log_group_name = ${log_group_name}
18-
initial_position = start_of_file
19-
20-
[/var/log/messages]
21-
file = /var/log/messages
22-
log_stream_name = {instanceId}/messages
23-
log_group_name = ${log_group_name}
24-
datetime_format = %b %d %H:%M:%S
25-
initial_position = start_of_file
26-
27-
[/var/log/user-data.log]
28-
file = /var/log/user-data.log
29-
log_stream_name = {instanceId}/user-data
30-
log_group_name = ${log_group_name}
31-
initial_position = start_of_file
9+
# Create the CloudWatch Logs configuration file
10+
cat > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json <<- EOF
11+
{
12+
"agent": {
13+
"run_as_user": "root"
14+
},
15+
"metrics": {
16+
"metrics_collected": {
17+
"cpu": {
18+
"measurement": [
19+
"cpu_usage_idle"
20+
],
21+
"metrics_collection_interval": 300,
22+
"totalcpu": true
23+
},
24+
"mem": {
25+
"measurement": [
26+
"mem_used_percent"
27+
],
28+
"metrics_collection_interval": 300
29+
}
30+
}
31+
},
32+
"logs": {
33+
"logs_collected": {
34+
"files": {
35+
"collect_list": [
36+
{
37+
"file_path": "/var/log/messages",
38+
"log_group_name": "${log_group_name}",
39+
"log_stream_name": "{instance_id}/messages"
40+
},
41+
{
42+
"file_path": "/var/log/user-data.log",
43+
"log_group_name": "${log_group_name}",
44+
"log_stream_name": "{instance_id}/user-data"
45+
}
46+
]
47+
}
48+
}
49+
}
50+
}
3251
3352
EOF
3453

35-
# Set the region to send CloudWatch Logs data to (the region where the instance is located)
36-
region=$(curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)
37-
sed -i -e "s/region = us-east-1/region = $region/g" /etc/awslogs/awscli.conf
38-
39-
# Replace instance id.
40-
instanceId=$(curl -s -H "X-aws-ec2-metadata-token: $token" http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .instanceId)
41-
sed -i -e "s/{instanceId}/$instanceId/g" /etc/awslogs/awslogs.conf
42-
43-
if grep -q ':2$' /etc/system-release-cpe ; then
44-
# AWS Linux 2 renamed the awslogs service to awslogsd and uses systemd
45-
systemctl enable awslogsd
46-
systemctl start awslogsd
47-
else
48-
service awslogs start
49-
chkconfig awslogs on
50-
fi
54+
systemctl --now enable rsyslog
55+
systemctl restart amazon-cloudwatch-agent

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ variable "runner_instance" {
135135
}
136136

137137
variable "runner_ami_filter" {
138-
description = "List of maps used to create the AMI filter for the Runner AMI. Must resolve to an Amazon Linux 1 or 2 image."
138+
description = "List of maps used to create the AMI filter for the Runner AMI. Must resolve to an Amazon Linux 1, 2 or 2023 image."
139139
type = map(list(string))
140140

141141
default = {
142-
name = ["amzn2-ami-hvm-2.*-x86_64-ebs"]
142+
name = ["al2023-ami-2023*-x86_64"]
143143
}
144144
}
145145

0 commit comments

Comments
 (0)