Skip to content

Commit d3b5825

Browse files
authored
Add contract test (aws-observability#85)
1 parent cec7306 commit d3b5825

Some content is hidden

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

45 files changed

+3664
-1
lines changed

contract-tests/README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## Introduction
2+
3+
This directory contain contract tests that exist to prevent regressions. They cover:
4+
5+
* [OpenTelemetry semantic conventions](https://github.com/open-telemetry/semantic-conventions/).
6+
* Application Signals-specific attributes.
7+
8+
## How it works?
9+
10+
The tests present here rely on the auto-instrumentation of a sample application which will send telemetry signals to a mock collector. The tests will use the data collected by the mock collector to perform assertions and validate that the contracts are being respected.
11+
12+
## Types of tested frameworks
13+
14+
The frameworks and libraries that are tested in the contract tests should fall in the following categories (more can be added on demand):
15+
16+
* http-servers - applications meant to test http servers (e.g. http module in node.js).
17+
* aws-sdk - Applications meant to test the AWS SDK (e.g. AWS SDK for JavaScript v3).
18+
* database-clients - Applications meant to test database clients (e.g. mysql2, Mongoose, Mongodb).
19+
20+
When testing a framework, we will create a sample application. The sample applications are stored following this convention: `contract-tests/images/applications/<framework-name>`.
21+
22+
## Adding tests for a new library or framework
23+
24+
The steps to add a new test for a library or framework are:
25+
26+
* Create a sample application.
27+
* The sample application should be created in `contract-tests/images/applications/<framework-name>`.
28+
* Implement a node.js application and create a `Dockerfile` to containerize the application
29+
* Add a test class for the sample application.
30+
* The test class should be created in `contract-tests/tests/amazon/<framework-name>`.
31+
* The test class should extend `contract_test_base.py`
32+
33+
## How to run the tests locally?
34+
35+
Pre-requirements:
36+
37+
* Have `docker` installed and running - verify by running the `docker` command.
38+
39+
Steps:
40+
41+
* From `aws-otel-js-instrumentation` dir, execute:
42+
43+
```sh
44+
# create a virtual environment in python for the tests
45+
python3 -m venv venv
46+
source venv/bin/activate
47+
# build the instrumentation SDK
48+
./scripts/build_and_install_distro.sh
49+
# build the relevant images for sample app and build the contract tests
50+
./scripts/set-up-contract-tests.sh
51+
# run all the tests
52+
pytest contract-tests/tests
53+
# exit the virtual python environment
54+
deactivate
55+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Use an official Node.js runtime as the base image
2+
FROM node:20-alpine
3+
#FROM node:20
4+
5+
# Set the working directory inside the container
6+
WORKDIR /aws-sdk
7+
8+
# Copy the relevant files
9+
COPY ./dist/$DISTRO /aws-sdk
10+
COPY ./contract-tests/images/applications/aws-sdk /aws-sdk
11+
12+
13+
ARG DISTRO
14+
# Install dependencies
15+
RUN npm install
16+
RUN npm install ./${DISTRO}
17+
18+
# Expose the port the app runs on
19+
EXPOSE 8080
20+
21+
# Run the app with nodejs auto instrumentation
22+
CMD ["node", "--require", "@aws/aws-distro-opentelemetry-node-autoinstrumentation/register", "server.js"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "aws-sdk-forwarder",
3+
"version": "1.0.0",
4+
"main": "server.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1",
7+
"start": "node server.js"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"description": "",
12+
"dependencies": {
13+
"@aws-sdk/client-dynamodb": "^3.658.1",
14+
"@aws-sdk/client-kinesis": "^3.658.1",
15+
"@aws-sdk/client-s3": "^3.658.1",
16+
"@aws-sdk/client-sqs": "^3.658.1",
17+
"@smithy/node-http-handler": "^3.2.3",
18+
"node-fetch": "^2.7.0"
19+
}
20+
}

0 commit comments

Comments
 (0)