Skip to content

Commit

Permalink
Emit Runner info at the start of every job on self hosted linux runne…
Browse files Browse the repository at this point in the history
…rs (#5485)

Emits:
- Runner type
- Instance Type
- AMI ID
- AMI Name (if known)

Note: Hard coding the ami id->name mapping isn't ideal, we should get
the name dynamically. However, that requires granting the runners extra
permissions to read the AMI name so will add that as a follow up.

Sample output:
<img width="725" alt="image"
src="https://github.com/user-attachments/assets/d0933907-2f6c-4ade-aeb4-44fe5fe139b6">

Testing:
https://github.com/pytorch/pytorch-canary/actions/runs/10012762937/job/27679499479?pr=227
  • Loading branch information
ZainRizvi authored Jul 19, 2024
1 parent c8c45fb commit a979143
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ EOF
. /home/$USER_NAME/runner-scripts/utils.sh
sudo chown -R $USER_NAME:$USER_NAME /home/$USER_NAME/actions-runner
# Use the IDMS v2 token
token=\$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 600" -s)
# Use the token to fetch instance metadata
instance_id=\$(curl -H "X-aws-ec2-metadata-token: \$token" -s http://169.254.169.254/latest/meta-data/instance-id)
region=\$(curl -H "X-aws-ec2-metadata-token: \$token" -s http://169.254.169.254/latest/meta-data/placement/region)
runner_type=\$(aws ec2 describe-tags --filters "Name=resource-id,Values=\$instance_id" "Name=key,Values=RunnerType" --query 'Tags[0].Value' --output text --region \$region)
instance_type=\$(curl -H "X-aws-ec2-metadata-token: \$token" -s http://169.254.169.254/latest/meta-data/instance-type)
ami_id=\$(curl -H "X-aws-ec2-metadata-token: \$token" -s http://169.254.169.254/latest/meta-data/ami-id)
echo "Runner Type: \$runner_type"
echo "Instance Type: \$instance_type"
case \$ami_id in
ami-0ce0c36d7a00b20e2) echo "AMI Name: amzn2-ami-hvm-2.0.20240306.2-x86_64-ebs";;
ami-06c68f701d8090592) echo "AMI Name: al2023-ami-2023.5.20240701.0-kernel-6.1-x86_64";;
*) echo "AMI Name: unknown";;
esac
echo "AMI ID: \$ami_id"
metric_report "runner_scripts.before_job" 1
EOF
chmod 755 $BEFORE_JOB_SCRIPT
Expand All @@ -86,7 +108,7 @@ PROC_LOGS_FILE="/home/$USER_NAME/.proc_logs"
function update_curr_logs_file {
pushd /home/$USER_NAME/actions-runner/_diag >/dev/null
ls -a Worker_* | cat | sort > \$CURR_LOGS_FILE
ls -a Worker_* | cat | sort > $CURR_LOGS_FILE
popd >/dev/null
}
Expand Down

0 comments on commit a979143

Please sign in to comment.