@emartech/aggregate-metric-logger 4.0.0 → 5.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emartech/aggregate-metric-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "aggregate metrics in memory for logging",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -30,20 +30,20 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@emartech/json-logger": "^8.0.2",
|
|
33
|
-
"@google-cloud/monitoring": "^
|
|
34
|
-
"date-fns": "
|
|
33
|
+
"@google-cloud/monitoring": "^4.0.0",
|
|
34
|
+
"date-fns": "2.30.0",
|
|
35
35
|
"json-stable-stringify": "^1.0.1",
|
|
36
36
|
"lodash": "^4.17.15",
|
|
37
37
|
"ms": "^2.1.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@sinonjs/fake-timers": "
|
|
41
|
-
"@types/jest": "
|
|
40
|
+
"@sinonjs/fake-timers": "11.1.0",
|
|
41
|
+
"@types/jest": "29.5.5",
|
|
42
42
|
"dotenv-haphap": "^3.1.2",
|
|
43
|
-
"eslint": "
|
|
43
|
+
"eslint": "8.50.0",
|
|
44
44
|
"eslint-config-emarsys": "^5.1.0",
|
|
45
|
-
"eslint-plugin-jest": "
|
|
46
|
-
"jest": "
|
|
45
|
+
"eslint-plugin-jest": "27.4.2",
|
|
46
|
+
"jest": "29.7.0",
|
|
47
47
|
"semantic-release": "^19.0.2"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -5,13 +5,23 @@ const { publishTimeSeries } = require('../gcp-time-series-publisher/gcp-time-ser
|
|
|
5
5
|
const { buildTimeSeries } = require('../gcp-time-series-builder/gcp-time-series-builder');
|
|
6
6
|
const { createCounter } = require('../metric-types/counter/counter');
|
|
7
7
|
const { createDistribution } = require('../metric-types/distribution/distribution');
|
|
8
|
+
const { isNumber, isPlainObject } = require('lodash');
|
|
8
9
|
|
|
9
10
|
let metrics = {};
|
|
10
11
|
let initialized = false;
|
|
11
12
|
let timeoutId = null;
|
|
12
13
|
|
|
13
|
-
exports.count = (metricName, labels = {}, value = 1) =>
|
|
14
|
+
exports.count = (metricName, labels = {}, value = 1) => {
|
|
15
|
+
if (!isNumber(value)) {
|
|
16
|
+
throw new Error(`${ value } is not a number`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!isPlainObject(labels)) {
|
|
20
|
+
throw new Error('labels is not a plain object');
|
|
21
|
+
}
|
|
22
|
+
|
|
14
23
|
addToMetric(metricName, labels, 'counter', value);
|
|
24
|
+
};
|
|
15
25
|
|
|
16
26
|
exports.measure = (metricName, labels = {}, value = 1) =>
|
|
17
27
|
addToMetric(metricName, labels, 'distribution', value);
|
|
@@ -98,6 +98,22 @@ describe('gcpMetricCollector', () => {
|
|
|
98
98
|
|
|
99
99
|
expect(getPublishedMetrics()).toEqual([]);
|
|
100
100
|
});
|
|
101
|
+
|
|
102
|
+
it('should validate labels parameter whether it is an object', async () => {
|
|
103
|
+
process.env.METRIC_LOGGER_ENABLED = 'false';
|
|
104
|
+
|
|
105
|
+
expect(() => {
|
|
106
|
+
gcpMetricCollector.count('irrelevant', new Error('not a plain object'), 88);
|
|
107
|
+
}).toThrow(new Error('labels is not a plain object'));
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should validate value parameter whether it is a number', async () => {
|
|
111
|
+
process.env.METRIC_LOGGER_ENABLED = 'false';
|
|
112
|
+
|
|
113
|
+
expect(() => {
|
|
114
|
+
gcpMetricCollector.count('irrelevant', {}, '88');
|
|
115
|
+
}).toThrow(new Error('88 is not a number'));
|
|
116
|
+
});
|
|
101
117
|
});
|
|
102
118
|
|
|
103
119
|
describe('measure', () => {
|