10000 Restructure snapshots dir, add input events · DataDog/datadog-lambda-python@44c9d2a · GitHub
[go: up one dir, main page]

Skip to content

Commit 44c9d2a

Browse files
committed
Restructure snapshots dir, add input events
1 parent bf82854 commit 44c9d2a

File tree

64 files changed

+505
-104
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+505
-104
lines changed

scripts/run_integration_tests.sh

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,36 +42,49 @@ else
4242
echo "Not building layers, ensure they've already been built or re-run with 'REBUILD_LAYERS=true ./scripts/run_integration_tests.sh'"
4343
fi
4444

45-
echo "Deploying functions"
4645
cd $integration_tests_dir
46+
input_event_files=$(ls ./input_events)
47+
# Sort events by name so that snapshots stay consistent
48+
input_event_files=($(for file_name in ${input_event_files[@]}; do echo $file_name; done | sort))
49+
50+
echo "Deploying functions"
4751
serverless deploy
4852

4953
echo "Invoking functions"
5054
set +e # Don't immediately exit this script if an invocation fails or there's a diff
5155
for handler_name in "${LAMBDA_HANDLERS[@]}"; do
5256
for runtime in "${RUNTIMES[@]}"; do
5357
function_name="${handler_name}_${runtime}"
54-
function_snapshot_path="./snapshots/$function_name.return_value"
55-
56-
return_value=$(serverless invoke -f $function_name)
57-
58-
if [ -n "$UPDATE_SNAPSHOTS" ] || [ ! -f $function_snapshot_path ]; then
59-
# If $UPDATE_SNAPSHOTS is set to true, write the new logs over the current snapshot
60-
# If the snapshot file doesn't exist yet, we create it
61-
echo "Writing return value snapshot for $function_name"
62-
echo "$return_value" >$function_snapshot_path
63-
else
64-
# Compare new return value to snapshot
65-
diff_output=$(echo "$return_value" | diff - $function_snapshot_path)
66-
if [ $? -eq 1 ]; then
67-
echo "Failed: Return value for $function_name does not match snapshot:"
68-
echo "$diff_output"
69-
mismatch_found=true
58+
# Invoke function once for each input event
59+
for input_event_file in "${input_event_files[@]}"; do
60+
echo "input_event_file=$input_event_file"
61+
# Get event name without trailing ".json" so we can build the snapshot name
62+
input_event_name=$(echo "$input_event_file" | sed "s/.json//")
63+
# Return value snapshot file format is snapshots/return_values/{handler}_{runtime}_{input-event}
64+
snapshot_path="./snapshots/return_values/${function_name}_${input_event_name}.json"
65+
66+
return_value=$(serverless invoke -f $function_name --path "./input_events/$input_event_file")
67+
68+
if [ -n "$UPDATE_SNAPSHOTS" ] || [ ! -f $snapshot_path ]; then
69+
# If $UPDATE_SNAPSHOTS is set to true, write the new logs over the current snapshot
70+
# If the snapshot file doesn't exist yet, we create it
71+
echo "Writing return value snapshot for $snapshot_path"
72+
echo "$return_value" >$snapshot_path
7073
else
71-
echo "Ok: Return value for $function_name matches snapshot"
74+
# Compare new return value to snapshot
75+
diff_output=$(echo "$return_value" | diff - $snapshot_path)
76+
if [ $? -eq 1 ]; then
77+
echo "Failed: Return value for $function_name does not match snapshot:"
78+
echo "$diff_output"
79+
mismatch_found=true
80+
else
81+
echo "Ok: Return value for $function_name matches snapshot"
82+
fi
7283
fi
73-
fi
84+
done
85+
7486
done
87+
7588
done
7689
set -e
7790

@@ -82,7 +95,7 @@ echo "Fetching logs for invocations and comparing to snapshots"
8295
for handler_name in "${LAMBDA_HANDLERS[@]}"; do
8396
for runtime in "${RUNTIMES[@]}"; do
8497
function_name="${handler_name}_${runtime}"
85-
function_snapshot_path="./snapshots/$function_name.logs"
98+
function_snapshot_path="./snapshots/logs/$function_name.log"
8699

