@oino-ts/common 0.21.1 → 1.0.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 +183 -0
- package/dist/cjs/OINOApi.js +322 -0
- package/dist/cjs/OINOBenchmark.js +3 -4
- package/dist/cjs/OINOConfig.js +104 -0
- package/dist/cjs/OINOConstants.js +42 -0
- package/dist/cjs/OINODataField.js +346 -0
- package/dist/cjs/OINODataModel.js +182 -0
- package/dist/cjs/OINODataSource.js +165 -0
- package/dist/cjs/OINOFormatter.js +6 -5
- package/dist/cjs/OINOHtmlTemplate.js +21 -18
- package/dist/cjs/OINOModelSet.js +333 -0
- package/dist/cjs/OINOParser.js +448 -0
- package/dist/cjs/OINOQueryParams.js +434 -0
- package/dist/cjs/OINORequest.js +21 -13
- package/dist/cjs/OINOResult.js +13 -12
- package/dist/cjs/OINOStr.js +11 -11
- package/dist/cjs/OINOSwagger.js +205 -0
- package/dist/cjs/index.js +57 -39
- package/dist/esm/OINOApi.js +315 -0
- package/dist/esm/OINOBenchmark.js +3 -4
- package/dist/esm/OINOConfig.js +100 -0
- package/dist/esm/OINOConstants.js +39 -0
- package/dist/esm/OINODataField.js +337 -0
- package/dist/esm/OINODataModel.js +178 -0
- package/dist/esm/OINODataSource.js +159 -0
- package/dist/esm/OINOFormatter.js +2 -1
- package/dist/esm/OINOHtmlTemplate.js +4 -1
- package/dist/esm/OINOModelSet.js +329 -0
- package/dist/esm/OINOParser.js +444 -0
- package/dist/esm/OINOQueryParams.js +426 -0
- package/dist/esm/OINORequest.js +9 -1
- package/dist/esm/OINOResult.js +2 -1
- package/dist/esm/OINOStr.js +1 -1
- package/dist/esm/OINOSwagger.js +201 -0
- package/dist/esm/index.js +14 -32
- package/dist/types/OINOApi.d.ts +191 -0
- package/dist/types/OINOBenchmark.d.ts +1 -1
- package/dist/types/OINOConfig.d.ts +63 -0
- package/dist/types/OINOConstants.d.ts +51 -0
- package/dist/types/OINODataField.d.ts +209 -0
- package/dist/types/OINODataModel.d.ts +78 -0
- package/dist/types/OINODataSource.d.ts +184 -0
- package/dist/types/OINOHtmlTemplate.d.ts +1 -1
- package/dist/types/OINOModelSet.d.ts +64 -0
- package/dist/types/OINOParser.d.ts +42 -0
- package/dist/types/OINOQueryParams.d.ts +270 -0
- package/dist/types/OINORequest.d.ts +4 -1
- package/dist/types/OINOResult.d.ts +1 -1
- package/dist/types/OINOStr.d.ts +1 -1
- package/dist/types/OINOSwagger.d.ts +25 -0
- package/dist/types/index.d.ts +14 -31
- package/package.json +32 -32
- package/src/OINOApi.ts +429 -0
- package/src/OINOBenchmark.ts +323 -324
- package/src/OINOConfig.ts +113 -0
- package/src/OINOConstants.ts +59 -0
- package/src/OINODataField.ts +371 -0
- package/src/OINODataModel.ts +187 -0
- package/src/OINODataSource.ts +280 -0
- package/src/OINOFormatter.ts +166 -165
- package/src/OINOHeaders.ts +51 -51
- package/src/OINOHtmlTemplate.test.ts +114 -114
- package/src/OINOHtmlTemplate.ts +225 -222
- package/src/OINOLog.ts +292 -292
- package/src/OINOModelSet.ts +359 -0
- package/src/OINOParser.ts +441 -0
- package/src/OINOQueryParams.ts +449 -0
- package/src/OINORequest.ts +204 -196
- package/src/OINOResult.ts +331 -330
- package/src/OINOStr.ts +254 -254
- package/src/OINOSwagger.ts +213 -0
- package/src/index.ts +18 -38
package/src/OINOBenchmark.ts
CHANGED
|
@@ -1,324 +1,323 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
-
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
-
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Static class for benchmarking functions.
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
export abstract class OINOBenchmark {
|
|
12
|
-
|
|
13
|
-
protected static _instance:OINOBenchmark
|
|
14
|
-
protected static _enabled:Record<string, boolean> = {}
|
|
15
|
-
protected static _healthBenchmarks: string[] = []
|
|
16
|
-
protected static _healthLateRatio: number = 0
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a new OINOBenchmark instance.
|
|
20
|
-
*
|
|
21
|
-
* @param enabledModules array of those benchmarks that are enabled
|
|
22
|
-
*/
|
|
23
|
-
constructor(enabledModules:string[] = []) {
|
|
24
|
-
OINOBenchmark.setEnabled(enabledModules)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Set active benchmarking instance.
|
|
29
|
-
*
|
|
30
|
-
* @param instance OINOBenchmark instance
|
|
31
|
-
*
|
|
32
|
-
*/
|
|
33
|
-
static setInstance(instance: OINOBenchmark) {
|
|
34
|
-
if (instance) {
|
|
35
|
-
OINOBenchmark._instance = instance
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get active benchmarking instance.
|
|
41
|
-
*
|
|
42
|
-
*/
|
|
43
|
-
static getInstance(): OINOBenchmark {
|
|
44
|
-
return OINOBenchmark._instance
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Add benchmark to be used for service health monitoring.
|
|
49
|
-
* @param module of the benchmark
|
|
50
|
-
* @param method of the benchmark
|
|
51
|
-
*/
|
|
52
|
-
static addHealthBenchmark(module: string, method: string): void {
|
|
53
|
-
const name = module + "." + method
|
|
54
|
-
if (!OINOBenchmark._healthBenchmarks.includes(name)) {
|
|
55
|
-
OINOBenchmark._healthBenchmarks.push(name)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Remove benchmark from being used for service health monitoring.
|
|
61
|
-
* @param module of the benchmark
|
|
62
|
-
* @param method of the benchmark
|
|
63
|
-
*/
|
|
64
|
-
static removeHealthBenchmark(module: string, method: string): void {
|
|
65
|
-
const name = module + "." + method
|
|
66
|
-
const index = OINOBenchmark._healthBenchmarks.indexOf(name)
|
|
67
|
-
if (index !== -1) {
|
|
68
|
-
OINOBenchmark._healthBenchmarks.splice(index, 1)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Set late ratio threshold for health monitoring. If a request takes this many times longer than the average duration, it is considered late and a health failure.
|
|
74
|
-
* @param lateRatio of health benchmarks, e.g. 2.0 means requests that take 2 times longer than the average
|
|
75
|
-
*/
|
|
76
|
-
static setHealthLateRatio(lateRatio: number): void {
|
|
77
|
-
OINOBenchmark._healthLateRatio = lateRatio
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Get service health based on the configured health benchmark.
|
|
82
|
-
*
|
|
83
|
-
* @returns service health as 0-1
|
|
84
|
-
*/
|
|
85
|
-
static getHealth(): number {
|
|
86
|
-
return OINOBenchmark._instance? OINOBenchmark._instance._getHealth() : 1
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
protected abstract _getHealth(): number
|
|
90
|
-
|
|
91
|
-
protected abstract _reset():void
|
|
92
|
-
/**
|
|
93
|
-
* Reset benchmark data (but not what is enabled).
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
static reset():void {
|
|
97
|
-
OINOBenchmark._instance?._reset()
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Set benchmark names that are enabled.
|
|
102
|
-
*
|
|
103
|
-
* @param modules array of those benchmarks that are enabled
|
|
104
|
-
*/
|
|
105
|
-
static setEnabled(modules:string[]):void {
|
|
106
|
-
OINOBenchmark._enabled = {}
|
|
107
|
-
modules.forEach(module_name => {
|
|
108
|
-
this._enabled[module_name] = true
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
protected abstract _startMetric(module:string, method:string):void
|
|
113
|
-
/**
|
|
114
|
-
* Start benchmark timing.
|
|
115
|
-
*
|
|
116
|
-
* @param module of the benchmark
|
|
117
|
-
* @param method of the benchmark
|
|
118
|
-
*/
|
|
119
|
-
static startMetric(module:string, method:string):void {
|
|
120
|
-
OINOBenchmark._instance?._startMetric(module, method)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
protected abstract _endMetric(module:string, method:string, success:boolean):void
|
|
124
|
-
/**
|
|
125
|
-
* Complete benchmark timing
|
|
126
|
-
*
|
|
127
|
-
* @param module of the benchmark
|
|
128
|
-
* @param method of the benchmark
|
|
129
|
-
* @param success indicates if the benchmark was successful
|
|
130
|
-
*/
|
|
131
|
-
static endMetric(module:string, method:string, success:boolean = true):void {
|
|
132
|
-
OINOBenchmark._instance?._endMetric(module, method, success)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
protected abstract _getMetric(module:string, method:string):number
|
|
136
|
-
/**
|
|
137
|
-
* Get given benchmark data.
|
|
138
|
-
*
|
|
139
|
-
* @param module of the benchmark
|
|
140
|
-
* @param method of the benchmark
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
static getMetric(module:string, method:string):number {
|
|
144
|
-
return OINOBenchmark._instance?._getMetric(module, method)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
protected abstract _getMetrics():Record<string, number>
|
|
148
|
-
/**
|
|
149
|
-
* Get all benchmark data.
|
|
150
|
-
*
|
|
151
|
-
*/
|
|
152
|
-
static getMetrics():Record<string, number> {
|
|
153
|
-
return OINOBenchmark._instance?._getMetrics()
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
protected abstract _trackMetric(module:string, method:string, value:number, success:boolean):void
|
|
157
|
-
/**
|
|
158
|
-
* Track a metric value
|
|
159
|
-
*
|
|
160
|
-
* @param module of the metric
|
|
161
|
-
* @param method of the metric
|
|
162
|
-
* @param value of the metric
|
|
163
|
-
* @param success indicates if the metric was successful
|
|
164
|
-
*/
|
|
165
|
-
static trackMetric(module:string, method:string, value:number, success:boolean = true):void {
|
|
166
|
-
if (OINOBenchmark._enabled[module]) {
|
|
167
|
-
OINOBenchmark._instance?._trackMetric(module, method, value, success)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
protected abstract _trackException(module:string, method:string, name:string, message:string, stack: string):void
|
|
172
|
-
/**
|
|
173
|
-
* Track an exception
|
|
174
|
-
*
|
|
175
|
-
* @param module of the benchmark
|
|
176
|
-
* @param method of the benchmark
|
|
177
|
-
* @param name of the exception
|
|
178
|
-
* @param message of the exception
|
|
179
|
-
* @param stack trace of the exception
|
|
180
|
-
*/
|
|
181
|
-
static trackException(module:string, method:string, name:string, message:string, stack:string):void {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
*
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
protected
|
|
205
|
-
protected
|
|
206
|
-
protected
|
|
207
|
-
|
|
208
|
-
protected
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.
|
|
218
|
-
this.
|
|
219
|
-
this.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* @param
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* @param
|
|
240
|
-
* @param
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
this.
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
* @param
|
|
258
|
-
*
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
*
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
this.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
this.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
3
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Static class for benchmarking functions.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export abstract class OINOBenchmark {
|
|
12
|
+
|
|
13
|
+
protected static _instance:OINOBenchmark
|
|
14
|
+
protected static _enabled:Record<string, boolean> = {}
|
|
15
|
+
protected static _healthBenchmarks: string[] = []
|
|
16
|
+
protected static _healthLateRatio: number = 0
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new OINOBenchmark instance.
|
|
20
|
+
*
|
|
21
|
+
* @param enabledModules array of those benchmarks that are enabled
|
|
22
|
+
*/
|
|
23
|
+
constructor(enabledModules:string[] = []) {
|
|
24
|
+
OINOBenchmark.setEnabled(enabledModules)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Set active benchmarking instance.
|
|
29
|
+
*
|
|
30
|
+
* @param instance OINOBenchmark instance
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
static setInstance(instance: OINOBenchmark) {
|
|
34
|
+
if (instance) {
|
|
35
|
+
OINOBenchmark._instance = instance
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get active benchmarking instance.
|
|
41
|
+
*
|
|
42
|
+
*/
|
|
43
|
+
static getInstance(): OINOBenchmark {
|
|
44
|
+
return OINOBenchmark._instance
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Add benchmark to be used for service health monitoring.
|
|
49
|
+
* @param module of the benchmark
|
|
50
|
+
* @param method of the benchmark
|
|
51
|
+
*/
|
|
52
|
+
static addHealthBenchmark(module: string, method: string): void {
|
|
53
|
+
const name = module + "." + method
|
|
54
|
+
if (!OINOBenchmark._healthBenchmarks.includes(name)) {
|
|
55
|
+
OINOBenchmark._healthBenchmarks.push(name)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Remove benchmark from being used for service health monitoring.
|
|
61
|
+
* @param module of the benchmark
|
|
62
|
+
* @param method of the benchmark
|
|
63
|
+
*/
|
|
64
|
+
static removeHealthBenchmark(module: string, method: string): void {
|
|
65
|
+
const name = module + "." + method
|
|
66
|
+
const index = OINOBenchmark._healthBenchmarks.indexOf(name)
|
|
67
|
+
if (index !== -1) {
|
|
68
|
+
OINOBenchmark._healthBenchmarks.splice(index, 1)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Set late ratio threshold for health monitoring. If a request takes this many times longer than the average duration, it is considered late and a health failure.
|
|
74
|
+
* @param lateRatio of health benchmarks, e.g. 2.0 means requests that take 2 times longer than the average
|
|
75
|
+
*/
|
|
76
|
+
static setHealthLateRatio(lateRatio: number): void {
|
|
77
|
+
OINOBenchmark._healthLateRatio = lateRatio
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get service health based on the configured health benchmark.
|
|
82
|
+
*
|
|
83
|
+
* @returns service health as 0-1
|
|
84
|
+
*/
|
|
85
|
+
static getHealth(): number {
|
|
86
|
+
return OINOBenchmark._instance? OINOBenchmark._instance._getHealth() : 1
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
protected abstract _getHealth(): number
|
|
90
|
+
|
|
91
|
+
protected abstract _reset():void
|
|
92
|
+
/**
|
|
93
|
+
* Reset benchmark data (but not what is enabled).
|
|
94
|
+
*
|
|
95
|
+
*/
|
|
96
|
+
static reset():void {
|
|
97
|
+
OINOBenchmark._instance?._reset()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Set benchmark names that are enabled.
|
|
102
|
+
*
|
|
103
|
+
* @param modules array of those benchmarks that are enabled
|
|
104
|
+
*/
|
|
105
|
+
static setEnabled(modules:string[]):void {
|
|
106
|
+
OINOBenchmark._enabled = {}
|
|
107
|
+
modules.forEach(module_name => {
|
|
108
|
+
this._enabled[module_name] = true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
protected abstract _startMetric(module:string, method:string):void
|
|
113
|
+
/**
|
|
114
|
+
* Start benchmark timing.
|
|
115
|
+
*
|
|
116
|
+
* @param module of the benchmark
|
|
117
|
+
* @param method of the benchmark
|
|
118
|
+
*/
|
|
119
|
+
static startMetric(module:string, method:string):void {
|
|
120
|
+
OINOBenchmark._instance?._startMetric(module, method)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
protected abstract _endMetric(module:string, method:string, success:boolean):void
|
|
124
|
+
/**
|
|
125
|
+
* Complete benchmark timing
|
|
126
|
+
*
|
|
127
|
+
* @param module of the benchmark
|
|
128
|
+
* @param method of the benchmark
|
|
129
|
+
* @param success indicates if the benchmark was successful
|
|
130
|
+
*/
|
|
131
|
+
static endMetric(module:string, method:string, success:boolean = true):void {
|
|
132
|
+
OINOBenchmark._instance?._endMetric(module, method, success)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
protected abstract _getMetric(module:string, method:string):number
|
|
136
|
+
/**
|
|
137
|
+
* Get given benchmark data.
|
|
138
|
+
*
|
|
139
|
+
* @param module of the benchmark
|
|
140
|
+
* @param method of the benchmark
|
|
141
|
+
*
|
|
142
|
+
*/
|
|
143
|
+
static getMetric(module:string, method:string):number {
|
|
144
|
+
return OINOBenchmark._instance?._getMetric(module, method)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
protected abstract _getMetrics():Record<string, number>
|
|
148
|
+
/**
|
|
149
|
+
* Get all benchmark data.
|
|
150
|
+
*
|
|
151
|
+
*/
|
|
152
|
+
static getMetrics():Record<string, number> {
|
|
153
|
+
return OINOBenchmark._instance?._getMetrics()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected abstract _trackMetric(module:string, method:string, value:number, success:boolean):void
|
|
157
|
+
/**
|
|
158
|
+
* Track a metric value
|
|
159
|
+
*
|
|
160
|
+
* @param module of the metric
|
|
161
|
+
* @param method of the metric
|
|
162
|
+
* @param value of the metric
|
|
163
|
+
* @param success indicates if the metric was successful
|
|
164
|
+
*/
|
|
165
|
+
static trackMetric(module:string, method:string, value:number, success:boolean = true):void {
|
|
166
|
+
if (OINOBenchmark._enabled[module]) {
|
|
167
|
+
OINOBenchmark._instance?._trackMetric(module, method, value, success)
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
protected abstract _trackException(module:string, method:string, name:string, message:string, stack: string):void
|
|
172
|
+
/**
|
|
173
|
+
* Track an exception. Does not consider enabled modules.
|
|
174
|
+
*
|
|
175
|
+
* @param module of the benchmark
|
|
176
|
+
* @param method of the benchmark
|
|
177
|
+
* @param name of the exception
|
|
178
|
+
* @param message of the exception
|
|
179
|
+
* @param stack trace of the exception
|
|
180
|
+
*/
|
|
181
|
+
static trackException(module:string, method:string, name:string, message:string, stack:string):void {
|
|
182
|
+
OINOBenchmark._instance?._trackException(module, method, name, message, stack)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
protected abstract _getExceptions():any[]
|
|
186
|
+
/**
|
|
187
|
+
* Get all tracked exceptions.
|
|
188
|
+
*
|
|
189
|
+
*/
|
|
190
|
+
static getExceptions():any[] {
|
|
191
|
+
return OINOBenchmark._instance?._getExceptions()
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* OINOMemoryBenchmark is a memory-based benchmark implementation.
|
|
197
|
+
* It stores the benchmark data in memory and allows to reset, start, end and get benchmark data.
|
|
198
|
+
* In case of recursively/iteratively starting a benchmark, it will honor the first start and ignore the rest. *
|
|
199
|
+
*/
|
|
200
|
+
export class OINOMemoryBenchmark extends OINOBenchmark {
|
|
201
|
+
|
|
202
|
+
protected _benchmarkCount:Record<string, number> = {}
|
|
203
|
+
protected _benchmarkData:Record<string, number> = {}
|
|
204
|
+
protected _benchmarkStart:Record<string, number> = {}
|
|
205
|
+
protected _healthRequests: number = 0
|
|
206
|
+
protected _healthFailures: number = 0
|
|
207
|
+
|
|
208
|
+
protected _exceptions:any[] = []
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Reset benchmark data (but not what is enabled).
|
|
212
|
+
*
|
|
213
|
+
*/
|
|
214
|
+
protected _reset():void {
|
|
215
|
+
this._exceptions = []
|
|
216
|
+
this._benchmarkData = {}
|
|
217
|
+
this._benchmarkCount = {}
|
|
218
|
+
this._healthRequests = 0
|
|
219
|
+
this._healthFailures = 0
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Start benchmark timing.
|
|
224
|
+
*
|
|
225
|
+
* @param module of the benchmark
|
|
226
|
+
* @param method of the benchmark
|
|
227
|
+
*/
|
|
228
|
+
protected _startMetric(module:string, method:string):void {
|
|
229
|
+
const name:string = module + "." + method
|
|
230
|
+
if (OINOBenchmark._enabled[module] && ((this._benchmarkStart[name] === undefined) || (this._benchmarkStart[name] === 0))) { // if benchmark is already started (e.g. loop/recursion), do not start it again
|
|
231
|
+
this._benchmarkStart[name] = performance.now()
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Complete benchmark timing
|
|
237
|
+
*
|
|
238
|
+
* @param module of the benchmark
|
|
239
|
+
* @param method of the benchmark
|
|
240
|
+
* @param success indicates if the benchmark was successful
|
|
241
|
+
*/
|
|
242
|
+
protected _endMetric(module:string, method:string, success:boolean = true):void {
|
|
243
|
+
const name:string = module + "." + method
|
|
244
|
+
let result:number = 0
|
|
245
|
+
if (OINOBenchmark._enabled[module] && (this._benchmarkStart[name] > 0)) { // if benchmark is started, end it
|
|
246
|
+
const duration = performance.now() - this._benchmarkStart[name]
|
|
247
|
+
this._benchmarkStart[name] = 0
|
|
248
|
+
this._trackMetric(module, method, duration, success)
|
|
249
|
+
}
|
|
250
|
+
return
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Get given benchmark data.
|
|
255
|
+
*
|
|
256
|
+
* @param module of the benchmark
|
|
257
|
+
* @param method of the benchmark
|
|
258
|
+
*
|
|
259
|
+
*/
|
|
260
|
+
protected _getMetric(module:string, method:string):number {
|
|
261
|
+
const name:string = module + "." + method
|
|
262
|
+
if (OINOBenchmark._enabled[module] && (this._benchmarkCount[name] > 0)) {
|
|
263
|
+
return this._benchmarkData[module] / this._benchmarkCount[module]
|
|
264
|
+
}
|
|
265
|
+
return -1
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Get all benchmark data.
|
|
270
|
+
*
|
|
271
|
+
*/
|
|
272
|
+
protected _getMetrics():Record<string, number> {
|
|
273
|
+
let result:Record<string, number> = {}
|
|
274
|
+
for (const name in this._benchmarkData) {
|
|
275
|
+
if (this._benchmarkCount[name] > 0) {
|
|
276
|
+
result[name] = this._benchmarkData[name] / this._benchmarkCount[name]
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return result
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
protected _trackMetric(module:string, method:string, value:number, success:boolean = true):void {
|
|
283
|
+
const name:string = module + "." + method
|
|
284
|
+
if (this._benchmarkCount[name] == undefined) {
|
|
285
|
+
this._benchmarkCount[name] = 1
|
|
286
|
+
this._benchmarkData[name] = value
|
|
287
|
+
} else {
|
|
288
|
+
this._benchmarkCount[name] += 1
|
|
289
|
+
this._benchmarkData[name] += value
|
|
290
|
+
}
|
|
291
|
+
if (OINOBenchmark._healthBenchmarks.includes(name)) {
|
|
292
|
+
// console.log(`Health benchmark ${name}: value=${value.toFixed(2)}ms, average=${(this._benchmarkData[name] / this._benchmarkCount[name]).toFixed(2)}ms, late=${late_ratio>=OINOBenchmark._healthLateRatio}, success=${success}`)
|
|
293
|
+
this._healthRequests += 1
|
|
294
|
+
if (!success) {
|
|
295
|
+
this._healthFailures += 1
|
|
296
|
+
|
|
297
|
+
} else if (OINOBenchmark._healthLateRatio > 0) {
|
|
298
|
+
const late_ratio = value / (this._benchmarkData[name] / this._benchmarkCount[name])
|
|
299
|
+
if ((late_ratio > OINOBenchmark._healthLateRatio)) {
|
|
300
|
+
this._healthFailures += 1
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
protected _trackException(module:string, method:string, name:string, message:string, stack:string):void {
|
|
307
|
+
const exception = { module, method, name, message, stack, timestamp: Date.now() }
|
|
308
|
+
this._exceptions.push(exception)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
protected _getExceptions():any[] {
|
|
312
|
+
return this._exceptions
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
protected _getHealth(): number {
|
|
316
|
+
if ((OINOBenchmark._healthBenchmarks.length == 0) || (this._healthRequests == 0)) {
|
|
317
|
+
return 1.0
|
|
318
|
+
|
|
319
|
+
} else {
|
|
320
|
+
return (this._healthRequests - this._healthFailures) / this._healthRequests
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|