Skip to content

Commit f1bd993

Browse files
authored
Add node ecs test (#308)
*Issue description:* *Description of changes:* Add the workflows that are used for node ECS release test. Note that we won't enable the node ecs canary test. The release test will be run in [another repo](https://github.com/aws-observability/aws-otel-js-instrumentation) whenever a change is merged into mainline. *Rollback procedure:* Revert the commit. *Ensure you've run the following tests on your changes and include the link below:* To do so, create a `test.yml` file with `name: Test` and workflow description to test your changes, then remove the file for your PR. Link your test run in your PR description. This process is a short term solution while we work on creating a staging environment for testing. Manually triggered a test run and confirmed node ECS test run successfully. See details here: https://github.com/aws-observability/aws-application-signals-test-framework/actions/runs/11615779546 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent a7df958 commit f1bd993

File tree

12 files changed

+800
-0
lines changed

12 files changed

+800
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 ECS Retry
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+
permissions:
19+
id-token: write
20+
contents: read
21+
22+
jobs:
23+
node-ecs-attempt-1:
24+
uses: ./.github/workflows/node-ecs-test.yml
25+
secrets: inherit
26+
with:
27+
aws-region: ${{ inputs.aws-region }}
28+
caller-workflow-name: ${{ inputs.caller-workflow-name }}
29+
30+
node-ecs-attempt-2:
31+
needs: [ node-ecs-attempt-1 ]
32+
if: ${{ needs.node-ecs-attempt-1.outputs.job-started != 'true' }}
33+
uses: ./.github/workflows/node-ecs-test.yml
34+
secrets: inherit
35+
with:
36+
aws-region: ${{ inputs.aws-region }}
37+
caller-workflow-name: ${{ inputs.caller-workflow-name }}
38+
39+
publish-metric-attempt-1:
40+
needs: [ node-ecs-attempt-1, node-ecs-attempt-2 ]
41+
if: always()
42+
uses: ./.github/workflows/enablement-test-publish-result.yml
43+
secrets: inherit
44+
with:
45+
aws-region: ${{ inputs.aws-region }}
46+
caller-workflow-name: ${{ inputs.caller-workflow-name }}
47+
validation-result: ${{ needs.node-ecs-attempt-1.outputs.validation-result || needs.node-ecs-attempt-2.outputs.validation-result }}
48+
49+
publish-metric-attempt-2:
50+
needs: [ node-ecs-attempt-1, node-ecs-attempt-2, publish-metric-attempt-1 ]
51+
if: ${{ always() && needs.publish-metric-attempt-1.outputs.job-started != 'true' }}
52+
uses: ./.github/workflows/enablement-test-publish-result.yml
53+
secrets: inherit
54+
with:
55+
aws-region: ${{ inputs.aws-region }}
56+
caller-workflow-name: ${{ inputs.caller-workflow-name }}
57+
validation-result: ${{ needs.node-ecs-attempt-1.outputs.validation-result || needs.node-ecs-attempt-2.outputs.validation-result }}
Lines changed: 275 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,275 @@
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 E2E 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 ECS 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+
adot-image-name:
18+
required: false
19+
type: string
20+
cwagent-image-name:
21+
required: false
22+
type: string
23+
outputs:
24+
job-started:
25+
value: ${{ jobs.node-ecs.outputs.job-started }}
26+
validation-result:
27+
value: ${{ jobs.node-ecs.outputs.validation-result }}
28+
29+
permissions:
30+
id-token: write
31+
contents: read
32+
33+
env:
34+
E2E_TEST_AWS_REGION: ${{ inputs.aws-region }}
35+
CALLER_WORKFLOW_NAME: ${{ inputs.caller-workflow-name }}
36+
ADOT_IMAGE_NAME: ${{ inputs.adot-image-name }}
37+
CLUSTER_NAME: e2e-test-node
38+
SAMPLE_APP_NAME: main-service-node
39+
METRIC_NAMESPACE: ApplicationSignals
40+
LOG_GROUP_NAME: /aws/application-signals/data
41+
TEST_RESOURCES_FOLDER: ${GITHUB_WORKSPACE}
42+
E2E_TEST_ACCOUNT_ID: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ACCOUNT_ID }}
43+
E2E_TEST_ROLE_NAME: ${{ secrets.APPLICATION_SIGNALS_E2E_TEST_ROLE_NAME }}
44+
45+
jobs:
46+
node-ecs:
47+
runs-on: ubuntu-latest
48+
outputs:
49+
job-started: ${{ steps.job-started.outputs.job-started }}
50+
validation-result: ${{ steps.validation-result.outputs.validation-result }}
51+
steps:
52+
- name: Check if the job started
53+
id: job-started
54+
run: echo "job-started=true" >> $GITHUB_OUTPUT
55+
56+
- name: Generate testing id and sample app namespace
57+
run: |
58+
echo TESTING_ID="${{ github.job }}-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}" >> $GITHUB_ENV
59+
60+
- uses: actions/checkout@v4
61+
with:
62+
repository: 'aws-observability/aws-application-signals-test-framework'
63+
ref: ${{ env.CALLER_WORKFLOW_NAME == 'main-build' && 'main' || github.ref }}
64+
fetch-depth: 0
65+
66+
# We initialize Gradlew Daemon early on during the workflow because sometimes initialization
67+
# fails due to transient issues. If it fails here, then we will try again later before the validators
68+
- name: Initiate Gradlew Daemon
69+
id: initiate-gradlew
70+
uses: ./.github/workflows/actions/execute_and_retry
71+
continue-on-error: true
72+
with:
73+
command: "./gradlew :validator:build"
74+
cleanup: "./gradlew clean"
75+
max_retry: 3
76+
sleep_time: 60
77+
78+
- name: Configure AWS Credentials
79+
uses: aws-actions/configure-aws-credentials@v4
80+
with:
81+
role-to-assume: arn:aws:iam::${{ env.E2E_TEST_ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
82+
aws-region: us-east-1
83+
84+
- name: Retrieve account
85+
uses: aws-actions/aws-secretsmanager-get-secrets@v1
86+
with:
87+
secret-ids: |
88+
ACCOUNT_ID, region-account/${{ env.E2E_TEST_AWS_REGION }}
89+
NODE_MAIN_SAMPLE_APP_IMAGE, e2e-test/node-main-sample-app-image
90+
NODE_REMOTE_SAMPLE_APP_IMAGE, e2e-test/node-remote-sample-app-image
91+
92+
# If the workflow is running as a canary, then we want to log in to the aws account in the appropriate region
93+
- name: Configure AWS Credentials
94+
if: ${{ github.event.repository.name == 'aws-application-signals-test-framework' }}
95+
uses: aws-actions/configure-aws-credentials@v4
96+
with:
97+
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
98+
aws-region: ${{ env.E2E_TEST_AWS_REGION }}
99+
100+
- name: Initiate Terraform
101+
uses: ./.github/workflows/actions/execute_and_retry
102+
with:
103+
command: "cd ${{ env.TEST_RESOURCES_FOLDER }}/terraform/node/ecs && terraform init && terraform validate"
104+
cleanup: "rm -rf .terraform && rm -rf .terraform.lock.hcl"
105+
max_retry: 6
106+
sleep_time: 60
107+
108+
- name: Set Sample App Image
109+
run: |
110+
echo MAIN_SAMPLE_APP_IMAGE_URI="${{ env.ACCOUNT_ID }}.dkr.ecr.${{ env.E2E_TEST_AWS_REGION }}.amazonaws.com/${{ env.NODE_MAIN_SAMPLE_APP_IMAGE }}" >> $GITHUB_ENV
111+
echo REMOTE_SAMPLE_APP_IMAGE_URI="${{ env.ACCOUNT_ID }}.dkr.ecr.${{ env.E2E_TEST_AWS_REGION }}.amazonaws.com/${{ env.NODE_REMOTE_SAMPLE_APP_IMAGE }}" >> $GITHUB_ENV
112+
113+
- name: Set ADOT Node image environment variable
114+
run: |
115+
if [ "${{ github.event.repository.name }}" = "aws-otel-js-instrumentation" ]; then
116+
# Use the staging image build by the ADOT node repo
117+
echo ADOT_INSTRUMENTATION_IMAGE_URI="${{ env.ADOT_IMAGE_NAME }}" >> $GITHUB_ENV
118+
else
119+
ADOT_INSTRUMENTATION_IMAGE_TAG=$(curl -s -I -L 'https://github.com/aws-observability/aws-otel-js-instrumentation/releases/latest' | grep -i Location | awk -F'/tag/' '{print $2}' | tr -d '\r')
120+
echo ADOT_INSTRUMENTATION_IMAGE_URI="public.ecr.aws/aws-observability/adot-autoinstrumentation-node:$ADOT_INSTRUMENTATION_IMAGE_TAG" >> $GITHUB_ENV
121+
fi
122+
123+
# Switch to use the public image for CW Agent
124+
- name: Set Get CW Agent command environment variable
125+
run: |
126+
if [ "${{ github.event.repository.name }}" = "amazon-cloudwatch-agent" ]; then
127+
echo CWAGENT_IMAGE_URI="${{ secrets.AWS_ECR_PRIVATE_REGISTRY }}/cwagent-integration-test:${{ github.sha }}" >> $GITHUB_ENV
128+
else
129+
echo CWAGENT_IMAGE_URI="public.ecr.aws/cloudwatch-agent/cloudwatch-agent:latest" >> $GITHUB_ENV
130+
fi
131+
132+
- name: Deploy sample app via terraform and wait for the endpoint to come online
133+
id: deploy-sample-app
134+
working-directory: terraform/node/ecs
135+
run: |
136+
# Attempt to deploy the sample app on an EKS instance and wait for its endpoint to come online.
137+
# There may be occasional failures due to transitivity issues, so try up to 2 times.
138+
# deployment_failed of 0 indicates that both the terraform deployment and the endpoint are running, while 1 indicates
139+
# that it failed at some point
140+
retry_counter=0
141+
max_retry=2
142+
while [ $retry_counter -lt $max_retry ]; do
143+
echo "Attempt $retry_counter"
144+
deployment_failed=0
145+
terraform apply -auto-approve \
146+
-var="test_id=${{ env.TESTING_ID }}" \
147+
-var="aws_region=${{ env.E2E_TEST_AWS_REGION }}" \
148+
-var="ecs_cluster_name=${{ env.CLUSTER_NAME }}-${{ env.TESTING_ID }}" \
149+
-var="sample_app_name=${{ env.SAMPLE_APP_NAME }}-${{ env.TESTING_ID }}" \
150+
-var="sample_app_image=${{ env.MAIN_SAMPLE_APP_IMAGE_URI }}" \
151+
-var="sample_remote_app_image=${{ env.REMOTE_SAMPLE_APP_IMAGE_URI }}" \
152+
-var="adot_instrumentation_image=${{ env.ADOT_INSTRUMENTATION_IMAGE_URI }}" \
153+
-var="cwagent_image=${{ env.CWAGENT_IMAGE_URI }}" \
154+
|| deployment_failed=$?
155+
156+
if [ $deployment_failed -ne 0 ]; then
157+
echo "Terraform deployment was unsuccessful. Will attempt to retry deployment."
158+
fi
159+
160+
# If the deployment_failed is 1 then either the terraform deployment or the endpoint connection failed, so first destroy the
161+
# resources created from terraform and try again.
162+
if [ $deployment_failed -eq 1 ]; then
163+
echo "Destroying terraform"
164+
terraform destroy -auto-approve \
165+
-var="test_id=${{ env.TESTING_ID }}" \
166+
-var="aws_region=${{ env.E2E_TEST_AWS_REGION }}" \
167+
-var="ecs_cluster_name=${{ env.CLUSTER_NAME }}-${{ env.TESTING_ID }}" \
168+
-var="sample_app_name=${{ env.SAMPLE_APP_NAME }}-${{ env.TESTING_ID }}" \
169+
-var="sample_app_image=${{ env.MAIN_SAMPLE_APP_IMAGE_URI }}" \
170+
-var="sample_remote_app_image=${{ env.REMOTE_SAMPLE_APP_IMAGE_URI }}" \
171+
-var="adot_instrumentation_image=${{ env.ADOT_INSTRUMENTATION_IMAGE_URI }}" \
172+
-var="cwagent_image=${{ env.CWAGENT_IMAGE_URI }}"
173+
174+
retry_counter=$(($retry_counter+1))
175+
else
176+
# If deployment succeeded, then exit the loop
177+
break
178+
fi
179+
180+
if [ $retry_counter -ge $max_retry ]; then
181+
echo "Max retry reached, failed to deploy terraform and connect to the endpoint. Exiting code"
182+
exit 1
183+
fi
184+
done
185+
186+
- name: Sleep to Wait for Canary Generated and Log Artifact Versions
187+
run: |
188+
sleep 120
189+
echo "ADOT Image: ${{ env.ADOT_INSTRUMENTATION_IMAGE_URI }}";
190+
echo "CW Agent Image: ${{ env.CWAGENT_IMAGE_URI }}";
191+
192+
- name: Initiate Gradlew Daemon
193+
if: steps.initiate-gradlew == 'failure'
194+
uses: ./.github/workflows/actions/execute_and_retry
195+
continue-on-error: true
196+
with:
197+
command: "./gradlew :validator:build"
198+
cleanup: "./gradlew clean"
199+
max_retry: 3
200+
sleep_time: 60
201+
202+
# Validation for app signals telemetry data
203+
- name: Call endpoint and validate generated EMF logs
204+
id: log-validation
205+
if: steps.deploy-sample-app.outcome == 'success' && !cancelled()
206+
run: ./gradlew validator:run --args='-c node/ecs/log-validation.yml
207+
--testing-id ${{ env.TESTING_ID }}
208+
--region ${{ env.E2E_TEST_AWS_REGION }}
209+
--account-id ${{ env.ACCOUNT_ID }}
210+
--metric-namespace ${{ env.METRIC_NAMESPACE }}
211+
--log-group ${{ env.LOG_GROUP_NAME }}
212+
--platform-info ${{ env.CLUSTER_NAME }}-${{ env.TESTING_ID }}
213+
--service-name ${{env.SAMPLE_APP_NAME }}-${{ env.TESTING_ID }}
214+
--rollup'
215+
216+
- name: Call endpoints and validate generated metrics
217+
id: metric-validation
218+
if: (steps.deploy-sample-app.outcome == 'success' || steps.log-validation.outcome == 'failure') && !cancelled()
219+
run: ./gradlew validator:run --args='-c node/ecs/metric-validation.yml
220+
--testing-id ${{ env.TESTING_ID }}
221+
--region ${{ env.E2E_TEST_AWS_REGION }}
222+
--account-id ${{ env.ACCOUNT_ID }}
223+
--metric-namespace ${{ env.METRIC_NAMESPACE }}
224+
--log-group ${{ env.LOG_GROUP_NAME }}
225+
--platform-info ${{ env.CLUSTER_NAME }}-${{ env.TESTING_ID }}
226+
--service-name ${{env.SAMPLE_APP_NAME }}-${{ env.TESTING_ID }}
227+
--rollup'
228+
229+
- name: Call endpoints and validate generated traces
230+
id: trace-validation
231+
if: (steps.deploy-sample-app.outcome == 'success' || steps.log-validation.outcome == 'failure' || steps.metric-validation.outcome == 'failure') && !cancelled()
232+
run: ./gradlew validator:run --args='-c node/ecs/trace-validation.yml
233+
--testing-id ${{ env.TESTING_ID }}
234+
--region ${{ env.E2E_TEST_AWS_REGION }}
235+
--account-id ${{ env.ACCOUNT_ID }}
236+
--metric-namespace ${{ env.METRIC_NAMESPACE }}
237+
--log-group ${{ env.LOG_GROUP_NAME }}
238+
--platform-info ${{ env.CLUSTER_NAME }}-${{ env.TESTING_ID }}
239+
--service-name ${{env.SAMPLE_APP_NAME }}-${{ env.TESTING_ID }}
240+
--rollup'
241+
242+
- name: Refresh AWS Credentials
243+
if: ${{ github.event.repository.name == 'aws-application-signals-test-framework' }}
244+
uses: aws-actions/configure-aws-credentials@v4
245+
with:
246+
role-to-assume: arn:aws:iam::${{ env.ACCOUNT_ID }}:role/${{ env.E2E_TEST_ROLE_NAME }}
247+
aws-region: ${{ env.E2E_TEST_AWS_REGION }}
248+
249+
- name: Save test results
250+
if: always()
251+
id: validation-result
252+
run: |
253+
if [ "${{ steps.log-validation.outcome }}" = "success" ] && [ "${{ steps.metric-validation.outcome }}" = "success" ] && [ "${{ steps.trace-validation.outcome }}" = "success" ]; then
254+
echo "validation-result=success" >> $GITHUB_OUTPUT
255+
else
256+
echo "validation-result=failure" >> $GITHUB_OUTPUT
257+
fi
258+
259+
# Clean up Procedures
260+
261+
- name: Terraform destroy
262+
if: always()
263+
continue-on-error: true
264+
timeout-minutes: 5
265+
working-directory: terraform/node/ecs
266+
run: |
267+
terraform destroy -auto-approve \
268+
-var="test_id=${{ env.TESTING_ID }}" \
269+
-var="aws_region=${{ env.E2E_TEST_AWS_REGION }}" \
270+
-var="ecs_cluster_name=${{ env.CLUSTER_NAME }}-${{ env.TESTING_ID }}" \
271+
-var="sample_app_name=${{ env.SAMPLE_APP_NAME }}-${{ env.TESTING_ID }}" \
272+
-var="sample_app_image=${{ env.MAIN_SAMPLE_APP_IMAGE_URI }}" \
273+
-var="sample_remote_app_image=${{ env.REMOTE_SAMPLE_APP_IMAGE_URI }}" \
274+
-var="adot_instrumentation_image=${{ env.ADOT_INSTRUMENTATION_IMAGE_URI }}" \
275+
-var="cwagent_image=${{ env.CWAGENT_IMAGE_URI }}"

0 commit comments

Comments
 (0)