Skip to content

Commit ee4b9b6

Browse files
[Python] Add ADOT SigV4 release test workflow + validations (#377)
1 parent e837423 commit ee4b9b6

21 files changed

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

0 commit comments

Comments
 (0)