-
Notifications
You must be signed in to change notification settings - Fork 590
chore: Add docker compose and test services scripts #2886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b99f3d6
8666907
b2cea62
2a41b7f
b75a0c1
38ef4fe
864fe05
42a1123
3815bca
2c24405
7bf72e9
642e9a9
9b6a94d
2ba1b11
f832c97
daee887
d049606
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,8 +176,6 @@ jobs: | |
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ matrix.node }} | ||
- name: Set MySQL variables | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for reviewer: same here |
||
run: mysql --user=root --password=${MYSQL_ROOT_PASSWORD} --host=${MYSQL_HOST} --port=${MYSQL_PORT} -e "SET GLOBAL log_output='TABLE'; SET GLOBAL general_log = 1;" mysql | ||
- name: Install | ||
run: npm ci | ||
- name: Download Build Artifacts | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,6 +135,34 @@ The conventional commit type (in PR title) is very important to automatically bu | |
|
||
There is no need to update the CHANGELOG in a PR because it will be updated as part of the release process (see [RELEASING.md](RELEASING.md) for more details). | ||
|
||
### Testing | ||
|
||
Most unit tests case be run via: | ||
|
||
```sh | ||
npm test | ||
``` | ||
|
||
However, some instrumentations require test-services to be running (e.g. the `instrumentation-mongodb` package requires a MongoDB server). Use the `test-services`-related npm scripts to start all required services in Docker and then run the tests with the appropriate configuration to use those services: | ||
|
||
```sh | ||
npm run test-services:start # starts services in Docker | ||
npm run test:with-services-config # runs 'npm test' with envvars from test/test-services.env | ||
david-luna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
npm run test-services:stop # stops services in Docker | ||
``` | ||
|
||
If you only want to test a single package (e.g. the `instrumentation-mongodb`) you can `cd` into it and run the tests after you started the services. | ||
|
||
```sh | ||
npm run test-services:start # starts services in Docker | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could optionally be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm planning to do a follow up PR to add scripts for each package which will use this feature. I'll remember to update this description. |
||
cd plugins/node/opentelemetry-instrumentation-mongodb # get into the instrumenation folder | ||
RUN_MONGODB_TESTS=1 npm test # run the test with the proper config (check each package) | ||
cd ../../.. # go back to root folder | ||
npm run test-services:stop # stops services in Docker | ||
``` | ||
|
||
NOTE: scripts for each package will be added to avoid extra consumption of resources and improve the development experience. | ||
|
||
### Benchmarks | ||
|
||
When two or more approaches must be compared, please write a benchmark in the benchmark/index.js module so that we can keep track of the most efficient algorithm. | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,28 +64,38 @@ interface Result extends RowDataPacket { | |
solution: number; | ||
} | ||
|
||
describe('mysql2', () => { | ||
const testMysql = process.env.RUN_MYSQL_TESTS; // For CI: assumes local mysql db is already available | ||
const testMysqlLocally = process.env.RUN_MYSQL_TESTS_LOCAL; // For local: spins up local mysql db via docker | ||
const shouldTest = testMysql || testMysqlLocally; // Skips these tests if false (default) | ||
|
||
before(function (done) { | ||
if (testMysqlLocally) { | ||
testUtils.startDocker('mysql'); | ||
// wait 15 seconds for docker container to start | ||
this.timeout(20000); | ||
setTimeout(done, 15000); | ||
} else { | ||
done(); | ||
} | ||
// Helper function to setup the database | ||
const execPromise = (conn: Connection, command: string) => { | ||
return new Promise<void>((res, rej) => { | ||
conn.execute(command, err => { | ||
if (err) rej(err); | ||
else res(); | ||
}); | ||
}); | ||
}; | ||
|
||
after(function (done) { | ||
if (testMysqlLocally) { | ||
this.timeout(5000); | ||
testUtils.cleanUpDocker('mysql'); | ||
describe('mysql2', () => { | ||
// assumes local mysql db is already available in CI or | ||
// using `npm run test-services:start` script at the root folder | ||
const shouldTest = process.env.RUN_MYSQL_TESTS; | ||
|
||
before(async function () { | ||
const connection = createConnection({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for reviewer: enabling here the |
||
port, | ||
user: 'root', | ||
host, | ||
password: rootPassword, | ||
database, | ||
}); | ||
try { | ||
await execPromise(connection, "SET GLOBAL log_output='TABLE'"); | ||
await execPromise(connection, 'SET GLOBAL general_log = 1'); | ||
} catch (execErr) { | ||
console.error('MySQL seup error: ', execErr); | ||
this.skip(); | ||
} finally { | ||
connection.end(); | ||
} | ||
done(); | ||
}); | ||
|
||
describe('callback API', () => { | ||
|
@@ -358,7 +368,7 @@ describe('mysql2', () => { | |
it('should not add comment by default', done => { | ||
const span = provider.getTracer('default').startSpan('test span'); | ||
context.with(trace.setSpan(context.active(), span), () => { | ||
connection.query('SELECT 1+1 as solution', () => { | ||
connection.query('SELECT 1+1 as solution', (e, r) => { | ||
const spans = memoryExporter.getFinishedSpans(); | ||
assert.strictEqual(spans.length, 1); | ||
getLastQueries(1).then(([query]) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,7 +64,7 @@ const memoryExporter = new InMemorySpanExporter(); | |
const CONFIG = { | ||
user: process.env.POSTGRES_USER || 'postgres', | ||
password: process.env.POSTGRES_PASSWORD || 'postgres', | ||
database: process.env.POSTGRES_DB || 'postgres', | ||
database: process.env.POSTGRES_DB || 'otel_pg_database', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for reviewer: align the value with the one in workflow services |
||
host: process.env.POSTGRES_HOST || 'localhost', | ||
port: process.env.POSTGRES_PORT | ||
? parseInt(process.env.POSTGRES_PORT, 10) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# A `docker compose` config file to run tests services for testing | ||
# `@opentelemetry/instrumentation-*` locally. | ||
# | ||
# Note: This isn't used in CI. CI uses GitHub Actions' `services: ...` for | ||
# defining test services. | ||
# | ||
# Usage: | ||
# npm run test-services:start [services...] | ||
# npm run test-services:stop [services...] | ||
|
||
name: opentelemetry-js-contrib-test-services | ||
|
||
services: | ||
cassandra: | ||
image: cassandra:3 | ||
environment: | ||
MAX_HEAP_SIZE: "1G" | ||
HEAP_NEWSIZE: 400m | ||
ports: | ||
- "9042:9042" | ||
healthcheck: | ||
test: ["CMD-SHELL", "[ $$(nodetool statusgossip) = running ]"] | ||
interval: 1s | ||
timeout: 10s | ||
retries: 30 | ||
|
||
memcached: | ||
image: memcached:1.6.37-alpine | ||
ports: | ||
- 11211:11211 | ||
|
||
mongodb: | ||
david-luna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
image: mongo:7 | ||
ports: | ||
- "27017:27017" | ||
healthcheck: | ||
test: ["CMD", "mongosh", "--eval", "db.runCommand('ping').ok", "--quiet"] | ||
interval: 1s | ||
timeout: 10s | ||
retries: 30 | ||
|
||
mssql: | ||
# Tags listed at https://hub.docker.com/r/microsoft/mssql-server | ||
# Docs: https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker | ||
image: mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04 | ||
platform: linux/amd64 | ||
environment: | ||
- ACCEPT_EULA=Y | ||
- MSSQL_SA_PASSWORD=mssql_passw0rd | ||
ports: | ||
- "1433:1433" | ||
healthcheck: | ||
test: ["CMD", "/opt/mssql-tools18/bin/sqlcmd", "-C", "-S", "mssql", "-U", "sa", "-P", "mssql_passw0rd", "-Q", "select 1"] | ||
interval: 1s | ||
timeout: 10s | ||
retries: 30 | ||
|
||
mysql: | ||
image: mysql:5.7 | ||
# No ARM64 image layer. See https://stackoverflow.com/a/65592942 | ||
platform: linux/x86_64 | ||
environment: | ||
MYSQL_USER: "otel" | ||
MYSQL_PASSWORD: "secret" | ||
MYSQL_DATABASE: "otel_mysql_database" | ||
MYSQL_ROOT_PASSWORD: "rootpw" | ||
ports: | ||
- "33306:3306" | ||
healthcheck: | ||
test: ["CMD", "mysqladmin" ,"ping"] | ||
interval: 1s | ||
timeout: 10s | ||
retries: 30 | ||
|
||
oracledb: | ||
image: gvenzl/oracle-free:slim | ||
environment: | ||
APP_USER: "otel" | ||
APP_USER_PASSWORD: "secret" | ||
ORACLE_PASSWORD: "oracle" | ||
ports: | ||
- 1521:1521 | ||
healthcheck: | ||
test: ["CMD", "sqlplus" ,"system/oracle@//localhost/FREEPDB1"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 30 | ||
|
||
postgres: | ||
david-luna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# https://github.com/docker-library/docs/blob/master/postgres/README.md#how-to-extend-this-image | ||
image: postgres:16-alpine | ||
ports: | ||
- "54320:5432" | ||
environment: | ||
POSTGRES_HOST_AUTH_METHOD: "trust" | ||
POSTGRES_USER: "postgres" | ||
POSTGRES_DB: "otel_pg_database" | ||
POSTGRES_PASSWORD: "postgres" | ||
healthcheck: | ||
test: ["CMD", "pg_isready"] | ||
interval: 1s | ||
timeout: 10s | ||
retries: 30 | ||
|
||
rabbitmq: | ||
image: rabbitmq:3 | ||
environment: | ||
RABBITMQ_DEFAULT_USER: "username" | ||
RABBITMQ_DEFAULT_PASS: "password" | ||
ports: | ||
- "22221:5672" | ||
|
||
redis: | ||
image: redis:7 | ||
ports: | ||
- "6379:6379" | ||
healthcheck: | ||
test: ["CMD", "redis-cli", "ping"] | ||
interval: 1s | ||
timeout: 10s | ||
retries: 30 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for reviewer: this is required only for testing
@opentelemetry/instrumentation-mysql
and can be executed as a query using the client. Hence is removed from there and added inplugins/node/opentelemetry-instrumentation-mysql/test/mysql.test.ts