@kronos-integration/interceptor 13.3.7 → 13.4.0
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/README.md +13 -3
- package/package.json +3 -3
- package/src/index.mjs +1 -0
- package/src/monitoring-interceptor.mjs +79 -0
package/README.md
CHANGED
|
@@ -50,15 +50,17 @@ const response = interceptor.receive(endpoint, arg1, arg2);
|
|
|
50
50
|
* [name](#name-1)
|
|
51
51
|
* [LoggingInterceptor](#logginginterceptor)
|
|
52
52
|
* [name](#name-2)
|
|
53
|
+
* [MonitoringInterceptor](#monitoringinterceptor)
|
|
54
|
+
* [name](#name-3)
|
|
53
55
|
* [StatsCollectorInterceptor](#statscollectorinterceptor)
|
|
54
56
|
* [receive](#receive-1)
|
|
55
57
|
* [Parameters](#parameters-5)
|
|
56
|
-
* [name](#name-3)
|
|
57
|
-
* [TemplateInterceptor](#templateinterceptor)
|
|
58
58
|
* [name](#name-4)
|
|
59
|
+
* [TemplateInterceptor](#templateinterceptor)
|
|
60
|
+
* [name](#name-5)
|
|
59
61
|
* [TimeoutInterceptor](#timeoutinterceptor)
|
|
60
62
|
* [Properties](#properties-1)
|
|
61
|
-
* [name](#name-
|
|
63
|
+
* [name](#name-6)
|
|
62
64
|
* [rejectUnlessResolvedWithin](#rejectunlessresolvedwithin)
|
|
63
65
|
* [Parameters](#parameters-6)
|
|
64
66
|
|
|
@@ -184,6 +186,14 @@ logs args and result
|
|
|
184
186
|
|
|
185
187
|
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'logging'
|
|
186
188
|
|
|
189
|
+
## MonitoringInterceptor
|
|
190
|
+
|
|
191
|
+
**Extends Interceptor**
|
|
192
|
+
|
|
193
|
+
### name
|
|
194
|
+
|
|
195
|
+
Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** 'monitor'
|
|
196
|
+
|
|
187
197
|
## StatsCollectorInterceptor
|
|
188
198
|
|
|
189
199
|
**Extends Interceptor**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kronos-integration/interceptor",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.4.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"lint:docs": "documentation lint ./src**/*.mjs"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"pacc": "^11.
|
|
38
|
+
"pacc": "^11.2.3"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@kronos-integration/test-interceptor": "^7.
|
|
41
|
+
"@kronos-integration/test-interceptor": "^7.2.2",
|
|
42
42
|
"ava": "^8.0.1",
|
|
43
43
|
"c8": "^12.0.0",
|
|
44
44
|
"documentation": "^14.0.3",
|
package/src/index.mjs
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { prepareAttributesDefinitions, duration_ms_attribute, default_attribute } from "pacc";
|
|
2
|
+
import { Interceptor } from "@kronos-integration/interceptor";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
*/
|
|
7
|
+
export class MonitoringInterceptor extends Interceptor {
|
|
8
|
+
static attributes = prepareAttributesDefinitions(
|
|
9
|
+
{
|
|
10
|
+
gracePeriod: {
|
|
11
|
+
...duration_ms_attribute,
|
|
12
|
+
name: "gracePeriod",
|
|
13
|
+
default: "120s"
|
|
14
|
+
},
|
|
15
|
+
settingPeriod: {
|
|
16
|
+
...duration_ms_attribute,
|
|
17
|
+
name: "settingPeriod",
|
|
18
|
+
default: "300s"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
Interceptor.attributes
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @return {string} 'monitor'
|
|
26
|
+
*/
|
|
27
|
+
static get name() {
|
|
28
|
+
return "monitor";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
reset() {
|
|
32
|
+
this.endpointStates = new Map();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/*
|
|
36
|
+
gracePeriod = 2 * 60 * 1000;
|
|
37
|
+
settingPeriod = 5 * 60 * 1000;
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
async receive(endpoint, next, ...args) {
|
|
41
|
+
const state = this.endpointStates.get(endpoint);
|
|
42
|
+
|
|
43
|
+
if (this.check(endpoint, ...args)) {
|
|
44
|
+
if (state) {
|
|
45
|
+
endpoint.warn(`${endpoint.name}: back ok`);
|
|
46
|
+
this.endpointStates.delete(endpoint);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
|
|
51
|
+
if (state === undefined) {
|
|
52
|
+
this.endpointStates.set(endpoint, { time: now, state: 0 });
|
|
53
|
+
endpoint.info(`${endpoint.name}: entering monitoring period`);
|
|
54
|
+
} else {
|
|
55
|
+
switch (state.state) {
|
|
56
|
+
case 0:
|
|
57
|
+
if (now - state.time > this.gracePeriod) {
|
|
58
|
+
state.time = now;
|
|
59
|
+
state.state += 1;
|
|
60
|
+
endpoint.warn(
|
|
61
|
+
`${endpoint.name}: execute monitoring resolveAction`
|
|
62
|
+
);
|
|
63
|
+
await this.resolveAction(endpoint);
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
|
|
67
|
+
case 1:
|
|
68
|
+
if (now - state.time > this.settingPeriod) {
|
|
69
|
+
endpoint.info(`${endpoint.name}: clear monitoring action`);
|
|
70
|
+
this.endpointStates.delete(endpoint);
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return super.receive(endpoint, next, ...args);
|
|
78
|
+
}
|
|
79
|
+
}
|