Skip to content

Commit dc5fe84

Browse files
authored
Turn on better logging for EC2 test framework (#2298)
### Description of changes: Currently Cloudwatch logs only captures the output of commands run, not which command ran so it's hard to figure out what is causing an issue. This turns on logging for all commands, combines the standard error and out logs, and turns on exit on any failure. ### Testing: Before: ``` DEPENDENCIES_DIR=/home/dependencies OLDPWD=/var/snap/amazon-ssm-agent/7984/aws-lc-pr _=/usr/bin/env Building AWS-LC in Release mode with address sanitizer, and running only non ssl test. Using Ninja build system (ninja). -- Go compiler 1.20.1 found -- The C compiler identification is Clang 15.0.7 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/clang - skipped -- Detecting C compile features ``` After: ``` + echo 'Using Ninja build system (ninja).' + BUILD_COMMAND=ninja + cflags+=(-GNinja) + cmake3 -DASAN=1 -DCMAKE_BUILD_TYPE=Release -DENABLE_DILITHIUM=ON -GNinja /var/snap/amazon-ssm-agent/7984/aws-lc-pr -- Go compiler 1.20.1 found -- The C compiler identification is Clang 15.0.7 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/clang - skipped -- Detecting C compile features -- Detecting C compile features - done ``` By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 8acccd9 commit dc5fe84

File tree

3 files changed

+58
-54
lines changed

3 files changed

+58
-54
lines changed

tests/ci/benchmark_framework/install_docker.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
# SPDX-License-Identifier: Apache-2.0 OR ISC
44

5-
set -xo
5+
set -exo pipefail
66

77
if ! [ -x "$(command -v docker)" ]; then
88
apt-get update

tests/ci/cdk/cdk/ssm/general_test_run_ssm_document.yaml

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,65 @@ mainSteps:
99
name: runShellScript
1010
inputs:
1111
timeoutSeconds: '7200'
12+
shell: bash
1213
runCommand:
1314
# Fallback plan to shut down the ec2 instance in 90 minutes in case it's not terminated.
1415
# Codebuild just "stops" the instance calling the script, so "trap cleanup" is not executed.
15-
- shutdown -P +90
16-
- sudo -i
17-
- systemctl stop apt-daily.timer
18-
- export DEBIAN_FRONTEND=noninteractive
19-
- export CPU_TYPE=$(dpkg --print-architecture)
20-
- export SOURCE={SOURCE}
21-
# if we have a cpu type of x86, we want linux-x86
22-
- if [ "${CPU_TYPE}" = amd64 ]; then export CPU_ARCH=linux-x86; export AWS_CLI_PREFIX=x86_; fi
23-
# if we have a cpu type of arm, we want linux-aarch
24-
- if [ "${CPU_TYPE}" = arm64 ]; then export CPU_ARCH=linux-aarch; export AWS_CLI_PREFIX=aarch; fi
25-
# install aws-cli
26-
- killall apt apt-get
27-
- apt-get update
28-
- apt-get -y remove needrestart
29-
- apt-get -y install unzip
30-
- curl "https://awscli.amazonaws.com/awscli-exe-linux-${AWS_CLI_PREFIX}64.zip" -o "awscliv2.zip"
31-
- unzip awscliv2.zip
32-
- ./aws/install
33-
# Check if the source code is on S3, otherwise treat the source as a PR.
34-
- >
35-
if [ "$(expr substr "$SOURCE" 1 16)" = "aws-lc-codebuild" ]; then
36-
aws s3api get-object --bucket {S3_BUCKET} --key "${SOURCE##{S3_BUCKET}/}" aws-lc-pr.zip
37-
unzip aws-lc-pr.zip
38-
else
39-
git clone {SOURCE} aws-lc-pr
40-
cd aws-lc-pr
41-
git fetch origin pull/{PR_NUM}/head:temp
42-
git checkout temp
43-
git show
44-
if [ "$(git log -n 1 --pretty=format:"%H")" != "{COMMIT_ID}" ]; then
45-
exit 1
16+
- |
17+
#!/usr/bin/env bash
18+
# Redirect standard error to out so logs are combined in CloudWatch Logs
19+
exec 2>&1
20+
# Echo all commands before executing and exit on any failure
21+
set -exo pipefail
22+
shutdown -P +90
23+
sudo -i
24+
systemctl stop apt-daily.timer
25+
export DEBIAN_FRONTEND=noninteractive
26+
export CPU_TYPE=$(dpkg --print-architecture)
27+
export SOURCE={SOURCE}
28+
# if we have a cpu type of x86, we want linux-x86
29+
if [ "${CPU_TYPE}" = amd64 ]; then export CPU_ARCH=linux-x86; export AWS_CLI_PREFIX=x86_; fi
30+
# if we have a cpu type of arm, we want linux-aarch
31+
if [ "${CPU_TYPE}" = arm64 ]; then export CPU_ARCH=linux-aarch; export AWS_CLI_PREFIX=aarch; fi
32+
# install aws-cli
33+
killall apt apt-get || echo "No apt processes found"
34+
apt-get update
35+
apt-get -y remove needrestart
36+
apt-get -y install unzip
37+
curl "https://awscli.amazonaws.com/awscli-exe-linux-${AWS_CLI_PREFIX}64.zip" -o "awscliv2.zip"
38+
unzip awscliv2.zip
39+
./aws/install
40+
# Check if the source code is on S3, otherwise treat the source as a PR.
41+
if [ "$(expr substr "$SOURCE" 1 16)" = "aws-lc-codebuild" ]; then
42+
aws s3api get-object --bucket {S3_BUCKET} --key "${SOURCE##{S3_BUCKET}/}" aws-lc-pr.zip
43+
unzip aws-lc-pr.zip
44+
else
45+
git clone {SOURCE} aws-lc-pr
46+
cd aws-lc-pr
47+
git fetch origin pull/{PR_NUM}/head:temp
48+
git checkout temp
49+
git show
50+
if [ "$(git log -n 1 --pretty=format:"%H")" != "{COMMIT_ID}" ]; then
51+
exit 1
52+
fi
4653
fi
47-
fi
48-
# install docker if its not already installed
49-
- chmod +x ./tests/ci/benchmark_framework/install_docker.sh
50-
- ./tests/ci/benchmark_framework/install_docker.sh
51-
# log into docker and get needed docker image from ecr
52-
- export ECR_REPO="{AWS_ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/aws-lc-docker-images-${CPU_ARCH}"
53-
- aws ecr get-login-password --region us-west-2 | docker login -u AWS --password-stdin "${ECR_REPO}"
54-
- docker pull "${ECR_REPO}:{ECR_DOCKER_TAG}_latest"
55-
# Start the container. Docker needs to be run in "privileged" mode for TSAN tests to pass.
56-
- exec_docker="docker run -v `pwd`:`pwd` -w `pwd` --privileged ${ECR_REPO}:{ECR_DOCKER_TAG}_latest"
57-
# Check if container was spun up succesfully. Then run test scripts and check the output.
58-
- >
59-
if [ -n "$exec_docker" ]; then
60-
chmod +x {TARGET_TEST_SCRIPT}
61-
$exec_docker {TARGET_TEST_SCRIPT}
62-
if [ $? != 0 ]; then
54+
# install docker if its not already installed
55+
chmod +x ./tests/ci/benchmark_framework/install_docker.sh
56+
./tests/ci/benchmark_framework/install_docker.sh
57+
# log into docker and get needed docker image from ecr
58+
export ECR_REPO="{AWS_ACCOUNT_ID}.dkr.ecr.us-west-2.amazonaws.com/aws-lc-docker-images-${CPU_ARCH}"
59+
aws ecr get-login-password --region us-west-2 | docker login -u AWS --password-stdin "${ECR_REPO}"
60+
docker pull "${ECR_REPO}:{ECR_DOCKER_TAG}_latest"
61+
# Start the container. Docker needs to be run in "privileged" mode for TSAN tests to pass.
62+
exec_docker="docker run -v `pwd`:`pwd` -w `pwd` --privileged ${ECR_REPO}:{ECR_DOCKER_TAG}_latest"
63+
# Check if container was spun up succesfully. Then run test scripts and check the output.
64+
if [ -n "$exec_docker" ]; then
65+
chmod +x {TARGET_TEST_SCRIPT}
66+
$exec_docker {TARGET_TEST_SCRIPT}
67+
if [ $? != 0 ]; then
68+
exit 1
69+
fi
70+
else
6371
exit 1
6472
fi
65-
else
66-
exit 1
67-
fi
68-
- echo All ec2 test framework tests passed
73+
echo All ec2 test framework tests passed

tests/ci/run_ec2_test_framework.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ ec2_test_ssm_command_id=$(run_ssm_command "${ssm_doc_name}" "${instance_id}" ${c
9595
run_url="https://${AWS_REGION}.console.aws.amazon.com/cloudwatch/home?region=${AWS_REGION}\
9696
#logsV2:log-groups/log-group/${cloudwatch_group_name}/log-events/${ec2_test_ssm_command_id}\$252F${instance_id}\$252FrunShellScript\$252F"
9797

98-
echo "Actual Run in EC2 can be observered at CloudWatch URL: ${run_url}stdout"
99-
echo "Error outputs can be observered at CloudWatch URL: ${run_url}stderr"
98+
echo "Actual Run in EC2 can be observed at CloudWatch URL: ${run_url}stdout all output is redirected to stdout. If something is weird check the same url s/stdout/stderr"
10099

101100

102101
# Give some time for the commands to run, total wait time is 90 minutes.

0 commit comments

Comments
 (0)