@kronos-integration/interceptor 12.1.3 → 12.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Interceptor } from
|
|
1
|
+
import { Interceptor } from "./interceptor.mjs";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Interceptor to collect processing time, number of
|
|
@@ -9,69 +9,43 @@ export class StatsCollectorInterceptor extends Interceptor {
|
|
|
9
9
|
* @return {string} 'collect-request-stats'
|
|
10
10
|
*/
|
|
11
11
|
static get name() {
|
|
12
|
-
return
|
|
12
|
+
return "collect-request-stats";
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
#numberOfRequests;
|
|
16
|
-
#numberOfFailedRequests;;
|
|
17
|
-
#minRequestProcessingTime;;
|
|
18
|
-
#maxRequestProcessingTime;
|
|
19
|
-
#totalRequestProcessingTime;
|
|
20
|
-
|
|
21
15
|
reset() {
|
|
22
|
-
this
|
|
23
|
-
this
|
|
24
|
-
this
|
|
25
|
-
this
|
|
26
|
-
this
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get numberOfRequests() {
|
|
30
|
-
return this.#numberOfRequests;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get numberOfFailedRequests() {
|
|
34
|
-
return this.#numberOfFailedRequests;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get maxRequestProcessingTime() {
|
|
38
|
-
return this.#maxRequestProcessingTime;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get minRequestProcessingTime() {
|
|
42
|
-
return this.#minRequestProcessingTime;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get totalRequestProcessingTime() {
|
|
46
|
-
return this.#totalRequestProcessingTime;
|
|
16
|
+
this.numberOfRequests = 0;
|
|
17
|
+
this.numberOfFailedRequests = 0;
|
|
18
|
+
this.minRequestProcessingTime = Number.MAX_VALUE;
|
|
19
|
+
this.maxRequestProcessingTime = 0;
|
|
20
|
+
this.totalRequestProcessingTime = 0;
|
|
47
21
|
}
|
|
48
22
|
|
|
49
23
|
/**
|
|
50
24
|
* Logs the time the requests takes
|
|
51
25
|
*/
|
|
52
|
-
async receive(endpoint
|
|
53
|
-
this
|
|
26
|
+
async receive(endpoint, next, ...args) {
|
|
27
|
+
this.numberOfRequests += 1;
|
|
54
28
|
|
|
55
29
|
const start = Date.now();
|
|
56
30
|
|
|
57
31
|
try {
|
|
58
|
-
const response = await
|
|
32
|
+
const response = await next(...args);
|
|
59
33
|
const now = Date.now();
|
|
60
34
|
const pt = now - start;
|
|
61
|
-
this
|
|
35
|
+
this.totalRequestProcessingTime += pt;
|
|
62
36
|
|
|
63
|
-
if (pt > this
|
|
64
|
-
this
|
|
37
|
+
if (pt > this.maxRequestProcessingTime) {
|
|
38
|
+
this.maxRequestProcessingTime = pt;
|
|
65
39
|
}
|
|
66
40
|
|
|
67
|
-
if (pt < this
|
|
68
|
-
this
|
|
41
|
+
if (pt < this.minRequestProcessingTime) {
|
|
42
|
+
this.minRequestProcessingTime = pt;
|
|
69
43
|
}
|
|
70
44
|
|
|
71
|
-
endpoint.logger.debug(level
|
|
45
|
+
endpoint.logger.debug(level => `took ${pt} ms for ${[...args]}`);
|
|
72
46
|
return response;
|
|
73
47
|
} catch (err) {
|
|
74
|
-
this
|
|
48
|
+
this.numberOfFailedRequests += 1;
|
|
75
49
|
throw err;
|
|
76
50
|
}
|
|
77
51
|
}
|
|
@@ -3,15 +3,14 @@
|
|
|
3
3
|
* processed and failed requests.
|
|
4
4
|
*/
|
|
5
5
|
export class StatsCollectorInterceptor extends Interceptor {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
numberOfRequests: number;
|
|
7
|
+
numberOfFailedRequests: number;
|
|
8
|
+
minRequestProcessingTime: number;
|
|
9
|
+
maxRequestProcessingTime: number;
|
|
10
|
+
totalRequestProcessingTime: number;
|
|
11
11
|
/**
|
|
12
12
|
* Logs the time the requests takes
|
|
13
13
|
*/
|
|
14
|
-
receive(endpoint: any, ...args: any[]): Promise<any>;
|
|
15
|
-
#private;
|
|
14
|
+
receive(endpoint: any, next: any, ...args: any[]): Promise<any>;
|
|
16
15
|
}
|
|
17
|
-
import { Interceptor } from
|
|
16
|
+
import { Interceptor } from "./interceptor.mjs";
|