1+ # # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+ # # SPDX-License-Identifier: Apache-2.0
3+
4+ # This is a reusable workflow for running the Enablement test for App Signals.
5+ # It is meant to be called from another workflow.
6+ # Read more about reusable workflows: https://docs.github.com/en/actions/using-workflows/reusing-workflows#overview
7+ name : Java EC2 Ubuntu Use Case
8+ on :
9+ workflow_call :
10+ inputs :
11+ aws-region :
12+ required : true
13+ type : string
14+ caller-workflow-name :
15+ required : true
16+ type : string
17+
18+ outputs :
19+ job-started :
20+ value : ${{ jobs.java-ec2-ubuntu.outputs.job-started }}
21+ validation-result :
22+ value : ${{ jobs.java-ec2-ubuntu.outputs.validation-result }}
23+
24+ permissions :
25+ id-token : write
26+ contents : read
27+
28+ env :
29+ E2E_TEST_AWS_REGION : ${{ inputs.aws-region }}
30+ CALLER_WORKFLOW_NAME : ${{ inputs.caller-workflow-name }}
31+ SAMPLE_APP_FRONTEND_SERVICE_JAR : s3://aws-appsignals-sample-app-prod-${{ inputs.aws-region }}/java-main-service-v11.jar
32+ SAMPLE_APP_REMOTE_SERVICE_JAR : s3://aws-appsignals-sample-app-prod-${{ inputs.aws-region }}/java-remote-service-v11.jar
33+ E2E_TEST_ACCOUNT_ID : ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }}
34+ E2E_TEST_ROLE_NAME : ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }}
35+ METRIC_NAMESPACE : ApplicationSignals
36+ LOG_GROUP_NAME : /aws/application-signals/data
37+ TEST_RESOURCES_FOLDER : ${GITHUB_WORKSPACE}
38+
39+ jobs :
40+ java-ec2-ubuntu :
41+ runs-on : ubuntu-latest
42+ timeout-minutes : 30
43+ outputs :
44+ job-started : ${{ steps.job-started.outputs.job-started }}
45+ validation-result : ${{ steps.validation-result.outputs.validation-result }}
46+ steps :
47+ - name : Check if the job started
48+ id : job-started
49+ run : echo "job-started=true" >> $GITHUB_OUTPUT
50+
51+ - name : Generate testing id
52+ run : echo TESTING_ID="${{ github.run_id }}-${{ github.run_number }}-${RANDOM}" >> $GITHUB_ENV
53+
54+ - uses : actions/checkout@v4
55+ with :
56+ repository : ' aws-observability/aws-application-signals-test-framework'
57+ ref : ${{ env.CALLER_WORKFLOW_NAME == 'main-build' && 'main' || github.ref }}
58+ fetch-depth : 0
59+
60+ # We initialize Gradlew Daemon early on during the workflow because sometimes initialization
61+ # fails due to transient issues. If it fails here, then we will try again later before the validators
62+ - name : Initiate Gradlew Daemon
63+ id : initiate-gradlew
64+ uses : ./.github/workflows/actions/execute_and_retry
65+ continue-on-error : true
66+ with :
67+ command : " ./gradlew :validator:build"
68+ cleanup : " ./gradlew clean"
69+ max_retry : 3
70+ sleep_time : 60
71+
72+ - name : Configure AWS Credentials
73+ uses : aws-actions/configure-aws-credentials@v4
74+ with :
75+ role-to-assume : arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
76+ aws-region : us-east-1
77+
78+ - name : Retrieve account
79+ uses : aws-actions/aws-secretsmanager-get-secrets@v1
80+ with :
81+ secret-ids : |
82+ ACCOUNT_ID, region-account/${{ env.E2E_TEST_AWS_REGION }}
83+
84+ # If the workflow is running as a canary, then we want to log in to the aws account in the appropriate region
85+ - name : Configure AWS Credentials
86+ if : ${{ github.event.repository.name == 'aws-application-signals-test-framework' }}
87+ uses : aws-actions/configure-aws-credentials@v4
88+ with :
89+ role-to-assume : arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
90+ aws-region : ${{ env.E2E_TEST_AWS_REGION }}
91+
92+ - name : Set Get ADOT JAR command environment variable
93+ run : |
94+ if [ "${{ github.event.repository.name }}" = "aws-otel-java-instrumentation" ]; then
95+ echo GET_ADOT_JAR_COMMAND="aws s3 cp s3://adot-main-build-staging-jar/aws-opentelemetry-agent.jar ./adot.jar" >> $GITHUB_ENV
96+ else
97+ echo GET_ADOT_JAR_COMMAND="wget -O adot.jar https://github.com/aws-observability/aws-otel-java-instrumentation/releases/latest/download/aws-opentelemetry-agent.jar" >> $GITHUB_ENV
98+ fi
99+
100+ - name : Set Get CW Agent command environment variable
101+ run : |
102+ if [ "${{ github.event.repository.name }}" = "amazon-cloudwatch-agent" ]; then
103+ echo GET_CW_AGENT_DEB_COMMAND= "aws s3 cp s3://${{ secrets.S3_INTEGRATION_BUCKET }}/integration-test/binary/${{ github.sha }}/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb ./cw-agent.deb" >> $GITHUB_ENV
104+ else
105+ echo GET_CW_AGENT_DEB_COMMAND="wget -O cw-agent.deb https://amazoncloudwatch-agent-${{ inputs.aws-region }}.s3.${{ inputs.aws-region }}.amazonaws.com/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb" >> $GITHUB_ENV
106+ fi
107+
108+ - name : Set up terraform
109+ uses : ./.github/workflows/actions/execute_and_retry
110+ with :
111+ command : " wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg"
112+ post-command : ' echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
113+ && sudo apt update && sudo apt install terraform'
114+ sleep_time : 60
115+
116+ - name : Initiate Terraform
117+ uses : ./.github/workflows/actions/execute_and_retry
118+ with :
119+ command : " cd ${{ env.TEST_RESOURCES_FOLDER }}/terraform/java/ec2/ubuntu && terraform init && terraform validate"
120+ cleanup : " rm -rf .terraform && rm -rf .terraform.lock.hcl"
121+ max_retry : 6
122+ sleep_time : 60
123+
124+ - name : Deploy sample app via terraform and wait for endpoint to come online
125+ working-directory : terraform/java/ec2/ubuntu
126+ run : |
127+ # Attempt to deploy the sample app on an EC2 instance and wait for its endpoint to come online.
128+ # There may be occasional failures due to transitivity issues, so try up to 2 times.
129+ # deployment_failed of 0 indicates that both the terraform deployment and the endpoint are running, while 1 indicates
130+ # that it failed at some point
131+ retry_counter=0
132+ max_retry=2
133+ while [ $retry_counter -lt $max_retry ]; do
134+ echo "Attempt $retry_counter"
135+ deployment_failed=0
136+ terraform apply -auto-approve \
137+ -var="aws_region=${{ inputs.aws-region }}" \
138+ -var="test_id=${{ env.TESTING_ID }}" \
139+ -var="sample_app_jar=${{ env.SAMPLE_APP_FRONTEND_SERVICE_JAR }}" \
140+ -var="sample_remote_app_jar=${{ env.SAMPLE_APP_REMOTE_SERVICE_JAR }}" \
141+ -var="get_cw_agent_deb_command=${{ env.GET_CW_AGENT_DEB_COMMAND }}" \
142+ -var="get_adot_jar_command=${{ env.GET_ADOT_JAR_COMMAND }}" \
143+ || deployment_failed=$?
144+
145+ if [ $deployment_failed -eq 1 ]; then
146+ echo "Terraform deployment was unsuccessful. Will attempt to retry deployment."
147+ fi
148+
149+ # If the success is 1 then either the terraform deployment or the endpoint connection failed, so first destroy the
150+ # resources created from terraform and try again.
151+ if [ $deployment_failed -eq 1 ]; then
152+ echo "Destroying terraform"
153+ terraform destroy -auto-approve \
154+ -var="test_id=${{ env.TESTING_ID }}"
155+
156+ retry_counter=$(($retry_counter+1))
157+ else
158+ # If deployment succeeded, then exit the loop
159+ break
160+ fi
161+
162+ if [ $retry_counter -eq $max_retry ]; then
163+ echo "Max retry reached, failed to deploy terraform and connect to the endpoint. Exiting code"
164+ exit 1
165+ fi
166+ done
167+
168+ - name : Get the ec2 instance ami id
169+ working-directory : terraform/java/ec2/ubuntu
170+ run : |
171+ echo "EC2_INSTANCE_AMI=$(terraform output ec2_instance_ami)" >> $GITHUB_ENV
172+
173+ - name : Get the sample app and EC2 instance information
174+ working-directory : terraform/java/ec2/ubuntu
175+ run : |
176+ echo "MAIN_SERVICE_ENDPOINT=localhost:8080" >> $GITHUB_ENV
177+ echo "REMOTE_SERVICE_IP=$(terraform output sample_app_remote_service_private_ip)" >> $GITHUB_ENV
178+ echo "MAIN_SERVICE_INSTANCE_ID=$(terraform output main_service_instance_id)" >> $GITHUB_ENV
179+
180+ - name : Initiate Gradlew Daemon
181+ if : steps.initiate-gradlew == 'failure'
182+ uses : ./.github/workflows/actions/execute_and_retry
183+ continue-on-error : true
184+ with :
185+ command : " ./gradlew :validator:build"
186+ cleanup : " ./gradlew clean"
187+ max_retry : 3
188+ sleep_time : 60
189+
190+ # Validation for pulse telemetry data
191+ - name : Validate generated EMF logs
192+ id : log-validation
193+ run : ./gradlew validator:run --args='-c java/ec2/ubuntu/log-validation.yml
194+ --testing-id ${{ env.TESTING_ID }}
195+ --endpoint http://${{ env.MAIN_SERVICE_ENDPOINT }}
196+ --remote-service-deployment-name ${{ env.REMOTE_SERVICE_IP }}:8080
197+ --region ${{ inputs.aws-region }}
198+ --account-id ${{ env.ACCOUNT_ID }}
199+ --metric-namespace ${{ env.METRIC_NAMESPACE }}
200+ --log-group ${{ env.LOG_GROUP_NAME }}
201+ --service-name sample-application-${{ env.TESTING_ID }}
202+ --remote-service-name sample-remote-application-${{ env.TESTING_ID }}
203+ --query-string ip=${{ env.REMOTE_SERVICE_IP }}&testingId=${{ env.TESTING_ID }}
204+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
205+ --instance-id ${{ env.MAIN_SERVICE_INSTANCE_ID }}
206+ --rollup'
207+
208+ - name : Validate generated metrics
209+ id : metric-validation
210+ if : (success() || steps.log-validation.outcome == 'failure') && !cancelled()
211+ run : ./gradlew validator:run --args='-c java/ec2/ubuntu/metric-validation.yml
212+ --testing-id ${{ env.TESTING_ID }}
213+ --endpoint http://${{ env.MAIN_SERVICE_ENDPOINT }}
214+ --remote-service-deployment-name ${{ env.REMOTE_SERVICE_IP }}:8080
215+ --region ${{ inputs.aws-region }}
216+ --account-id ${{ env.ACCOUNT_ID }}
217+ --metric-namespace ${{ env.METRIC_NAMESPACE }}
218+ --log-group ${{ env.LOG_GROUP_NAME }}
219+ --service-name sample-application-${{ env.TESTING_ID }}
220+ --remote-service-name sample-remote-application-${{ env.TESTING_ID }}
221+ --query-string ip=${{ env.REMOTE_SERVICE_IP }}&testingId=${{ env.TESTING_ID }}
222+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
223+ --instance-id ${{ env.MAIN_SERVICE_INSTANCE_ID }}
224+ --rollup'
225+
226+ - name : Validate generated traces
227+ id : trace-validation
228+ if : (success() || steps.log-validation.outcome == 'failure' || steps.metric-validation.outcome == 'failure') && !cancelled()
229+ run : ./gradlew validator:run --args='-c java/ec2/ubuntu/trace-validation.yml
230+ --testing-id ${{ env.TESTING_ID }}
231+ --endpoint http://${{ env.MAIN_SERVICE_ENDPOINT }}
232+ --remote-service-deployment-name ${{ env.REMOTE_SERVICE_IP }}:8080
233+ --region ${{ inputs.aws-region }}
234+ --account-id ${{ env.ACCOUNT_ID }}
235+ --metric-namespace ${{ env.METRIC_NAMESPACE }}
236+ --log-group ${{ env.LOG_GROUP_NAME }}
237+ --service-name sample-application-${{ env.TESTING_ID }}
238+ --remote-service-name sample-remote-application-${{ env.TESTING_ID }}
239+ --query-string ip=${{ env.REMOTE_SERVICE_IP }}&testingId=${{ env.TESTING_ID }}
240+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
241+ --instance-id ${{ env.MAIN_SERVICE_INSTANCE_ID }}
242+ --rollup'
243+
244+ - name : Refresh AWS Credentials
245+ if : ${{ github.event.repository.name == 'aws-application-signals-test-framework' }}
246+ uses : aws-actions/configure-aws-credentials@v4
247+ with :
248+ role-to-assume : arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
249+ aws-region : ${{ env.E2E_TEST_AWS_REGION }}
250+
251+ - name : Save test results
252+ if : always()
253+ id : validation-result
254+ run : |
255+ if [ "${{ steps.log-validation.outcome }}" = "success" ] && [ "${{ steps.metric-validation.outcome }}" = "success" ] && [ "${{ steps.trace-validation.outcome }}" = "success" ]; then
256+ echo "validation-result=success" >> $GITHUB_OUTPUT
257+ else
258+ echo "validation-result=failure" >> $GITHUB_OUTPUT
259+ fi
260+
261+ # Clean up Procedures
262+ - name : Terraform destroy
263+ if : always()
264+ continue-on-error : true
265+ working-directory : terraform/java/ec2/ubuntu
266+ run : |
267+ terraform destroy -auto-approve \
268+ -var="test_id=${{ env.TESTING_ID }}"
0 commit comments