@@ -5,6 +5,9 @@ name: App Signals Enablement E2E Testing - EC2 Use Case
5
5
on :
6
6
workflow_call :
7
7
inputs :
8
+ aws-region :
9
+ required : true
10
+ type : string
8
11
caller-workflow-name :
9
12
required : true
10
13
type : string
@@ -14,11 +17,10 @@ permissions:
14
17
contents : read
15
18
16
19
env :
17
- AWS_DEFAULT_REGION : us-east-1
20
+ AWS_DEFAULT_REGION : ${{ inputs.aws-region }} # Used by terraform and AWS CLI commands
18
21
TEST_ACCOUNT : ${{ secrets.APP_SIGNALS_E2E_TEST_ACC }}
19
22
SAMPLE_APP_FRONTEND_SERVICE_JAR : " s3://aws-appsignals-sample-app/main-service.jar"
20
23
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"
22
24
APP_SIGNALS_ADOT_JAR : " https://github.com/aws-observability/aws-otel-java-instrumentation/releases/latest/download/aws-opentelemetry-agent.jar"
23
25
METRIC_NAMESPACE : AppSignals
24
26
LOG_GROUP_NAME : /aws/appsignals/generic
31
33
with :
32
34
fetch-depth : 0
33
35
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
+
34
45
- name : Generate testing id
35
46
run : echo TESTING_ID="${{ github.run_id }}-${{ github.run_number }}" >> $GITHUB_ENV
36
47
@@ -41,45 +52,88 @@ jobs:
41
52
aws-region : ${{ env.AWS_DEFAULT_REGION }}
42
53
43
54
- name : Set up terraform
44
- uses : hashicorp/setup-terraform@v2
55
+ uses : hashicorp/setup-terraform@v3
45
56
with :
46
57
terraform_wrapper : false
47
58
48
- - name : Deploy sample app via terraform
59
+ - name : Deploy sample app via terraform and wait for endpoint to come online
49
60
working-directory : testing/terraform/ec2
50
61
run : |
51
62
terraform init
52
63
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
60
130
61
131
- name : Get the sample app endpoint
62
132
run : |
63
133
echo "MAIN_SERVICE_ENDPOINT=$(terraform output sample_app_main_service_public_dns):8080" >> $GITHUB_ENV
64
134
echo "REMOTE_SERVICE_IP=$(terraform output sample_app_remote_service_public_ip)" >> $GITHUB_ENV
65
135
working-directory : testing/terraform/ec2
66
136
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
-
83
137
# This steps increases the speed of the validation by creating the telemetry data in advance
84
138
- name : Call all test APIs
85
139
continue-on-error : true
@@ -103,6 +157,7 @@ jobs:
103
157
--service-name sample-application-${{ env.TESTING_ID }}
104
158
--remote-service-name sample-remote-application-${{ env.TESTING_ID }}
105
159
--request-body ip=${{ env.REMOTE_SERVICE_IP }}
160
+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
106
161
--rollup'
107
162
108
163
- name : Validate generated metrics
@@ -119,6 +174,7 @@ jobs:
119
174
--service-name sample-application-${{ env.TESTING_ID }}
120
175
--remote-service-name sample-remote-application-${{ env.TESTING_ID }}
121
176
--request-body ip=${{ env.REMOTE_SERVICE_IP }}
177
+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
122
178
--rollup'
123
179
124
180
- name : Validate generated traces
@@ -135,6 +191,7 @@ jobs:
135
191
--service-name sample-application-${{ env.TESTING_ID }}
136
192
--remote-service-name sample-remote-application-${{ env.TESTING_ID }}
137
193
--request-body ip=${{ env.REMOTE_SERVICE_IP }}
194
+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
138
195
--rollup'
139
196
140
197
- name : Publish metric on test result
@@ -163,4 +220,4 @@ jobs:
163
220
working-directory : testing/terraform/ec2
164
221
run : |
165
222
terraform destroy -auto-approve \
166
- -var="test_id=${{ env.TESTING_ID }}"
223
+ -var="test_id=${{ env.TESTING_ID }}"
0 commit comments