Skip to content

Commit 5e10150

Browse files
author
Davide Melfi
committed
chore: add proper testing
1 parent 35758d0 commit 5e10150

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

.github/workflows/aws-lambda-java-profiler.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ jobs:
5858
working-directory: ./experimental/aws-lambda-java-profiler
5959
run: ./integration_tests/invoke_function.sh
6060

61+
- name: Invoke Java Custom Options function
62+
working-directory: ./experimental/aws-lambda-java-profiler
63+
run: ./integration_tests/invoke_function_custom_options.sh
64+
6165
- name: Download from s3
6266
working-directory: ./experimental/aws-lambda-java-profiler
6367
run: ./integration_tests/download_from_s3.sh

experimental/aws-lambda-java-profiler/integration_tests/create_function.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22

33
# Set variables
44
FUNCTION_NAME="aws-lambda-java-profiler-function-${GITHUB_RUN_ID}"
5+
FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS="aws-lambda-java-profiler-function-custom-profiler-options-${GITHUB_RUN_ID}"
56
ROLE_NAME="aws-lambda-java-profiler-role-${GITHUB_RUN_ID}"
67
HANDLER="helloworld.Handler::handleRequest"
78
RUNTIME="java21"
89
LAYER_ARN=$(cat /tmp/layer_arn)
910

1011
JAVA_TOOL_OPTIONS="-XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -javaagent:/opt/profiler-extension.jar"
1112
AWS_LAMBDA_PROFILER_RESULTS_BUCKET_NAME="aws-lambda-java-profiler-bucket-${GITHUB_RUN_ID}"
13+
AWS_LAMBDA_PROFILER_START_COMMAND="start,event=wall,interval=1us"
14+
AWS_LAMBDA_PROFILER_STOP_COMMAND="stop,file=%s,include=*AWSLambda.main,include=start_thread"
1215

1316
# Compile the Hello World project
1417
cd integration_tests/helloworld
@@ -63,6 +66,19 @@ aws lambda create-function \
6366
--environment "Variables={JAVA_TOOL_OPTIONS='$JAVA_TOOL_OPTIONS',AWS_LAMBDA_PROFILER_RESULTS_BUCKET_NAME='$AWS_LAMBDA_PROFILER_RESULTS_BUCKET_NAME',AWS_LAMBDA_PROFILER_DEBUG='true'}" \
6467
--layers "$LAYER_ARN"
6568

69+
70+
# Create Lambda function custom profiler options
71+
aws lambda create-function \
72+
--function-name "$FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS" \
73+
--runtime "$RUNTIME" \
74+
--role "$ROLE_ARN" \
75+
--handler "$HANDLER" \
76+
--timeout 30 \
77+
--memory-size 512 \
78+
--zip-file fileb://integration_tests/helloworld/build/distributions/code.zip \
79+
--environment "Variables={JAVA_TOOL_OPTIONS='$JAVA_TOOL_OPTIONS',AWS_LAMBDA_PROFILER_RESULTS_BUCKET_NAME='$AWS_LAMBDA_PROFILER_RESULTS_BUCKET_NAME',AWS_LAMBDA_PROFILER_DEBUG='true',AWS_LAMBDA_PROFILER_START_COMMAND='$AWS_LAMBDA_PROFILER_START_COMMAND',AWS_LAMBDA_PROFILER_STOP_COMMAND='$AWS_LAMBDA_PROFILER_STOP_COMMAND'}" \
80+
--layers "$LAYER_ARN"
81+
6682
echo "Lambda function '$FUNCTION_NAME' created successfully with Java 21 runtime"
6783

6884
echo "Waiting the function to be ready so we can invoke it..."
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#!/bin/bash
2+
3+
# Set variables
4+
FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS="aws-lambda-java-profiler-function-custom-profiler-options-${GITHUB_RUN_ID}"
5+
PAYLOAD='{"key": "value"}'
6+
7+
# Expected profiler commands (should match create_function.sh)
8+
EXPECTED_START_COMMAND="start,event=wall,interval=1us"
9+
EXPECTED_STOP_COMMAND="stop,file=%s,include=*AWSLambda.main,include=start_thread"
10+
11+
echo "Invoking Lambda function with custom profiler options: $FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS"
12+
13+
# Invoke the Lambda function synchronously and capture the response
14+
RESPONSE=$(aws lambda invoke \
15+
--function-name "$FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS" \
16+
--payload "$PAYLOAD" \
17+
--cli-binary-format raw-in-base64-out \
18+
--log-type Tail \
19+
output.json)
20+
21+
# Extract the status code and log result from the response
22+
STATUS_CODE=$(echo "$RESPONSE" | jq -r '.StatusCode')
23+
LOG_RESULT=$(echo "$RESPONSE" | jq -r '.LogResult')
24+
25+
echo "Function invocation completed with status code: $STATUS_CODE"
26+
27+
# Decode and display the logs
28+
if [ -n "$LOG_RESULT" ]; then
29+
echo "Function logs:"
30+
echo "$LOG_RESULT" | base64 --decode
31+
else
32+
echo "No logs available."
33+
fi
34+
35+
# Display the function output
36+
echo "Function output:"
37+
cat output.json
38+
39+
# Verify profiler started
40+
echo "$LOG_RESULT" | base64 --decode | grep "starting the profiler for coldstart" || exit 1
41+
42+
# Verify custom start command is being used
43+
echo "$LOG_RESULT" | base64 --decode | grep "$EXPECTED_START_COMMAND" || exit 1
44+
45+
# Verify no upload on cold start
46+
echo "$LOG_RESULT" | base64 --decode | grep -v "uploading" || exit 1
47+
48+
# Clean up the output file
49+
rm output.json
50+
51+
52+
# Invoke it a second time for warm start
53+
echo "Invoking Lambda function (warm start): $FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS"
54+
55+
# Invoke the Lambda function synchronously and capture the response
56+
RESPONSE=$(aws lambda invoke \
57+
--function-name "$FUNCTION_NAME_CUSTOM_PROFILER_OPTIONS" \
58+
--payload "$PAYLOAD" \
59+
--cli-binary-format raw-in-base64-out \
60+
--log-type Tail \
61+
output.json)
62+
63+
# Extract the status code and log result from the response
64+
STATUS_CODE=$(echo "$RESPONSE" | jq -r '.StatusCode')
65+
LOG_RESULT=$(echo "$RESPONSE" | jq -r '.LogResult')
66+
67+
echo "Function invocation completed with status code: $STATUS_CODE"
68+
69+
# Decode and display the logs
70+
if [ -n "$LOG_RESULT" ]; then
71+
echo "Function logs:"
72+
echo "$LOG_RESULT" | base64 --decode
73+
else
74+
echo "No logs available."
75+
fi
76+
77+
# Display the function output
78+
echo "Function output:"
79+
cat output.json
80+
81+
# Verify upload happens on warm start
82+
echo "$LOG_RESULT" | base64 --decode | grep "uploading" || exit 1
83+
84+
# Verify custom stop command is being used
85+
echo "$LOG_RESULT" | base64 --decode | grep "$EXPECTED_STOP_COMMAND" || exit 1
86+
87+
# Clean up the output file
88+
rm output.json

0 commit comments

Comments
 (0)