Skip to content

Commit 6b2c926

Browse files
committed
Added java e2e test
1 parent 1d79c7d commit 6b2c926

File tree

3 files changed

+234
-4
lines changed

3 files changed

+234
-4
lines changed

.github/workflows/e2e-java.yml

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
name: E2E - Java Layer
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
logzio_api_url:
7+
description: "Logz.io API base URL (default https://api.logz.io)"
8+
required: false
9+
default: "https://api.logz.io"
10+
aws_region:
11+
description: "AWS Region"
12+
required: false
13+
default: "us-east-1"
14+
15+
push:
16+
branches:
17+
- feat/unified-lambda-layer
18+
19+
permissions:
20+
contents: read
21+
22+
env:
23+
AWS_REGION: ${{ inputs.aws_region || 'us-east-1' }}
24+
AWS_DEFAULT_REGION: ${{ inputs.aws_region || 'us-east-1' }}
25+
ARCHITECTURE: amd64
26+
FUNCTION_NAME: one-layer-e2e-test-java
27+
LAYER_BASE_NAME: otel-java-extension-e2e
28+
SERVICE_NAME: logzio-e2e-java-service
29+
LOGZIO_REGION: us
30+
31+
jobs:
32+
build-layer:
33+
runs-on: ubuntu-latest
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Set up Go (for Collector)
39+
uses: actions/setup-go@v5
40+
with:
41+
go-version-file: collector/go.mod
42+
43+
- name: Set up Java
44+
uses: actions/setup-java@v4
45+
with:
46+
distribution: 'temurin'
47+
java-version: '17'
48+
cache: 'gradle'
49+
50+
- name: Build combined Java layer (amd64)
51+
run: |
52+
cd java
53+
ARCHITECTURE=${ARCHITECTURE} ./build-combined.sh
54+
55+
- name: Upload layer artifact
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: otel-java-extension-layer.zip
59+
path: java/build/otel-java-extension-layer-${{ env.ARCHITECTURE }}.zip
60+
61+
publish-update-invoke:
62+
runs-on: ubuntu-latest
63+
needs: build-layer
64+
outputs:
65+
layer_arn: ${{ steps.publish.outputs.layer_arn }}
66+
e2e_label: ${{ steps.vars.outputs.e2e_label }}
67+
steps:
68+
- name: Checkout
69+
uses: actions/checkout@v4
70+
71+
- name: Download layer artifact
72+
uses: actions/download-artifact@v4
73+
with:
74+
name: otel-java-extension-layer.zip
75+
76+
- name: Configure AWS (User Credentials)
77+
uses: aws-actions/configure-aws-credentials@v4
78+
with:
79+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
80+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
81+
aws-region: ${{ env.AWS_REGION }}
82+
83+
- name: Publish layer version
84+
id: publish
85+
shell: bash
86+
run: |
87+
set -euo pipefail
88+
LAYER_NAME="${LAYER_BASE_NAME}-amd64"
89+
ZIP_FILE="otel-java-extension-layer-${ARCHITECTURE}.zip"
90+
ARN=$(aws lambda publish-layer-version \
91+
--layer-name "$LAYER_NAME" \
92+
--license-info "Apache-2.0" \
93+
--compatible-architectures x86_64 \
94+
--compatible-runtimes java11 java17 \
95+
--zip-file fileb://$ZIP_FILE \
96+
--query 'LayerVersionArn' --output text)
97+
echo "layer_arn=$ARN" >> "$GITHUB_OUTPUT"
98+
99+
- name: Prepare variables
100+
id: vars
101+
run: |
102+
echo "e2e_label=java-e2e-${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT"
103+
104+
- name: Check function exists and get current config
105+
run: |
106+
echo "Checking if function exists and its current configuration..."
107+
aws lambda get-function-configuration --function-name "${FUNCTION_NAME}" --query '{Role:Role,KMSKeyArn:KMSKeyArn,State:State,LastUpdateStatus:LastUpdateStatus}' --output table || {
108+
echo "❌ Function ${FUNCTION_NAME} does not exist or is not accessible."
109+
exit 1
110+
}
111+
112+
echo "Current environment variables:"
113+
aws lambda get-function-configuration --function-name "${FUNCTION_NAME}" --query 'Environment.Variables' --output json || echo "No environment variables set"
114+
115+
- name: Update Lambda configuration
116+
run: |
117+
echo "Updating function configuration..."
118+
aws lambda update-function-configuration \
119+
--function-name "${FUNCTION_NAME}" \
120+
--layers "${{ steps.publish.outputs.layer_arn }}" \
121+
--environment "Variables={AWS_LAMBDA_EXEC_WRAPPER=/opt/otel-handler,OPENTELEMETRY_COLLECTOR_CONFIG_URI=/opt/collector-config/config.e2e.yaml,OTEL_SERVICE_NAME=${SERVICE_NAME},OTEL_TRACES_SAMPLER=always_on,OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf,OTEL_RESOURCE_ATTRIBUTES=deployment.environment=${{ steps.vars.outputs.e2e_label }},ENVIRONMENT=${{ steps.vars.outputs.e2e_label }},LOGZIO_REGION=${LOGZIO_REGION},LOGZIO_LOGS_TOKEN=${{ secrets.LOGZIO_LOGS_TOKEN }},LOGZIO_TRACES_TOKEN=${{ secrets.LOGZIO_TRACES_TOKEN }},LOGZIO_METRICS_TOKEN=${{ secrets.LOGZIO_METRICS_TOKEN }}}"
122+
123+
echo "Waiting for function update to complete..."
124+
aws lambda wait function-updated --function-name "${FUNCTION_NAME}"
125+
126+
echo "Updated configuration:"
127+
aws lambda get-function-configuration --function-name "${FUNCTION_NAME}" --query '{Layers:Layers[].Arn,Environment:Environment.Variables}' --output json
128+
129+
- name: Invoke function multiple times
130+
run: |
131+
echo "Invoking function first time..."
132+
aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response1.json
133+
echo "First invocation response:"
134+
cat response1.json
135+
echo ""
136+
137+
echo "Invoking function second time..."
138+
aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response2.json
139+
echo "Second invocation response:"
140+
cat response2.json
141+
echo ""
142+
143+
echo "Sleeping for 5 seconds before additional invocations..."
144+
sleep 5
145+
146+
echo "Invoking function third time..."
147+
aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response3.json
148+
echo "Third invocation response:"
149+
cat response3.json
150+
echo ""
151+
152+
echo "Invoking function fourth time..."
153+
aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response4.json
154+
echo "Fourth invocation response:"
155+
cat response4.json
156+
echo ""
157+
158+
echo "Invoking function fifth time..."
159+
aws lambda invoke --function-name "${FUNCTION_NAME}" --payload '{}' --cli-binary-format raw-in-base64-out response5.json
160+
echo "Fifth invocation response:"
161+
cat response5.json
162+
echo ""
163+
164+
- name: Check CloudWatch logs
165+
run: |
166+
echo "Checking recent CloudWatch logs for the function..."
167+
LOG_GROUP_NAME="/aws/lambda/${FUNCTION_NAME}"
168+
169+
# Get recent log events (last 5 minutes)
170+
aws logs filter-log-events \
171+
--log-group-name "$LOG_GROUP_NAME" \
172+
--start-time $(date -d '5 minutes ago' +%s)000 \
173+
--query 'events[].message' \
174+
--output text || {
175+
echo "❌ Could not fetch CloudWatch logs. Log group might not exist or no recent logs."
176+
echo "Checking if log group exists..."
177+
aws logs describe-log-groups --log-group-name-prefix "$LOG_GROUP_NAME" --query 'logGroups[].logGroupName' --output text
178+
}
179+
180+
verify-e2e:
181+
runs-on: ubuntu-latest
182+
needs: publish-update-invoke
183+
steps:
184+
- name: Checkout
185+
uses: actions/checkout@v4
186+
187+
- name: Set up Go
188+
uses: actions/setup-go@v5
189+
with:
190+
go-version: '1.21'
191+
192+
- name: Run E2E verification tests
193+
working-directory: e2e_tests
194+
env:
195+
LOGZIO_API_KEY: ${{ secrets.LOGZIO_API_KEY }}
196+
LOGZIO_API_URL: ${{ inputs.logzio_api_url || 'https://api.logz.io' }}
197+
LOGZIO_API_METRICS_KEY: ${{ secrets.LOGZIO_API_METRICS_KEY }}
198+
LOGZIO_METRICS_QUERY_URL: ${{ inputs.logzio_api_url || 'https://api.logz.io' }}
199+
LOGZIO_API_TRACES_KEY: ${{ secrets.LOGZIO_API_TRACES_KEY }}
200+
E2E_TEST_ENVIRONMENT_LABEL: ${{ needs.publish-update-invoke.outputs.e2e_label }}
201+
EXPECTED_LAMBDA_FUNCTION_NAME: one-layer-e2e-test-java
202+
EXPECTED_SERVICE_NAME: ${{ env.SERVICE_NAME }}
203+
GITHUB_RUN_ID: ${{ github.run_id }}
204+
AWS_REGION: ${{ env.AWS_REGION }}
205+
run: |
206+
go mod tidy
207+
go test ./... -v -tags=e2e -run TestE2ERunner
208+
209+
cleanup:
210+
if: always()
211+
runs-on: ubuntu-latest
212+
needs: [publish-update-invoke, verify-e2e]
213+
steps:
214+
- name: Configure AWS (User Credentials)
215+
uses: aws-actions/configure-aws-credentials@v4
216+
with:
217+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
218+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
219+
aws-region: ${{ inputs.aws_region || 'us-east-1' }}
220+
- name: Delete published layer version
221+
if: ${{ needs.publish-update-invoke.outputs.layer_arn != '' }}
222+
shell: bash
223+
run: |
224+
ARN="${{ needs.publish-update-invoke.outputs.layer_arn }}"
225+
LAYER_NAME=$(echo "$ARN" | cut -d: -f7)
226+
LAYER_VERSION=$(echo "$ARN" | cut -d: -f8)
227+
aws lambda delete-layer-version --layer-name "$LAYER_NAME" --version-number "$LAYER_VERSION" || echo "Failed to delete layer version."
228+
229+

.github/workflows/e2e-nodejs.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ on:
1212
required: false
1313
default: "us-east-1"
1414

15-
push:
16-
branches:
17-
- feat/unified-lambda-layer
18-
1915
permissions:
2016
contents: read
2117

java/build-combined.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ mkdir -p "$WORKSPACE_DIR/collector-config"
7777
cp "$COLLECTOR_DIR/build/extensions"/* "$WORKSPACE_DIR/extensions/"
7878
cp "$COLLECTOR_DIR/config.yaml" "$WORKSPACE_DIR/collector-config/"
7979

80+
# Include E2E-specific collector config for testing workflows
81+
if [[ -f "$COLLECTOR_DIR/config.e2e.yaml" ]]; then
82+
cp "$COLLECTOR_DIR/config.e2e.yaml" "$WORKSPACE_DIR/collector-config/"
83+
fi
84+
8085
# 6. Create the final layer package
8186
echo "--> Creating final layer .zip package..."
8287
(

0 commit comments

Comments
 (0)