87100
# Fetch logs with serverless cli
88101
raw_logs=$(serverless logs -f $function_name --startTime $script_start_time)
@@ -92,6 +105,8 @@ for handler_name in "${LAMBDA_HANDLERS[@]}"; do
92105
echo "$raw_logs" |
93106
# Filter serverless cli errors
94107
sed '/Serverless: Recoverable error occurred/d' |
108+
# Remove blank lines
109+
sed '/^$/d' |
95110
# Normalize Lambda runtime report logs
96111
sed -E 's/(RequestId|TraceId|SegmentId|Duration|Memory Used|"e"): [a-z0-9\.\-]+/\1: XXXX/g' |
97112
# Normalize DD APM headers
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"path": "/test/hello",
3+
"headers": {
4+
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
5+
"Accept-Encoding": "gzip, deflate, lzma, sdch, br",
6+
"Accept-Language": "en-US,en;q=0.8",
7+
"CloudFront-Forwarded-Proto": "https",
8+
"CloudFront-Is-Desktop-Viewer": "true",
9+
"CloudFront-Is-Mobile-Viewer": "false",
10+
"CloudFront-Is-SmartTV-Viewer": "false",
11+
"CloudFront-Is-Tablet-Viewer": "false",
12+
"CloudFront-Viewer-Country": "US",
13+
"Host": "wt6mne2s9k.execute-api.us-west-2.amazonaws.com",
14+
"Upgrade-Insecure-Requests": "1",
15+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48",
16+
"Via": "1.1 fb7cca60f0ecd82ce07790c9c5eef16c.cloudfront.net (CloudFront)",
17+
"X-Amz-Cf-Id": "nBsWBOrSHMgnaROZJK1wGCZ9PcRcSpq_oSXZNQwQ10OTZL4cimZo3g==",
18+
"X-Forwarded-For": "192.168.100.1, 192.168.1.1",
19+
"X-Forwarded-Port": "443",
20+
"X-Forwarded-Proto": "https"
21+
},
22+
"pathParameters": {
23+
"proxy": "hello"
24+
},
25+
"requestContext": {
26+
"accountId": "123456789012",
27+
"resourceId": "us4z18",
28+
"stage": "test",
29+
"requestId": "41b45ea3-70b5-11e6-b7bd-69b5aaebc7d9",
30+
"identity": {
31+
"cognitoIdentityPoolId": "",
32+
"accountId": "",
33+
"cognitoIdentityId": "",
34+
"caller": "",
35+
"apiKey": "",
36+
"sourceIp": "192.168.100.1",
37+
"cognitoAuthenticationType": "",
38+
"cognitoAuthenticationProvider": "",
39+
"userArn": "",
40+
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.82 Safari/537.36 OPR/39.0.2256.48",
41+
"user": ""
42+
},
43+
"resourcePath": "/{proxy+}",
44+
"httpMethod": "GET",
45+
"apiId": "wt6mne2s9k"
46+
},
47+
"resource": "/{proxy+}",
48+
"httpMethod": "GET",
49+
"queryStringParameters": {
50+
"name": "me"
51+
},
52+
"stageVariables": {
53+
"stageVarName": "stageVarValue"
54+
}
55+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"Records": [
3+
{
4+
"EventVersion": "1.0",
5+
"EventSubscriptionArn": "arn:aws:sns:us-east-2:123456789012:sns-lambda:21be56ed-a058-49f5-8c98-aedd2564c486",
6+
"EventSource": "aws:sns",
7+
"Sns": {
8+
"SignatureVersion": "1",
9+
"Timestamp": "2019-01-02T12:45:07.000Z",
10+
"Signature": "tcc6faL2yUC6dgZdmrwh1Y4cGa/ebXEkAi6RibDsvpi+tE/1+82j...65r==",
11+
"SigningCertUrl": "https://sns.us-east-2.amazonaws.com/SimpleNotificationService-ac565b8b1a6c5d002d285f9598aa1d9b.pem",
12+
"MessageId": "95df01b4-ee98-5cb9-9903-4c221d41eb5e",
13+
"Message": "Hello from SNS!",
14+
"MessageAttributes": {
15+
"Test": {
16+
"Type": "String",
17+
"Value": "TestString"
18+
},
19+
"TestBinary": {
20+
"Type": "Binary",
21+
"Value": "TestBinary"
22+
}
23+
},
24+
"Type": "Notification",
25+
"UnsubscribeUrl": "https://sns.us-east-2.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:us-east-2:123456789012:test-lambda:21be56ed-a058-49f5-8c98-aedd2564c486",
26+
"TopicArn": "arn:aws:sns:us-east-2:123456789012:sns-lambda",
27+
"Subject": "TestInvoke"
28+
}
29+
}
30+
]
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"Records": [
3+
{
4+
"messageId": "059f36b4-87a3-44ab-83d2-661975830a7d",
5+
"receiptHandle": "AQEBwJnKyrHigUMZj6rYigCgxlaS3SLy0a...",
6+
"body": "Test message.",
7+
"attributes": {
8+
"ApproximateReceiveCount": "1",
9+
"SentTimestamp": "1545082649183",
10+
"SenderId": "AIDAIENQZJOLO23YVJ4VO",
11+
"ApproximateFirstReceiveTimestamp": "1545082649185"
12+
},
13+
"messageAttributes": {},
14+
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3",
15+
"eventSource": "aws:sqs",
16+
"eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue",
17+
"awsRegion": "us-east-2"
18+
},
19+
{
20+
"messageId": "2e1424d4-f796-459a-8184-9c92662be6da",
21+
"receiptHandle": "AQEBzWwaftRI0KuVm4tP+/7q1rGgNqicHq...",
22+
"body": "Test message.",
23+
"attributes": {
24+
"ApproximateReceiveCount": "1",
25+
"SentTimestamp": "1545082650636",
26+
"SenderId": "AIDAIENQZJOLO23YVJ4VO",
27+
"ApproximateFirstReceiveTimestamp": "1545082650649"
28+
},
29+
"messageAttributes": {},
30+
"md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3",
31+
"eventSource": "aws:sqs",
32+
"eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:my-queue",
33+
"awsRegion": "us-east-2"
34+
}
35+
]
36+
}

