Skip to content

Commit 257f758

Browse files
authored
add report about used middlewares (#221)
* add report about used middlewares fixes idrinth-api-bench/issues#334 * fix middlewares being potentially not defined fixes idrinth-api-bench/issues#334 * fix typos fixes idrinth-api-bench/issues#334 * fix typos fixes idrinth-api-bench/issues#334 * fix broken test fixes idrinth-api-bench/issues#334 * fix broken test fixes idrinth-api-bench/issues#334 * fix broken test fixes idrinth-api-bench/issues#334
1 parent 3be3b53 commit 257f758

17 files changed

+68
-22
lines changed

integration/executor-job.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class FakeResult implements Result, ValidationResult, FinishedSet {
5858

5959
public maxDuration: number;
6060

61+
public middlewares: string[];
62+
6163
public response = {
6264
headers: {},
6365
cookies: {},
@@ -91,6 +93,7 @@ class FakeResult implements Result, ValidationResult, FinishedSet {
9193
this.median80 = duration;
9294
this.stdv100 = 100;
9395
this.stdv80 = 80;
96+
this.middlewares = ['id', 'duration'];
9497
}
9598

9699
public add() {

src/messaging/finished-set.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface FinishedSet {
1313
min80: number;
1414
max80: number;
1515
msgs?: {[msg: string]: number};
16+
middlewares?: string[];
1617
}
1718

1819
export default FinishedSet;

src/messaging/result-set.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,23 @@ export class ResultSet {
1212

1313
public msgs: {[msg: string]: number};
1414

15+
public middlewares: Array<string>;
16+
1517
public constructor(public readonly id: string,) {
1618
this.errors = INITIAL_ZERO;
1719
this.count = INITIAL_ZERO;
1820
this.durations = [];
1921
this.msgs = {};
22+
this.middlewares = [];
2023
}
2124

2225
public add(result: ValidationResult,): void {
2326
if (result.duration !== null) {
2427
this.durations.push(result.duration,);
2528
}
29+
if (this.middlewares.length === 0) {
30+
this.middlewares = result.middlewares ?? [];
31+
}
2632
this.count ++;
2733
if (! result.success) {
2834
this.errors ++;

src/messaging/result.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class Result {
2525
response: NeedleResponse,
2626
public validators: Array<string>,
2727
public maxDuration: number|undefined,
28+
public middlewares: Array<string>,
2829
) {
2930
this.duration = (end.shift() - start.shift()) * ToMicro;
3031
this.duration += end.pop() - start.pop();

src/messaging/validation-result.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface ValidationResult {
33
id: string;
44
success: boolean;
55
msg?: string;
6+
middlewares: Array<string>,
67
}
78

89
export default ValidationResult;

src/reporter/console-reporter.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,8 @@ const cli: Reporter = (
2020
'median 100%',
2121
'min 100%',
2222
'max 100%',
23-
'avg 80%',
24-
'median 80%',
25-
'min 80%',
26-
'max 80%',
27-
'stdv 80%',
2823
'stdv 100%',
24+
'Middlewares'
2925
],
3026
},);
3127
const formatter = new Intl.NumberFormat();
@@ -41,12 +37,8 @@ const cli: Reporter = (
4137
formatter.format(results[id].median100,),
4238
formatter.format(results[id].min100,),
4339
formatter.format(results[id].max100,),
44-
formatter.format(results[id].avg80,),
45-
formatter.format(results[id].median80,),
46-
formatter.format(results[id].min80,),
47-
formatter.format(results[id].max80,),
48-
formatter.format(results[id].stdv80,),
4940
formatter.format(results[id].stdv100,),
41+
results[id]?.middlewares?.join() ?? '',
5042
],);
5143
}
5244
// eslint-disable-next-line no-console

src/reporter/csv-reporter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const csv: Reporter = (
2121
csvStream.write({
2222
...results[id],
2323
msgs: JSON.stringify(results[id].msgs,),
24+
middlewares: results[id]?.middlewares?.join() ?? '',
2425
},);
2526
}
2627
csvStream.end();

src/reporter/html-reporter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const html: Reporter = (
3333
stream.write('<th>Standard Deviation 80%</th>',);
3434
stream.write('<th>Standard Deviation 100%</th>',);
3535
stream.write('<th>Messages</th>',);
36+
stream.write('<th>Middlewares</th>',);
3637
stream.write('</tr>',);
3738
stream.write('</thead>',);
3839
stream.write('<tbody>',);
@@ -52,6 +53,7 @@ const html: Reporter = (
5253
stream.write('<td>' + results[id].stdv80 + '</td>',);
5354
stream.write('<td>' + results[id].stdv100 + '</td>',);
5455
stream.write('<td>' + JSON.stringify(results[id].msgs,) + '</td>',);
56+
stream.write('<td>' + (results[id]?.middlewares?.join() ?? '') + '</td>',);
5557
stream.write('</tr>',);
5658
}
5759
stream.write('</tbody>',);

src/worker/calculator.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default (result: ResultSet,): FinishedSet => {
4141
median80: NaN,
4242
min80: NaN,
4343
max80: NaN,
44+
middlewares: result.middlewares,
4445
};
4546
}
4647
const sorted100 = result.durations.sort((a: number, b: number,) => a-b,);
@@ -71,5 +72,6 @@ export default (result: ResultSet,): FinishedSet => {
7172
median80: calculateAverage(min80, max80,),
7273
min80,
7374
max80,
75+
middlewares: result.middlewares ?? [],
7476
};
7577
};

src/worker/runner.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ export default async(task: Task, callable: Callback,): Promise<void> => {
7979
validators: [],
8080
// eslint-disable-next-line no-undefined
8181
maxDuration: undefined,
82+
middlewares: [
83+
...(task.pre?.map((value,) => `pre:${value}`) ?? []),
84+
...(task.post?.map((value,) => `post:${value}`) ?? [])
85+
],
8286
} as Result, error+'', false,),);
8387
return;
8488
}
@@ -90,6 +94,10 @@ export default async(task: Task, callable: Callback,): Promise<void> => {
9094
result,
9195
task.post || [],
9296
task.main.maxDuration,
97+
[
98+
...(task.pre?.map((value,) => `pre:${value}`) ?? []),
99+
...(task.post?.map((value,) => `post:${value}`) ?? [])
100+
],
93101
);
94102
if (await handlePost(task, httpResult, callable,)) {
95103
callable(buildAnswer(httpResult, '', true,),);

0 commit comments

Comments
 (0)