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 : Node EC2 ADOT SigV4 Use Case
8+ on :
9+ workflow_call :
10+ inputs :
11+ caller-workflow-name :
12+ required : true
13+ type : string
14+ node-version :
15+ description : " Currently support version 14, 16, 18, 20, 22"
16+ required : false
17+ type : string
18+ # 'none' means to use the node version come with the OS
19+ default : ' none'
20+ cpu-architecture :
21+ description : " Permitted values: x86_64 or arm64"
22+ required : false
23+ type : string
24+ default : " x86_64"
25+ staging-instrumentation-name :
26+ required : false
27+ default : ' @aws/aws-distro-opentelemetry-node-autoinstrumentation'
28+ type : string
29+
30+ permissions :
31+ id-token : write
32+ contents : read
33+
34+ env :
35+ E2E_TEST_AWS_REGION : ' us-west-2'
36+ CALLER_WORKFLOW_NAME : ${{ inputs.caller-workflow-name }}
37+ NODE_VERSION : ${{ inputs.node-version }}
38+ CPU_ARCHITECTURE : ${{ inputs.cpu-architecture }}
39+ ADOT_INSTRUMENTATION_NAME : ${{ inputs.staging-instrumentation-name }}
40+ E2E_TEST_ACCOUNT_ID : ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }}
41+ E2E_TEST_ROLE_NAME : ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }}
42+ METRIC_NAMESPACE : ApplicationSignals
43+ LOG_GROUP_NAME : aws/spans
44+ TEST_RESOURCES_FOLDER : ${GITHUB_WORKSPACE}
45+
46+ jobs :
47+ node-ec2-adot-sigv4 :
48+ runs-on : ubuntu-latest
49+ steps :
50+ - name : Check if the job started
51+ id : job-started
52+ run : echo "job-started=true" >> $GITHUB_OUTPUT
53+
54+ - name : Generate testing id
55+ run : echo TESTING_ID="${{ github.job }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}-${{ env.NODE_VERSION }}-${{ env.CPU_ARCHITECTURE }}" >> $GITHUB_ENV
56+
57+ - uses : actions/checkout@v4
58+ with :
59+ repository : ' aws-observability/aws-application-signals-test-framework'
60+ ref : ${{ env.CALLER_WORKFLOW_NAME == 'main-build' && 'main' || github.ref }}
61+ fetch-depth : 0
62+
63+ # We initialize Gradlew Daemon early on during the workflow because sometimes initialization
64+ # fails due to transient issues. If it fails here, then we will try again later before the validators
65+ - name : Initiate Gradlew Daemon
66+ id : initiate-gradlew
67+ uses : ./.github/workflows/actions/execute_and_retry
68+ continue-on-error : true
69+ with :
70+ command : " ./gradlew :validator:build"
71+ cleanup : " ./gradlew clean"
72+ max_retry : 3
73+ sleep_time : 60
74+
75+ - name : Configure AWS Credentials
76+ uses : aws-actions/configure-aws-credentials@v4
77+ with :
78+ role-to-assume : arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
79+ aws-region : ${{ env.E2E_TEST_AWS_REGION }}
80+
81+ - name : Set Get ADOT Instrumentation command environment variable
82+ run : |
83+ echo GET_ADOT_INSTRUMENTATION_COMMAND="aws s3 cp s3://adot-autoinstrumentation-node-staging/${{ env.ADOT_INSTRUMENTATION_NAME }} ./${{ env.ADOT_INSTRUMENTATION_NAME }} --region us-east-1 && npm install ${{ env.ADOT_INSTRUMENTATION_NAME }}" >> $GITHUB_ENV
84+ # if [ "${{ github.event.repository.name }}" = "aws-otel-js-instrumentation" ]; then
85+ # echo GET_ADOT_INSTRUMENTATION_COMMAND="aws s3 cp s3://adot-autoinstrumentation-node-staging/${{ env.ADOT_INSTRUMENTATION_NAME }} ./${{ env.ADOT_INSTRUMENTATION_NAME }} --region us-east-1 && npm install ${{ env.ADOT_INSTRUMENTATION_NAME }}" >> $GITHUB_ENV
86+ # else
87+ # echo GET_ADOT_INSTRUMENTATION_COMMAND="npm install ${{ env.ADOT_INSTRUMENTATION_NAME }}" >> $GITHUB_ENV
88+ # fi
89+
90+ - name : Set up terraform
91+ uses : ./.github/workflows/actions/execute_and_retry
92+ with :
93+ command : " wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg"
94+ 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
95+ && sudo apt update && sudo apt install terraform'
96+ sleep_time : 60
97+
98+ - name : Initiate Terraform
99+ uses : ./.github/workflows/actions/execute_and_retry
100+ with :
101+ command : " cd ${{ env.TEST_RESOURCES_FOLDER }}/terraform/node/ec2/adot-sigv4 && terraform init && terraform validate"
102+ cleanup : " rm -rf .terraform && rm -rf .terraform.lock.hcl"
103+ max_retry : 6
104+ sleep_time : 60
105+
106+ - name : Deploy sample app via terraform and wait for endpoint to come online
107+ working-directory : terraform/node/ec2/adot-sigv4
108+ run : |
109+ # Attempt to deploy the sample app on an EC2 instance and wait for its endpoint to come online.
110+ # There may be occasional failures due to transitivity issues, so try up to 2 times.
111+ # deployment_failed of 0 indicates that both the terraform deployment and the endpoint are running, while 1 indicates
112+ # that it failed at some point
113+ retry_counter=0
114+ max_retry=2
115+ while [ $retry_counter -lt $max_retry ]; do
116+ echo "Attempt $retry_counter"
117+ deployment_failed=0
118+ terraform apply -auto-approve \
119+ -var="aws_region=${{ env.E2E_TEST_AWS_REGION }}" \
120+ -var="test_id=${{ env.TESTING_ID }}" \
121+ -var="sample_app_zip=s3://aws-appsignals-sample-app-prod-us-east-1/node-sample-app.zip" \
122+ -var="get_adot_instrumentation_command=${{ env.GET_ADOT_INSTRUMENTATION_COMMAND }}" \
123+ -var="language_version=${{ env.NODE_VERSION }}" \
124+ -var="cpu_architecture=${{ env.CPU_ARCHITECTURE }}" \
125+ || deployment_failed=$?
126+
127+ if [ $deployment_failed -eq 1 ]; then
128+ echo "Terraform deployment was unsuccessful. Will attempt to retry deployment."
129+ fi
130+
131+ # If the success is 1 then either the terraform deployment or the endpoint connection failed, so first destroy the
132+ # resources created from terraform and try again.
133+ if [ $deployment_failed -eq 1 ]; then
134+ echo "Destroying terraform"
135+ terraform destroy -auto-approve \
136+ -var="test_id=${{ env.TESTING_ID }}"
137+
138+ retry_counter=$(($retry_counter+1))
139+ else
140+ # If deployment succeeded, then exit the loop
141+ break
142+ fi
143+
144+ if [ $retry_counter -eq $max_retry ]; then
145+ echo "Max retry reached, failed to deploy terraform and connect to the endpoint. Exiting code"
146+ exit 1
147+ fi
148+ done
149+
150+ - name : Get the ec2 instance ami id
151+ working-directory : terraform/node/ec2/adot-sigv4
152+ run : |
153+ echo "EC2_INSTANCE_AMI=$(terraform output ec2_instance_ami)" >> $GITHUB_ENV
154+
155+ - name : Get the sample app and EC2 instance information
156+ working-directory : terraform/node/ec2/adot-sigv4
157+ run : |
158+ echo "MAIN_SERVICE_ENDPOINT=localhost:8000" >> $GITHUB_ENV
159+ echo "REMOTE_SERVICE_IP=$(terraform output sample_app_remote_service_private_ip)" >> $GITHUB_ENV
160+ echo "MAIN_SERVICE_INSTANCE_ID=$(terraform output main_service_instance_id)" >> $GITHUB_ENV
161+
162+ - name : Initiate Gradlew Daemon
163+ if : steps.initiate-gradlew == 'failure'
164+ uses : ./.github/workflows/actions/execute_and_retry
165+ continue-on-error : true
166+ with :
167+ command : " ./gradlew :validator:build"
168+ cleanup : " ./gradlew clean"
169+ max_retry : 3
170+ sleep_time : 60
171+
172+ # Validation for pulse telemetry data
173+ - name : Validate generated EMF logs
174+ id : log-validation
175+ run : ./gradlew validator:run --args='-c node/ec2/adot-sigv4/log-validation.yml
176+ --testing-id ${{ env.TESTING_ID }}
177+ --endpoint http://${{ env.MAIN_SERVICE_ENDPOINT }}
178+ --remote-service-deployment-name ${{ env.REMOTE_SERVICE_IP }}:8001
179+ --region ${{ env.E2E_TEST_AWS_REGION }}
180+ --account-id ${{ env.E2E_TEST_ACCOUNT_ID }}
181+ --metric-namespace ${{ env.METRIC_NAMESPACE }}
182+ --log-group ${{ env.LOG_GROUP_NAME }}
183+ --service-name node-sample-application-${{ env.TESTING_ID }}
184+ --remote-service-name node-sample-remote-application-${{ env.TESTING_ID }}
185+ --query-string ip=${{ env.REMOTE_SERVICE_IP }}&testingId=${{ env.TESTING_ID }}
186+ --instance-ami ${{ env.EC2_INSTANCE_AMI }}
187+ --instance-id ${{ env.MAIN_SERVICE_INSTANCE_ID }}
188+ --rollup'
189+
190+ - name : Validate generated metrics
191+ id : metric-validation
192+ if : (success() || steps.log-validation.outcome == 'failure') && !cancelled()
193+ run : ./gradlew validator:run --args='-c node/ec2/adot-sigv4/metric-validation.yml
194+ --testing-id ${{ env.TESTING_ID }}
195+ --endpoint http://${{ env.MAIN_SERVICE_ENDPOINT }}
196+ --remote-service-deployment-name ${{ env.REMOTE_SERVICE_IP }}:8001
197+ --region ${{ env.E2E_TEST_AWS_REGION }}
198+ --account-id ${{ env.E2E_TEST_ACCOUNT_ID }}
199+ --metric-namespace ${{ env.METRIC_NAMESPACE }}
200+ --log-group ${{ env.LOG_GROUP_NAME }}
201+ --service-name node-sample-application-${{ env.TESTING_ID }}
202+ --remote-service-name node-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 traces
209+ id : trace-validation
210+ if : (success() || steps.log-validation.outcome == 'failure' || steps.metric-validation.outcome == 'failure') && !cancelled()
211+ run : ./gradlew validator:run --args='-c node/ec2/adot-sigv4/trace-validation.yml
212+ --testing-id ${{ env.TESTING_ID }}
213+ --endpoint http://${{ env.MAIN_SERVICE_ENDPOINT }}
214+ --remote-service-deployment-name ${{ env.REMOTE_SERVICE_IP }}
215+ --region ${{ env.E2E_TEST_AWS_REGION }}
216+ --account-id ${{ env.E2E_TEST_ACCOUNT_ID }}
217+ --metric-namespace ${{ env.METRIC_NAMESPACE }}
218+ --log-group ${{ env.LOG_GROUP_NAME }}
219+ --service-name node-sample-application-${{ env.TESTING_ID }}
220+ --remote-service-name node-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 : Refresh AWS Credentials
227+ if : ${{ always() }}
228+ uses : aws-actions/configure-aws-credentials@v4
229+ with :
230+ role-to-assume : arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
231+ aws-region : ${{ env.E2E_TEST_AWS_REGION }}
232+
233+ # Clean up Procedures
234+ - name : Terraform destroy
235+ if : always()
236+ continue-on-error : true
237+ working-directory : terraform/node/ec2/adot-sigv4
238+ run : |
239+ terraform destroy -auto-approve \
240+ -var="test_id=${{ env.TESTING_ID }}"
0 commit comments