Skip to content

Commit da6f79e

Browse files
authored
[SVLS-5988] add integration tests for snapstart (#971)
https://datadoghq.atlassian.net/browse/SVLS-5988 https://datadoghq.atlassian.net/browse/SVLS-7836 ## Overview Adding integration tests for SnapStart, no functional changes to extension code. 1.) Testing that restore spans are created, and we don't use cold_start spans. This is a follow up to SVLS-7836. 2.) Testing that trace ids are correctly generated for SVLS-5988. If multiple lambdas are triggered, they should have unique trace ids. This is a potential issue for SnapStart because `init` is ran before taking the snapshot. This doesn't currently work for Python runtime so the test is commented out. Will follow up with APM Serverless team on correcting this. ## Testing * Newly added integration tests pass.
1 parent d6988dd commit da6f79e

16 files changed

Lines changed: 464 additions & 21 deletions

File tree

.gitlab/config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ outputFiles:
99
datasources:
1010
flavors:
1111
url: .gitlab/datasources/flavors.yaml
12-
12+
1313
environments:
1414
url: .gitlab/datasources/environments.yaml
1515

1616
regions:
1717
url: .gitlab/datasources/regions.yaml
18+
19+
test_suites:
20+
url: .gitlab/datasources/test-suites.yaml
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test_suites:
2+
- name: base
3+
- name: otlp
4+
- name: snapstart

.gitlab/templates/pipeline.yaml.tpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,9 @@ integration-suite:
466466
image: ${CI_DOCKER_TARGET_IMAGE}:${CI_DOCKER_TARGET_VERSION}
467467
parallel:
468468
matrix:
469-
- TEST_SUITE: [base, otlp]
469+
- TEST_SUITE: {{ range (ds "test_suites").test_suites }}
470+
- {{ .name }}
471+
{{- end}}
470472
rules:
471473
- when: on_success
472474
needs:

integration-tests/bin/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'source-map-support/register';
33
import * as cdk from 'aws-cdk-lib';
44
import {Base} from '../lib/stacks/base';
55
import {Otlp} from '../lib/stacks/otlp';
6+
import {Snapstart} from '../lib/stacks/snapstart';
67
import {getIdentifier} from '../tests/utils/config';
78

89
const app = new cdk.App();
@@ -21,6 +22,9 @@ const stacks = [
2122
new Otlp(app, `integ-${identifier}-otlp`, {
2223
env,
2324
}),
25+
new Snapstart(app, `integ-${identifier}-snapstart`, {
26+
env,
27+
}),
2428
]
2529

2630
// Tag all stacks so we can easily clean them up
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
obj/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Amazon.Lambda.Core;
2+
using System.Collections.Generic;
3+
using System.Threading.Tasks;
4+
5+
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
6+
7+
namespace Function
8+
{
9+
public class SnapstartHandler
10+
{
11+
public async Task<Dictionary<string, object>> FunctionHandler(Dictionary<string, object> input, ILambdaContext context)
12+
{
13+
// Wait 10 seconds to guarantee concurrent execution overlap
14+
await Task.Delay(10000);
15+
16+
return new Dictionary<string, object>
17+
{
18+
{ "statusCode", 200 },
19+
{ "body", "Snapstart .NET function executed" }
20+
};
21+
}
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>net8.0</TargetFramework>
4+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
5+
<AWSProjectType>Lambda</AWSProjectType>
6+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
7+
<PublishReadyToRun>true</PublishReadyToRun>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Amazon.Lambda.Core" Version="2.2.0" />
12+
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.0" />
13+
</ItemGroup>
14+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>example</groupId>
8+
<artifactId>snapstart-java-lambda</artifactId>
9+
<version>1.0.0</version>
10+
<packaging>jar</packaging>
11+
12+
<name>Snapstart Java Lambda</name>
13+
<description>Snapstart Java Lambda function for Datadog Extension integration testing</description>
14+
15+
<properties>
16+
<maven.compiler.source>21</maven.compiler.source>
17+
<maven.compiler.target>21</maven.compiler.target>
18+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.amazonaws</groupId>
24+
<artifactId>aws-lambda-java-core</artifactId>
25+
<version>1.2.3</version>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>3.5.0</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<finalName>function</finalName>
43+
<createDependencyReducedPom>false</createDependencyReducedPom>
44+
</configuration>
45+
</execution>
46+
</executions>
47+
</plugin>
48+
</plugins>
49+
</build>
50+
</project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package example;
2+
3+
import com.amazonaws.services.lambda.runtime.Context;
4+
import com.amazonaws.services.lambda.runtime.RequestHandler;
5+
import java.util.Map;
6+
import java.util.HashMap;
7+
8+
public class SnapstartHandler implements RequestHandler<Map<String, Object>, Map<String, Object>> {
9+
@Override
10+
public Map<String, Object> handleRequest(Map<String, Object> event, Context context) {
11+
12+
// Wait 10 seconds to guarantee concurrent execution overlap
13+
try {
14+
Thread.sleep(10000);
15+
} catch (InterruptedException e) {
16+
Thread.currentThread().interrupt();
17+
}
18+
19+
Map<String, Object> response = new HashMap<>();
20+
response.put("statusCode", 200);
21+
response.put("body", "Snapstart Java function executed");
22+
return response;
23+
}
24+
}

0 commit comments

Comments
 (0)