Skip to content

Commit 63b3bee

Browse files
committed
[Java] Adaptive sampling test case
1 parent 3f3a55e commit 63b3bee

File tree

10 files changed

+759
-0
lines changed

10 files changed

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

.github/workflows/test.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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: Test
8+
on:
9+
push:
10+
branches:
11+
- java-adap
12+
13+
permissions:
14+
id-token: write
15+
contents: read
16+
17+
jobs:
18+
java-ec2-adaptive-sampling:
19+
uses: ./.github/workflows/java-ec2-adaptive-sampling-test.yml
20+
secrets: inherit
21+
with:
22+
caller-workflow-name: 'test'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"agent": {
3+
"debug": true,
4+
"region": "$REGION"
5+
},
6+
"traces": {
7+
"traces_collected": {
8+
"application_signals": {}
9+
}
10+
},
11+
"logs": {
12+
"metrics_collected": {
13+
"application_signals": {}
14+
}
15+
}
16+
}

0 commit comments

Comments
 (0)