@axinom/mosaic-service-common 0.46.0-rc.9 → 0.46.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitoring-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/monitoring-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EACL,WAAW,EACX,kBAAkB,EAElB,MAAM,EACP,MAAM,WAAW,CAAC;AAInB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,WAClB,WAAW,GAAG,kBAAkB,sBACrB,kBAAkB,WAC5B,MAAM,KACd,
|
|
1
|
+
{"version":3,"file":"monitoring-middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/monitoring-middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,MAAM,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EACL,WAAW,EACX,kBAAkB,EAElB,MAAM,EACP,MAAM,WAAW,CAAC;AAInB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,QAAQ,CAAC;IAC1B;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;CAC5B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,WAClB,WAAW,GAAG,kBAAkB,sBACrB,kBAAkB,WAC5B,MAAM,KACd,QA+FF,CAAC"}
|
|
@@ -24,7 +24,46 @@ const setupMonitoring = (config, monitoringOptions = {}, logger) => {
|
|
|
24
24
|
environment: config.environment,
|
|
25
25
|
});
|
|
26
26
|
for (const metric of options.metrics) {
|
|
27
|
-
|
|
27
|
+
/**
|
|
28
|
+
* We wrap the collection of each metric in a try-catch block to ensure that any errors caused
|
|
29
|
+
* during the collection will not make the entire metrics endpoint unusable.
|
|
30
|
+
*
|
|
31
|
+
* Also now each metric's errors will be granularly logged instead of stoping the evaluation of
|
|
32
|
+
* other metrics when one metric collection fails.
|
|
33
|
+
*/
|
|
34
|
+
const safeMetric = new Proxy(metric, {
|
|
35
|
+
get(target, prop, receiver) {
|
|
36
|
+
if (prop === 'get') {
|
|
37
|
+
return async () => {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
const typelessTarget = target;
|
|
41
|
+
try {
|
|
42
|
+
return await typelessTarget[prop]();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const originalMetricData = {
|
|
46
|
+
name: (_a = typelessTarget === null || typelessTarget === void 0 ? void 0 : typelessTarget.name) !== null && _a !== void 0 ? _a : 'unknown_metric_name',
|
|
47
|
+
help: (_b = typelessTarget === null || typelessTarget === void 0 ? void 0 : typelessTarget.help) !== null && _b !== void 0 ? _b : 'unknown_metric_help',
|
|
48
|
+
};
|
|
49
|
+
localLogger.error(error, {
|
|
50
|
+
message: `METRIC_COLLECTION_ERROR`,
|
|
51
|
+
details: Object.assign({}, originalMetricData),
|
|
52
|
+
});
|
|
53
|
+
/**
|
|
54
|
+
* We return only the mandatory values (name, help) of any metric as we cannot
|
|
55
|
+
* assume a reasonable value for various metric types for erroneous situations.
|
|
56
|
+
*/
|
|
57
|
+
return originalMetricData;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return Reflect.get(target, prop, receiver);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
options.metricRegistry.registerMetric(safeMetric);
|
|
28
67
|
}
|
|
29
68
|
if (options.collectDefaultMetrics) {
|
|
30
69
|
(0, prom_client_1.collectDefaultMetrics)({ register: options.metricRegistry });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monitoring-middleware.js","sourceRoot":"","sources":["../../src/middleware/monitoring-middleware.ts"],"names":[],"mappings":";;;AACA,6CAAsE;AACtE,sCAKmB;AACnB,qDAAiD;AACjD,mCAAoC;AAwBpC;;;;;;;;;GASG;AACI,MAAM,eAAe,GAAG,CAC7B,MAAwC,EACxC,oBAAwC,EAAE,EAC1C,MAAe,EACL,EAAE;IACZ,MAAM,WAAW,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,IAAI,eAAM,CAAC,EAAE,OAAO,EAAE,uBAAe,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5E,MAAM,OAAO,mBACX,WAAW,EAAE,UAAU,EACvB,cAAc,EAAE,IAAI,sBAAQ,EAAE,EAC9B,qBAAqB,EAAE,IAAI,EAC3B,OAAO,EAAE,EAAE,IACR,iBAAiB,CACrB,CAAC;IAEF,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,8BAAa,CAAC,CAAC;IAEzC,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC;QACtC,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,WAAW,EAAE,MAAM,CAAC,WAAW;KAChC,CAAC,CAAC;IAEH,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE;QACpC,OAAO,CAAC,cAAc,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"monitoring-middleware.js","sourceRoot":"","sources":["../../src/middleware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c,CAAC,OAAO,EAAE,CAAC,CAAC;SAClD;QAAC,OAAO,CAAC,EAAE;YACV,GAAG,CAAC,IAAI,CACN,0EAA0E,MAAM,CAAC,SAAS,qBAAqB,CAChH,CAAC;YACF,MAAM,KAAK,GAAG,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC;YAC7B,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;SAC1B;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC,cAAc,CAAC;AAChC,CAAC,CAAC;AAnGW,QAAA,eAAe,mBAmG1B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axinom/mosaic-service-common",
|
|
3
|
-
"version": "0.46.0
|
|
3
|
+
"version": "0.46.0",
|
|
4
4
|
"description": "Common helpers and PostgreSQL-related functionality",
|
|
5
5
|
"author": "Axinom",
|
|
6
6
|
"license": "PROPRIETARY",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"jest": "^29",
|
|
44
44
|
"jest-expect-message": "^1.1.3",
|
|
45
45
|
"moment": "^2.29.1",
|
|
46
|
-
"prom-client": "^
|
|
46
|
+
"prom-client": "^15.1.0",
|
|
47
47
|
"serialize-error": "^7.0.1",
|
|
48
48
|
"serve-favicon": "^2.5.0",
|
|
49
49
|
"short-hash": "^1.0.0",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"publishConfig": {
|
|
69
69
|
"access": "public"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "1101ccda9a7b9d8c5710187459eddfc50099ae11"
|
|
72
72
|
}
|
|
@@ -63,7 +63,49 @@ export const setupMonitoring = (
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
for (const metric of options.metrics) {
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* We wrap the collection of each metric in a try-catch block to ensure that any errors caused
|
|
68
|
+
* during the collection will not make the entire metrics endpoint unusable.
|
|
69
|
+
*
|
|
70
|
+
* Also now each metric's errors will be granularly logged instead of stoping the evaluation of
|
|
71
|
+
* other metrics when one metric collection fails.
|
|
72
|
+
*/
|
|
73
|
+
const safeMetric: Metric<string> = new Proxy<Metric<string>>(metric, {
|
|
74
|
+
get(target, prop, receiver) {
|
|
75
|
+
if (prop === 'get') {
|
|
76
|
+
return async () => {
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
78
|
+
const typelessTarget = target as any;
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
return await typelessTarget[prop]();
|
|
82
|
+
} catch (error) {
|
|
83
|
+
const originalMetricData = {
|
|
84
|
+
name: typelessTarget?.name ?? 'unknown_metric_name',
|
|
85
|
+
help: typelessTarget?.help ?? 'unknown_metric_help',
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
localLogger.error(<Error>error, {
|
|
89
|
+
message: `METRIC_COLLECTION_ERROR`,
|
|
90
|
+
details: {
|
|
91
|
+
...originalMetricData,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* We return only the mandatory values (name, help) of any metric as we cannot
|
|
97
|
+
* assume a reasonable value for various metric types for erroneous situations.
|
|
98
|
+
*/
|
|
99
|
+
return originalMetricData;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
} else {
|
|
103
|
+
return Reflect.get(target, prop, receiver);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
options.metricRegistry.registerMetric(safeMetric);
|
|
67
109
|
}
|
|
68
110
|
|
|
69
111
|
if (options.collectDefaultMetrics) {
|