Skip to content

Commit

Permalink
fix: k6 with ts, add description in readme, removed unnecessary scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Amuhar committed Sep 12, 2023
1 parent 6f2d99c commit f4baaf5
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 105 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,34 @@ Pay attention that API by default running job for fetching and updating Validato

## Benchmarks

To see record output in file and send metrics to prometheus run command
`K6_PROMETHEUS_RW_SERVER_URL=http://localhost:9090/api/v1/write k6 run --out json=benchmarks/output.json -o experimental-prometheus-rw --tag testid=<SET-HERE-A-UNIQUE-ID> benchmarks/200.script.js`
This part of document outlines running benchmarks and collecting Prometheus metrics using K6.

At first install [k6](https://k6.io/docs/get-started/installation/).

Run `yarn build`.
Run KAPI `yarn start:dev`.

Running Benchmarks: Execute this command to run benchmarks and save results in benchmarks/output.json:

```bash
k6 run -e PORT=<KAPI-PORT> --out json=benchmarks/output.json --tag testid=<UNIQUE-ID> dist/benchmarks/<TEST-NAME>.script.js
```

Replace <UNIQUE-ID> with your unique test identifier.

Collecting Prometheus Metrics: For collecting benchmarks' Prometheus metrics, set the Prometheus server URL:

```bash
export K6_PROMETHEUS_RW_SERVER_URL=http://<PROMETHEUS-SERVER-URL>/api/v1/write
```

Replace <PROMETHEUS-SERVER-URL> with your Prometheus server's address. Then, execute benchmarks and collect Prometheus metrics:

```bash
k6 run -e PORT=<KAPI-PORT> --out json=benchmarks/output.json -o experimental-prometheus-rw --tag testid=<UNIQUE-ID> dist/benchmarks/<TEST-NAME>.script.js
```

Once again, use <UNIQUE-ID> to differentiate your test run in the results.

## Release flow

Expand Down
25 changes: 0 additions & 25 deletions benchmarks/1-vu.script.js

This file was deleted.

19 changes: 19 additions & 0 deletions benchmarks/1-vu.script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { get } from 'k6/http';
import { check } from 'k6';

// Test configuration
export const options = {
thresholds: {
http_req_duration: ['p(10) > 30000'],
},
// better to make it longer to cross with validators update
duration: '80s',
vus: 1,
};

// Simulated user behavior
export default function test() {
const res = get(`http://localhost:${__ENV.PORT}/v1/keys`);
// Validate response status
check(res, { 'Should return response with status 200': (r) => r.status == 200 });
}
29 changes: 0 additions & 29 deletions benchmarks/415.script.js

This file was deleted.

23 changes: 23 additions & 0 deletions benchmarks/415.script.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { post, file } from 'k6/http';
import { check } from 'k6';

// Test configuration
export const options = {
duration: '60s',
vus: 1,
};

export default function test() {
const data = {
field: 'this is a standard form field',
file: file('some data', 'test.bin'),
};

console.log('Test unsupported content/type');

const res = post(`http://localhost:${__ENV.PORT}/v1/keys`, data);

check(res, {
'Should return response with status 415': (r) => r.status === 415,
});
}
25 changes: 0 additions & 25 deletions benchmarks/batch.script.js

This file was deleted.

22 changes: 0 additions & 22 deletions benchmarks/multiple-vu.script.js

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.2",
"typechain": "^7.0.0"
"typechain": "^7.0.0",
"@types/k6": "~0.44.2"
},
"devDependencies": {
"@nestjs/cli": "^8.2.5",
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"forceConsistentCasingInFileNames": false,
"noFallthroughCasesInSwitch": false,
},
"include": ["src/**/*", "test/**/*"],
"include": ["src/**/*", "test/**/*", "benchmarks/*"],
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1582,6 +1582,11 @@
resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee"
integrity sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==

"@types/k6@~0.44.2":
version "0.44.3"
resolved "https://registry.yarnpkg.com/@types/k6/-/k6-0.44.3.tgz#bbd6c7ebed1970f537fce8d46af41d3d19631ac2"
integrity sha512-Ulu+xGZZQhZfk3hpLRo7oj69oSMBUfK7+FYdUtD3Dsj+nPyWQAH6j/GX5rLuHJ4SWZkdyEZ7Xmam7tBM8G2Srw==

"@types/node-fetch@^2.5.12":
version "2.6.2"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.6.2.tgz#d1a9c5fd049d9415dce61571557104dec3ec81da"
Expand Down

0 comments on commit f4baaf5

Please sign in to comment.