-
Notifications
You must be signed in to change notification settings - Fork 584
chore: add test-services scripts per package #2932
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
9f52a4e
b71a1af
240359f
dafcf86
6b88fdb
9a8d2ac
9785201
2eef913
536dab5
813a7c7
7d7d919
188d6a1
a2e0266
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 |
---|---|---|
|
@@ -117,7 +117,7 @@ The required steps to start development on a pacakge are: | |
|
||
- `npm ci` from root folder to install dependencies ([see npm-ci docs](https://docs.npmjs.com/cli/v10/commands/npm-ci)) | ||
- `cd` into the pacakge you want to apply changes. | ||
- `npm run setup:dev` compiles the TypeScript files for this package and its dependencies within the repository. | ||
- `npm run compile:with-dependencies` compiles the TypeScript files for this package and its dependencies within the repository. | ||
|
||
Then you can proceed to do apply the changes and use the scripts below for development workflow | ||
|
||
|
@@ -146,23 +146,21 @@ 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 | ||
npm run test-services:stop # stops services in Docker | ||
npm run test-services:start # starts services in Docker | ||
npm run test:with-services-env # runs 'npm test' with envvars from test/test-services.env | ||
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 to reviewer: this was a typo from #2886 |
||
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. | ||
If you only want to test a single package that dfepends on a service (e.g. the `instrumentation-mongodb`) you can `cd` into it and | ||
use the same scripts for testing. In this case the script will only start the services needed to test the package. | ||
|
||
```sh | ||
npm run test-services:start # starts services in Docker | ||
cd packages/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 | ||
cd packages/instrumentation-mongodb # get into the instrumenation folder | ||
npm run test-services:start # start the MongoDB service in Docker | ||
npm run test:with-services-env # runs 'npm test' with envvars from test/test-services.env | ||
npm run test-services:stop # stop MongoDB service 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 |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
import * as childProcess from 'child_process'; | ||
import { | ||
HrTime, | ||
Span, | ||
|
@@ -33,62 +32,6 @@ import * as path from 'path'; | |
import * as fs from 'fs'; | ||
import { InstrumentationBase } from '@opentelemetry/instrumentation'; | ||
|
||
const dockerRunCmds = { | ||
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: not needed anymore |
||
cassandra: | ||
'docker run --rm -d --name otel-cassandra -p 9042:9042 bitnami/cassandra:3', | ||
memcached: | ||
'docker run --rm -d --name otel-memcached -p 11211:11211 memcached:1.6.9-alpine', | ||
mssql: | ||
'docker run --rm -d --name otel-mssql -p 1433:1433 -e MSSQL_SA_PASSWORD=mssql_passw0rd -e ACCEPT_EULA=Y mcr.microsoft.com/mssql/server:2022-latest', | ||
mysql: | ||
'docker run --rm -d --name otel-mysql -p 33306:3306 -e MYSQL_ROOT_PASSWORD=rootpw -e MYSQL_DATABASE=test_db -e MYSQL_USER=otel -e MYSQL_PASSWORD=secret mysql:5.7 --log_output=TABLE --general_log=ON', | ||
oracledb: | ||
'docker run --rm -d --name otel-oracledb -p 1521:1521 -e ORACLE_PASSWORD=oracle -e APP_USER=otel -e APP_USER_PASSWORD=secret gvenzl/oracle-free:slim', | ||
postgres: | ||
'docker run --rm -d --name otel-postgres -p 54320:5432 -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=otel_pg_database postgres:16-alpine', | ||
redis: 'docker run --rm -d --name otel-redis -p 63790:6379 redis:alpine', | ||
}; | ||
|
||
export function startDocker(db: keyof typeof dockerRunCmds) { | ||
const tasks = [run(dockerRunCmds[db])]; | ||
|
||
for (let i = 0; i < tasks.length; i++) { | ||
const task = tasks[i]; | ||
if (task && task.code !== 0) { | ||
console.error('Failed to start container!'); | ||
console.error(task.output); | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
export function cleanUpDocker(db: keyof typeof dockerRunCmds) { | ||
run(`docker stop otel-${db}`); | ||
} | ||
|
||
function run(cmd: string) { | ||
try { | ||
const proc = childProcess.spawnSync(cmd, { | ||
shell: true, | ||
}); | ||
const output = Buffer.concat( | ||
proc.output.filter(c => c) as Buffer[] | ||
).toString('utf8'); | ||
if (proc.status !== 0) { | ||
console.error('Failed run command:', cmd); | ||
console.error(output); | ||
} | ||
return { | ||
code: proc.status, | ||
output, | ||
}; | ||
} catch (e) { | ||
console.log(e); | ||
return; | ||
} | ||
} | ||
|
||
export const assertSpan = ( | ||
span: ReadableSpan, | ||
kind: SpanKind, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,18 +31,21 @@ | |
}, | ||
"scripts": { | ||
"clean": "rimraf build/*", | ||
"setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-amqplib", | ||
"compile": "tsc -p .", | ||
"compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-amqplib", | ||
"lint": "eslint . --ext .ts", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"lint:readme": "node ../../scripts/lint-readme.js", | ||
"prepublishOnly": "npm run compile", | ||
"tdd": "npm run test -- --watch-extensions ts --watch", | ||
"test": "nyc mocha --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'", | ||
"test:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm test", | ||
"test-all-versions": "tav", | ||
"test-all-versions:with-services-env": "cross-env NODE_OPTIONS='-r dotenv/config' DOTENV_CONFIG_PATH=../../test/test-services.env npm run test-all-versions", | ||
"test-services:start": "cd ../.. && npm run test-services:start rabbitmq", | ||
"test-services:stop": "cd ../.. && npm run test-services:stop rabbitmq", | ||
"version:update": "node ../../scripts/version-update.js", | ||
"watch": "tsc -w", | ||
"test:docker:run": "docker run -d --hostname demo-amqplib-rabbit --name amqplib-unittests -p 22221:5672 --env RABBITMQ_DEFAULT_USER=username --env RABBITMQ_DEFAULT_PASS=password rabbitmq:3" | ||
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: scripts with docker commands have been deleted because now the service is controlled via |
||
"watch": "tsc -w" | ||
}, | ||
"peerDependencies": { | ||
"@opentelemetry/api": "^1.3.0" | ||
|
@@ -61,6 +64,7 @@ | |
"@types/node": "18.18.14", | ||
"@types/sinon": "17.0.4", | ||
"amqplib": "0.8.0", | ||
"cross-env": "7.0.3", | ||
"expect": "29.2.0", | ||
"lodash": "4.17.21", | ||
"nyc": "17.1.0", | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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: script name has changed to be more explicit about what it does. you will see this change on each
package.json
that has it