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 adaptive sampling validation 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 Adaptive Sampling Use Case
8
+ on :
9
+ workflow_call :
10
+ inputs :
11
+ caller-workflow-name :
12
+ required : true
13
+ type : string
14
+
15
+ permissions :
16
+ id-token : write
17
+ contents : read
18
+
19
+ env :
20
+ E2E_TEST_AWS_REGION : us-west-2
21
+ CALLER_WORKFLOW_NAME : ${{ inputs.caller-workflow-name }}
22
+ SAMPLE_APP_FRONTEND_SERVICE_JAR : s3://aws-appsignals-sample-app-prod-us-west-2-adap/java-main-service-v11.jar
23
+ SAMPLE_APP_REMOTE_SERVICE_JAR : s3://aws-appsignals-sample-app-prod-us-west-2-adap/java-remote-service-v11.jar
24
+ E2E_TEST_ACCOUNT_ID : ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }}
25
+ E2E_TEST_ROLE_NAME : ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }}
26
+ TEST_RESOURCES_FOLDER : ${GITHUB_WORKSPACE}
27
+
28
+ jobs :
29
+ java-ec2-adaptive-sampling :
30
+ runs-on : ubuntu-latest
31
+ timeout-minutes : 30
32
+ steps :
33
+ - name : Generate testing id
34
+ run : echo TESTING_ID="${{ github.run_id }}-${{ github.run_number }}-${RANDOM}" >> $GITHUB_ENV
35
+
36
+ - uses : actions/checkout@v4
37
+ with :
38
+ repository : ' aws-observability/aws-application-signals-test-framework'
39
+ ref : ${{ env.CALLER_WORKFLOW_NAME == 'main-build' && 'main' || github.ref }}
40
+ fetch-depth : 0
41
+
42
+ - name : Initiate Gradlew Daemon
43
+ id : initiate-gradlew
44
+ uses : ./.github/workflows/actions/execute_and_retry
45
+ continue-on-error : true
46
+ with :
47
+ command : " ./gradlew :validator:build"
48
+ cleanup : " ./gradlew clean"
49
+ max_retry : 3
50
+ sleep_time : 60
51
+
52
+ - name : Configure AWS Credentials
53
+ uses : aws-actions/configure-aws-credentials@v4
54
+ with :
55
+ role-to-assume : arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
56
+ aws-region : us-east-1
57
+
58
+ - name : Retrieve account
59
+ uses : aws-actions/aws-secretsmanager-get-secrets@v1
60
+ with :
61
+ secret-ids : |
62
+ ACCOUNT_ID, adaptive-sampling-region-account/prod-${{ env.E2E_TEST_AWS_REGION }}
63
+
64
+ - name : Configure AWS Credentials
65
+ if : ${{ github.event.repository.name == 'aws-application-signals-test-framework' }}
66
+ uses : aws-actions/configure-aws-credentials@v4
67
+ with :
68
+ role-to-assume : arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
69
+ aws-region : ${{ env.E2E_TEST_AWS_REGION }}
70
+
71
+ # TODO: Replace else action with getting latest ADOT release
72
+ - name : Set Get ADOT JAR command environment variable
73
+ run : |
74
+ if [ "${{ github.event.repository.name }}" = "aws-otel-java-instrumentation" ]; then
75
+ echo GET_ADOT_JAR_COMMAND="aws s3 cp s3://adot-main-build-staging-jar/aws-opentelemetry-agent.jar ./adot.jar" >> $GITHUB_ENV
76
+ else
77
+ echo GET_ADOT_JAR_COMMAND="aws s3 cp s3://aws-appsignals-sample-app-prod-us-west-2-adap/pre-release/aws-opentelemetry-agent-2.12.0-SNAPSHOT.jar ./adot.jar --region ${{ env.E2E_TEST_AWS_REGION }}" >> $GITHUB_ENV
78
+ fi
79
+
80
+ - name : Set Get CW Agent command environment variable
81
+ run : |
82
+ echo GET_CW_AGENT_RPM_COMMAND="wget -O cw-agent.rpm https://amazoncloudwatch-agent-${{ env.E2E_TEST_AWS_REGION }}.s3.${{ env.E2E_TEST_AWS_REGION }}.amazonaws.com/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm" >> $GITHUB_ENV
83
+
84
+ - name : Set up terraform
85
+ uses : ./.github/workflows/actions/execute_and_retry
86
+ with :
87
+ command : " wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg"
88
+ 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
89
+ && sudo apt update && sudo apt install terraform'
90
+ sleep_time : 60
91
+
92
+ - name : Initiate Terraform
93
+ uses : ./.github/workflows/actions/execute_and_retry
94
+ with :
95
+ command : " cd ${{ env.TEST_RESOURCES_FOLDER }}/terraform/java/ec2/adaptive-sampling && terraform init && terraform validate"
96
+ cleanup : " rm -rf .terraform && rm -rf .terraform.lock.hcl"
97
+ max_retry : 6
98
+ sleep_time : 60
99
+
100
+ - name : Deploy sample app via terraform and wait for endpoint to come online
101
+ working-directory : terraform/java/ec2/adaptive-sampling
102
+ run : |
103
+ retry_counter=0
104
+ max_retry=2
105
+ while [ $retry_counter -lt $max_retry ]; do
106
+ echo "Attempt $retry_counter"
107
+ deployment_failed=0
108
+ terraform apply -auto-approve \
109
+ -var="aws_region=${{ env.E2E_TEST_AWS_REGION }}" \
110
+ -var="test_id=${{ env.TESTING_ID }}" \
111
+ -var="sample_app_jar=${{ env.SAMPLE_APP_FRONTEND_SERVICE_JAR }}" \
112
+ -var="sample_remote_app_jar=${{ env.SAMPLE_APP_REMOTE_SERVICE_JAR }}" \
113
+ -var="get_cw_agent_rpm_command=${{ env.GET_CW_AGENT_RPM_COMMAND }}" \
114
+ -var="get_adot_jar_command=${{ env.GET_ADOT_JAR_COMMAND }}" \
115
+ || deployment_failed=$?
116
+
117
+ if [ $deployment_failed -eq 1 ]; then
118
+ echo "Terraform deployment was unsuccessful. Will attempt to retry deployment."
119
+ echo "Destroying terraform"
120
+ terraform destroy -auto-approve \
121
+ -var="test_id=${{ env.TESTING_ID }}"
122
+ retry_counter=$(($retry_counter+1))
123
+ else
124
+ break
125
+ fi
126
+
127
+ if [ $retry_counter -eq $max_retry ]; then
128
+ echo "Max retry reached, failed to deploy terraform and connect to the endpoint. Exiting code"
129
+ exit 1
130
+ fi
131
+ done
132
+
133
+ - name : Get the sample app and EC2 instance information
134
+ working-directory : terraform/java/ec2/adaptive-sampling
135
+ run : |
136
+ echo "MAIN_SERVICE_ENDPOINT=localhost:8080" >> $GITHUB_ENV
137
+ echo "REMOTE_SERVICE_IP=$(terraform output sample_app_remote_service_private_ip)" >> $GITHUB_ENV
138
+ echo "MAIN_SERVICE_INSTANCE_ID=$(terraform output main_service_instance_id)" >> $GITHUB_ENV
139
+ echo "EC2_INSTANCE_AMI=$(terraform output ec2_instance_ami)" >> $GITHUB_ENV
140
+
141
+ - name : Initiate Gradlew Daemon
142
+ if : steps.initiate-gradlew == 'failure'
143
+ uses : ./.github/workflows/actions/execute_and_retry
144
+ continue-on-error : true
145
+ with :
146
+ command : " ./gradlew :validator:build"
147
+ cleanup : " ./gradlew clean"
148
+ max_retry : 3
149
+ sleep_time : 60
150
+
151
+ - name : Validate generated adaptive-sampling
152
+ run : ./gradlew validator:run --args='-c java/ec2/adaptive-sampling/trace-validation.yml
153
+ --testing-id ${{ env.TESTING_ID }}
154
+ --endpoint http://${{ env.MAIN_SERVICE_ENDPOINT }}
155
+ --remote-service-deployment-name ${{ env.REMOTE_SERVICE_IP }}:8080
156
+ --region ${{ env.E2E_TEST_AWS_REGION }}
157
+ --account-id ${{ env.ACCOUNT_ID }}
158
+ --service-name main-${{ env.TESTING_ID }}
159
+ --remote-service-name remote-${{ env.TESTING_ID }}
160
+ --query-string ip=${{ env.REMOTE_SERVICE_IP }}
161
+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
162
+ --instance-id ${{ env.MAIN_SERVICE_INSTANCE_ID }}
163
+ --rollup'
164
+
165
+ - name : Refresh AWS Credentials
166
+ if : ${{ github.event.repository.name == 'aws-application-signals-test-framework' }}
167
+ uses : aws-actions/configure-aws-credentials@v4
168
+ with :
169
+ role-to-assume : arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
170
+ aws-region : ${{ env.E2E_TEST_AWS_REGION }}
171
+
172
+ # Ensures gap between terraform apply and destroy
173
+ - name : Sleep 10 seconds
174
+ if : always()
175
+ run : sleep 10
176
+
177
+ - name : Terraform destroy
178
+ if : always()
179
+ continue-on-error : true
180
+ working-directory : terraform/java/ec2/adaptive-sampling
181
+ run : |
182
+ terraform destroy -auto-approve \
183
+ -var="test_id=${{ env.TESTING_ID }}"
0 commit comments