tests/integration/snapshots/async-metrics_python27.logs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/integ 10000 ration/snapshots/async-metrics_python36.logs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/integration/snapshots/async-metrics_python37.logs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/integration/snapshots/async-metrics_python38.logs

Lines changed: 0 additions & 7 deletions
This file was deleted.

tests/integration/snapshots/http-requests_python27.logs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/integration/snapshots/http-requests_python36.logs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/integration/snapshots/http-requests_python37.logs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/integration/snapshots/http-requests_python38.logs

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
START RequestId: XXXX Version: $LATEST
2+
{"e": XXXX, "m": "aws.lambda.enhanced.invocations", "t": ["region:us-east-1", "account_id:601427279990", "functionname:integration-tester-dev-async-metrics_python27", "cold_start:true", "memorysize:1024", "runtime:python2.7", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 1}
3+
{"e": XXXX, "m": "hello.dog", "t": ["team:serverless", "role:hello", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 1}
4+
{"e": XXXX, "m": "tests.integration.count", "t": ["test:integration", "role:hello", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 21}
5+
END RequestId: XXXX
6+
REPORT RequestId: XXXX Duration: XXXX ms Billed Duration: XXXX ms Memory Size: 1024 MB Max Memory Used: XXXX MB Init Duration: XXXX ms
7+
XRAY TraceId: XXXX SegmentId: XXXX Sampled: true
8+
START RequestId: XXXX Version: $LATEST
9+
{"e": XXXX, "m": "aws.lambda.enhanced.invocations", "t": ["region:us-east-1", "account_id:601427279990", "functionname:integration-tester-dev-async-metrics_python27", "cold_start:false", "memorysize:1024", "runtime:python2.7", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 1}
10+
{"e": XXXX, "m": "hello.dog", "t": ["team:serverless", "role:hello", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 1}
11+
{"e": XXXX, "m": "tests.integration.count", "t": ["test:integration", "role:hello", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 21}
12+
END RequestId: XXXX
13+
REPORT RequestId: XXXX Duration: XXXX ms Billed Duration: XXXX ms Memory Size: 1024 MB Max Memory Used: XXXX MB
14+
XRAY TraceId: XXXX SegmentId: XXXX Sampled: true
15+
START RequestId: XXXX Version: $LATEST
16+
{"e": XXXX, "m": "aws.lambda.enhanced.invocations", "t": ["region:us-east-1", "account_id:601427279990", "functionname:integration-tester-dev-async-metrics_python27", "cold_start:false", "memorysize:1024", "runtime:python2.7", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 1}
17+
{"e": XXXX, "m": "hello.dog", "t": ["team:serverless", "role:hello", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 1}
18+
{"e": XXXX, "m": "tests.integration.count", "t": ["test:integration", "role:hello", "dd_lambda_layer:datadog-python27_2.13.0"], "v": 21}
19+
END RequestId: XXXX
20+
REPORT RequestId: XXXX Duration: XXXX ms Billed Duration: XXXX ms Memory Size: 1024 MB Max Memory Used: XXXX MB
21+
XRAY TraceId: XXXX SegmentId: XXXX Sampled: true

0 commit comments

Comments
 (0)
0