@kronos-integration/interceptor 12.1.2 → 12.1.4
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/interceptor",
|
|
3
|
-
"version": "12.1.
|
|
3
|
+
"version": "12.1.4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib es2024 -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"pacc": "^4.
|
|
42
|
+
"pacc": "^4.5.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@kronos-integration/test-interceptor": "^7.0.31",
|
|
@@ -13,14 +13,14 @@ export class LoggingInterceptor extends Interceptor {
|
|
|
13
13
|
|
|
14
14
|
async receive(endpoint, next, ...args) {
|
|
15
15
|
const logger = endpoint.owner;
|
|
16
|
-
logger.info(`${endpoint.identifier}:
|
|
16
|
+
logger.info(`${endpoint.identifier}: > ${JSON.stringify([...args])}`);
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
19
|
const result = await next(...args);
|
|
20
|
-
logger.info(`${endpoint.identifier}:
|
|
20
|
+
logger.info(`${endpoint.identifier}: < ${result}`);
|
|
21
21
|
return result;
|
|
22
22
|
} catch (e) {
|
|
23
|
-
logger.error(`${endpoint.identifier}:
|
|
23
|
+
logger.error(`${endpoint.identifier}: ${e}`);
|
|
24
24
|
throw e;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -12,45 +12,19 @@ export class StatsCollectorInterceptor extends Interceptor {
|
|
|
12
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
26
|
async receive(endpoint,...args) {
|
|
53
|
-
this
|
|
27
|
+
this.numberOfRequests += 1;
|
|
54
28
|
|
|
55
29
|
const start = Date.now();
|
|
56
30
|
|
|
@@ -58,20 +32,20 @@ export class StatsCollectorInterceptor extends Interceptor {
|
|
|
58
32
|
const response = await this.connected.receive(...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(
|
|
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
14
|
receive(endpoint: any, ...args: any[]): Promise<any>;
|
|
15
|
-
#private;
|
|
16
15
|
}
|
|
17
16
|
import { Interceptor } from './interceptor.mjs';
|