Skip to content

Commit 082563b

Browse files
authored
Improve and fix integration tests (#33)
1 parent 598119e commit 082563b

15 files changed

+95
-103
lines changed

.github/workflows/integration_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656

5757
- name: Build the layer
5858
# This version number is arbitrary and won't be used by AWS
59-
run: VERSION=123 ./scripts/build_binary_and_layer_dockerized.sh
59+
run: ARCHITECTURE=amd64 VERSION=123 ./scripts/build_binary_and_layer_dockerized.sh
6060

6161
- name: Run tests
6262
env:

integration_tests/run.sh

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
LOGS_WAIT_SECONDS=45
1010

11+
DEFAULT_NODE_LAYER_VERSION=64
12+
DEFAULT_PYTHON_LAYER_VERSION=49
13+
1114
set -e
1215

1316
script_utc_start_time=$(date -u +"%Y%m%dT%H%M%S")
@@ -18,10 +21,13 @@ if [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
1821
exit 1
1922
fi
2023

21-
if [ -n "$BUILD_EXTENSION" ]; then
24+
if [ "$BUILD_EXTENSION" == "true" ]; then
2225
echo "Building extension that will be deployed with our test functions"
26+
2327
# This version number is arbitrary and won't be used by AWS
24-
VERSION=123 ./scripts/build_binary_and_layer_dockerized.sh
28+
PLACEHOLDER_EXTENSION_VERSION=123
29+
30+
ARCHITECTURE=amd64 VERSION=$PLACEHOLDER_EXTENSION_VERSION ./scripts/build_binary_and_layer_dockerized.sh
2531
else
2632
echo "Not building extension, ensure it has already been built or re-run with 'BUILD_EXTENSION=true'"
2733
fi
@@ -39,48 +45,36 @@ cd src
3945
env GOOS=linux go build -ldflags="-s -w" -o ../bootstrap traceGo.go
4046
cd ..
4147

42-
function getLatestLayerVersion() {
43-
layerName=$1
44-
lastVersion=$(aws lambda list-layer-versions --layer-name $layerName --region sa-east-1 | jq -r ".LayerVersions | .[0] | .Version")
45-
if [ lastVersion == "null" ]; then
46-
exit 1
47-
else
48-
echo $lastVersion
49-
fi
50-
}
51-
5248
if [ -z "$NODE_LAYER_VERSION" ]; then
53-
echo "NODE_LAYER_VERSION not found, getting the latest one"
54-
export NODE_LAYER_VERSION=$(getLatestLayerVersion "Datadog-Node14-x")
55-
echo "NODE_LAYER_VERSION set to: $NODE_LAYER_VERSION"
49+
echo "NODE_LAYER_VERSION not found, using the default"
50+
export NODE_LAYER_VERSION=$DEFAULT_NODE_LAYER_VERSION
5651
fi
5752

5853
if [ -z "$PYTHON_LAYER_VERSION" ]; then
59-
echo "PYTHON_LAYER_VERSION not found, getting the latest one"
60-
export PYTHON_LAYER_VERSION=$(getLatestLayerVersion "Datadog-Python38")
61-
echo "PYTHON_LAYER_VERSION set to: $PYTHON_LAYER_VERSION"
54+
echo "PYTHON_LAYER_VERSION not found, using the default"
55+
export PYTHON_LAYER_VERSION=$DEFAULT_PYTHON_LAYER_VERSION
6256
fi
6357

58+
echo "NODE_LAYER_VERSION set to: $NODE_LAYER_VERSION"
59+
echo "PYTHON_LAYER_VERSION set to: $PYTHON_LAYER_VERSION"
60+
6461
# random 8-character ID to avoid collisions with other runs
6562
stage=$(xxd -l 4 -c 4 -p < /dev/random)
6663

67-
# always remove the stacks before exiting, no matter what
6864
function remove_stack() {
6965
echo "Removing stack for stage : ${stage}"
70-
NODE_LAYER_VERSION=${NODE_LAYER_VERSION} \
71-
PYTHON_LAYER_VERSION=${PYTHON_LAYER_VERSION} \
7266
serverless remove --stage ${stage}
7367
}
7468

75-
# making sure the remove_stack function will be called no matter what
69+
# always remove the stacks before exiting, no matter what
7670
trap remove_stack EXIT
7771

78-
# deploying the stack
72+
# deploy the stack
7973
NODE_LAYER_VERSION=${NODE_LAYER_VERSION} \
8074
PYTHON_LAYER_VERSION=${PYTHON_LAYER_VERSION} \
8175
serverless deploy --stage ${stage}
8276

83-
# invoking functions
77+
# invoke functions
8478
metric_function_names=("enhanced-metric-node" "enhanced-metric-python" "no-enhanced-metric-node" "no-enhanced-metric-python" "timeout-node" "timeout-python")
8579
log_function_names=("log-node" "log-python")
8680
trace_function_names=("simple-trace-node" "simple-trace-python" "simple-trace-go")
@@ -90,10 +84,8 @@ all_functions=("${metric_function_names[@]}" "${log_function_names[@]}" "${trace
9084
set +e # Don't exit this script if an invocation fails or there's a diff
9185

9286
for function_name in "${all_functions[@]}"; do
93-
NODE_LAYER_VERSION=${NODE_LAYER_VERSION} \
94-
PYTHON_LAYER_VERSION=${PYTHON_LAYER_VERSION} \
9587
serverless invoke --stage ${stage} -f ${function_name}
96-
# two invocations are needed since enhanced metrics are computed with the REPORT log line (which is trigered at the end of the first invocation)
88+
# two invocations are needed since enhanced metrics are computed with the REPORT log line (which is created at the end of the first invocation)
9789
return_value=$(serverless invoke --stage ${stage} -f ${function_name})
9890

9991
# Compare new return value to snapshot
@@ -181,7 +173,7 @@ for function_name in "${all_functions[@]}"; do
181173
# If no snapshot file exists yet, we create one
182174
echo "Writing logs to $function_snapshot_path because no snapshot exists yet"
183175
echo "$logs" >$function_snapshot_path
184-
elif [ -n "$UPDATE_SNAPSHOTS" ]; then
176+
elif [ "$UPDATE_SNAPSHOTS" == "true" ]; then
185177
# If $UPDATE_SNAPSHOTS is set to true write the new logs over the current snapshot
186178
echo "Overwriting log snapshot for $function_snapshot_path"
187179
echo "$logs" >$function_snapshot_path

integration_tests/serverless.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ functions:
4646
runtime: nodejs14.x
4747
handler: src/metric.enhancedMetricTest
4848
layers:
49-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
49+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
5050
- { Ref: RecorderExtensionLambdaLayer }
5151
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
5252
environment:
@@ -57,7 +57,7 @@ functions:
5757
runtime: python3.8
5858
handler: datadog_lambda.handler.handler
5959
layers:
60-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
60+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
6161
- { Ref: RecorderExtensionLambdaLayer }
6262
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
6363
environment:
@@ -69,7 +69,7 @@ functions:
6969
runtime: nodejs14.x
7070
handler: src/metric.noEnhancedMetricTest
7171
layers:
72-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
72+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
7373
- { Ref: RecorderExtensionLambdaLayer }
7474
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
7575
environment:
@@ -79,7 +79,7 @@ functions:
7979
runtime: python3.8
8080
handler: datadog_lambda.handler.handler
8181
layers:
82-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
82+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
8383
- { Ref: RecorderExtensionLambdaLayer }
8484
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
8585
environment:
@@ -90,7 +90,7 @@ functions:
9090
runtime: nodejs14.x
9191
handler: src/metric.timeoutMetricTest
9292
layers:
93-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
93+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
9494
- { Ref: RecorderExtensionLambdaLayer }
9595
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
9696
environment:
@@ -100,7 +100,7 @@ functions:
100100
runtime: python3.8
101101
handler: datadog_lambda.handler.handler
102102
layers:
103-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
103+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
104104
- { Ref: RecorderExtensionLambdaLayer }
105105
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
106106
environment:
@@ -111,7 +111,7 @@ functions:
111111
runtime: nodejs14.x
112112
handler: src/log.logTest
113113
layers:
114-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
114+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
115115
- { Ref: RecorderExtensionLambdaLayer }
116116
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
117117
environment:
@@ -127,7 +127,7 @@ functions:
127127
runtime: python3.8
128128
handler: datadog_lambda.handler.handler
129129
layers:
130-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
130+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
131131
- { Ref: RecorderExtensionLambdaLayer }
132132
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
133133
environment:
@@ -144,7 +144,7 @@ functions:
144144
runtime: nodejs14.x
145145
handler: /opt/nodejs/node_modules/datadog-lambda-js/handler.handler
146146
layers:
147-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
147+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Node14-x:${env:NODE_LAYER_VERSION}
148148
- { Ref: RecorderExtensionLambdaLayer }
149149
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
150150
environment:
@@ -160,7 +160,7 @@ functions:
160160
runtime: python3.8
161161
handler: datadog_lambda.handler.handler
162162
layers:
163-
- arn:aws:lambda:${self:provider.region}:601427279990:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
163+
- arn:aws:lambda:${self:provider.region}:464622532012:layer:Datadog-Python38:${env:PYTHON_LAYER_VERSION}
164164
- { Ref: RecorderExtensionLambdaLayer }
165165
- { Ref: DatadogExtensionIntegrationTestLambdaLayer }
166166
environment:

0 commit comments

Comments
 (0)