@@ -5,6 +5,9 @@ name: App Signals Enablement E2E Testing - EC2 Use Case
55on :
66 workflow_call :
77 inputs :
8+ aws-region :
9+ required : true
10+ type : string
811 caller-workflow-name :
912 required : true
1013 type : string
@@ -14,11 +17,10 @@ permissions:
1417 contents : read
1518
1619env :
17- AWS_DEFAULT_REGION : us-east-1
20+ AWS_DEFAULT_REGION : ${{ inputs.aws-region }} # Used by terraform and AWS CLI commands
1821 TEST_ACCOUNT : ${{ secrets.APP_SIGNALS_E2E_TEST_ACC }}
1922 SAMPLE_APP_FRONTEND_SERVICE_JAR : " s3://aws-appsignals-sample-app/main-service.jar"
2023 SAMPLE_APP_REMOTE_SERVICE_JAR : " s3://aws-appsignals-sample-app/remote-service.jar"
21- APP_SIGNALS_CW_AGENT_RPM : " https://amazoncloudwatch-agent-us-east-1.s3.amazonaws.com/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm"
2224 APP_SIGNALS_ADOT_JAR : " https://github.com/aws-observability/aws-otel-java-instrumentation/releases/latest/download/aws-opentelemetry-agent.jar"
2325 METRIC_NAMESPACE : AppSignals
2426 LOG_GROUP_NAME : /aws/appsignals/generic
3133 with :
3234 fetch-depth : 0
3335
36+ - name : Set CW Agent RPM environment variable
37+ run : |
38+ if [ ${{ env.AWS_DEFAULT_REGION }} == "us-east-1" ]; then
39+ echo APP_SIGNALS_CW_AGENT_RPM="https://amazoncloudwatch-agent-us-east-1.s3.amazonaws.com/amazon_linux/amd64/1.300031.0b313/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV
40+ else
41+ echo APP_SIGNALS_CW_AGENT_RPM="https://amazoncloudwatch-agent-${{ env.AWS_DEFAULT_REGION }}.s3.${{ env.AWS_DEFAULT_REGION }}.amazonaws.com/amazon_linux/amd64/1.300031.0b313/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV
42+ fi
43+
44+
3445 - name : Generate testing id
3546 run : echo TESTING_ID="${{ github.run_id }}-${{ github.run_number }}" >> $GITHUB_ENV
3647
@@ -41,45 +52,88 @@ jobs:
4152 aws-region : ${{ env.AWS_DEFAULT_REGION }}
4253
4354 - name : Set up terraform
44- uses : hashicorp/setup-terraform@v2
55+ uses : hashicorp/setup-terraform@v3
4556 with :
4657 terraform_wrapper : false
4758
48- - name : Deploy sample app via terraform
59+ - name : Deploy sample app via terraform and wait for endpoint to come online
4960 working-directory : testing/terraform/ec2
5061 run : |
5162 terraform init
5263 terraform validate
53- terraform apply -auto-approve \
54- -var="aws_region=${{ env.AWS_DEFAULT_REGION }}" \
55- -var="test_id=${{ env.TESTING_ID }}" \
56- -var="sample_app_jar=${{ env.SAMPLE_APP_FRONTEND_SERVICE_JAR }}" \
57- -var="sample_remote_app_jar=${{ env.SAMPLE_APP_REMOTE_SERVICE_JAR }}" \
58- -var="cw_agent_rpm=${{ env.APP_SIGNALS_CW_AGENT_RPM }}" \
59- -var="adot_jar=${{ env.APP_SIGNALS_ADOT_JAR }}"
64+
65+ # Attempt to deploy the sample app on an EC2 instance and wait for its endpoint to come online.
66+ # There may be occasional failures due to transitivity issues, so try up to 2 times.
67+ # deployment_failed of 0 indicates that both the terraform deployment and the endpoint are running, while 1 indicates
68+ # that it failed at some point
69+ retry_counter=0
70+ max_retry=2
71+ while [ $retry_counter -lt $max_retry ]; do
72+ echo "Attempt $retry_counter"
73+ deployment_failed=0
74+ terraform apply -auto-approve \
75+ -var="aws_region=${{ env.AWS_DEFAULT_REGION }}" \
76+ -var="test_id=${{ env.TESTING_ID }}" \
77+ -var="sample_app_jar=${{ env.SAMPLE_APP_FRONTEND_SERVICE_JAR }}" \
78+ -var="sample_remote_app_jar=${{ env.SAMPLE_APP_REMOTE_SERVICE_JAR }}" \
79+ -var="cw_agent_rpm=${{ env.APP_SIGNALS_CW_AGENT_RPM }}" \
80+ -var="adot_jar=${{ env.APP_SIGNALS_ADOT_JAR }}" \
81+ || deployment_failed=$?
82+
83+ if [ $deployment_failed -eq 1 ]; then
84+ echo "Terraform deployment was unsuccessful. Will attempt to retry deployment."
85+ fi
86+
87+ # If the deployment_failed is still 0, then the terraform deployment succeeded and now try to connect to the endpoint.
88+ # Attempts to connect will be made for up to 10 minutes
89+ if [ $deployment_failed -eq 0 ]; then
90+ echo "Attempting to connect to the endpoint"
91+ sample_app_endpoint=http://$(terraform output sample_app_main_service_public_dns):8080
92+ attempt_counter=0
93+ max_attempts=60
94+ until $(curl --output /dev/null --silent --head --fail $(echo "$sample_app_endpoint" | tr -d '"')); do
95+ if [ ${attempt_counter} -eq ${max_attempts} ];then
96+ echo "Failed to connect to endpoint. Will attempt to redeploy sample app."
97+ deployment_failed=1
98+ break
99+ fi
100+
101+ printf '.'
102+ attempt_counter=$(($attempt_counter+1))
103+ sleep 10
104+ done
105+ fi
106+
107+ # If the success is 1 then either the terraform deployment or the endpoint connection failed, so first destroy the
108+ # resources created from terraform and try again.
109+ if [ $deployment_failed -eq 1 ]; then
110+ echo "Destroying terraform"
111+ terraform destroy -auto-approve \
112+ -var="test_id=${{ env.TESTING_ID }}"
113+
114+ retry_counter=$(($retry_counter+1))
115+ else
116+ # If deployment succeeded, then exit the loop
117+ break
118+ fi
119+
120+ if [ $retry_counter -eq $max_retry ]; then
121+ echo "Max retry reached, failed to deploy terraform and connect to the endpoint. Exiting code"
122+ exit 1
123+ fi
124+ done
125+
126+ - name : Get the ec2 instance ami id
127+ run : |
128+ echo "EC2_INSTANCE_AMI=$(terraform output ec2_instance_ami)" >> $GITHUB_ENV
129+ working-directory : testing/terraform/ec2
60130
61131 - name : Get the sample app endpoint
62132 run : |
63133 echo "MAIN_SERVICE_ENDPOINT=$(terraform output sample_app_main_service_public_dns):8080" >> $GITHUB_ENV
64134 echo "REMOTE_SERVICE_IP=$(terraform output sample_app_remote_service_public_ip)" >> $GITHUB_ENV
65135 working-directory : testing/terraform/ec2
66136
67- - name : Wait for app endpoint to come online
68- id : endpoint-check
69- run : |
70- attempt_counter=0
71- max_attempts=30
72- until $(curl --output /dev/null --silent --head --fail http://${{ env.MAIN_SERVICE_ENDPOINT }}); do
73- if [ ${attempt_counter} -eq ${max_attempts} ];then
74- echo "Max attempts reached"
75- exit 1
76- fi
77-
78- printf '.'
79- attempt_counter=$(($attempt_counter+1))
80- sleep 10
81- done
82-
83137 # This steps increases the speed of the validation by creating the telemetry data in advance
84138 - name : Call all test APIs
85139 continue-on-error : true
@@ -103,6 +157,7 @@ jobs:
103157 --service-name sample-application-${{ env.TESTING_ID }}
104158 --remote-service-name sample-remote-application-${{ env.TESTING_ID }}
105159 --request-body ip=${{ env.REMOTE_SERVICE_IP }}
160+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
106161 --rollup'
107162
108163 - name : Validate generated metrics
@@ -119,6 +174,7 @@ jobs:
119174 --service-name sample-application-${{ env.TESTING_ID }}
120175 --remote-service-name sample-remote-application-${{ env.TESTING_ID }}
121176 --request-body ip=${{ env.REMOTE_SERVICE_IP }}
177+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
122178 --rollup'
123179
124180 - name : Validate generated traces
@@ -135,6 +191,7 @@ jobs:
135191 --service-name sample-application-${{ env.TESTING_ID }}
136192 --remote-service-name sample-remote-application-${{ env.TESTING_ID }}
137193 --request-body ip=${{ env.REMOTE_SERVICE_IP }}
194+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
138195 --rollup'
139196
140197 - name : Publish metric on test result
@@ -163,4 +220,4 @@ jobs:
163220 working-directory : testing/terraform/ec2
164221 run : |
165222 terraform destroy -auto-approve \
166- -var="test_id=${{ env.TESTING_ID }}"
223+ -var="test_id=${{ env.TESTING_ID }}"
0 commit comments