@emartech/aggregate-metric-logger 4.0.1 → 5.0.1
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/.github/workflows/build.yml +8 -8
- package/.nvmrc +1 -1
- package/eslint.config.js +19 -0
- package/package.json +11 -11
- package/src/gcp-metric-collector/gcp-metric-collector.js +11 -1
- package/src/gcp-metric-collector/gcp-metric-collector.spec.js +16 -0
- package/src/gcp-time-series-publisher/gcp-time-series-publisher.spec.js +0 -1
- package/.eslintrc.js +0 -25
|
@@ -13,14 +13,14 @@ jobs:
|
|
|
13
13
|
runs-on: ubuntu-latest
|
|
14
14
|
steps:
|
|
15
15
|
- name: Check out repository
|
|
16
|
-
uses: actions/checkout@
|
|
16
|
+
uses: actions/checkout@v4
|
|
17
17
|
- name: Use correct Node version
|
|
18
|
-
uses: actions/setup-node@
|
|
18
|
+
uses: actions/setup-node@v4
|
|
19
19
|
with:
|
|
20
20
|
node-version-file: '.nvmrc'
|
|
21
21
|
- name: Cache node_modules
|
|
22
22
|
id: cache_node_modules
|
|
23
|
-
uses: actions/cache@
|
|
23
|
+
uses: actions/cache@v4
|
|
24
24
|
with:
|
|
25
25
|
path: node_modules
|
|
26
26
|
key: node_modules-${{ hashFiles('**/package-lock.json') }}
|
|
@@ -33,7 +33,7 @@ jobs:
|
|
|
33
33
|
- name: Run tests
|
|
34
34
|
run: npm test
|
|
35
35
|
- name: Slack notification
|
|
36
|
-
uses: 8398a7/action-slack@
|
|
36
|
+
uses: 8398a7/action-slack@v3
|
|
37
37
|
if: ${{ failure() }}
|
|
38
38
|
with:
|
|
39
39
|
status: ${{ job.status }}
|
|
@@ -48,14 +48,14 @@ jobs:
|
|
|
48
48
|
runs-on: ubuntu-latest
|
|
49
49
|
steps:
|
|
50
50
|
- name: Check out repository
|
|
51
|
-
uses: actions/checkout@
|
|
51
|
+
uses: actions/checkout@v4
|
|
52
52
|
- name: Use correct Node version
|
|
53
|
-
uses: actions/setup-node@
|
|
53
|
+
uses: actions/setup-node@v4
|
|
54
54
|
with:
|
|
55
55
|
node-version-file: '.nvmrc'
|
|
56
56
|
- name: Cache node_modules
|
|
57
57
|
id: cache_node_modules
|
|
58
|
-
uses: actions/cache@
|
|
58
|
+
uses: actions/cache@v4
|
|
59
59
|
with:
|
|
60
60
|
path: node_modules
|
|
61
61
|
key: node_modules-${{ hashFiles('**/package-lock.json') }}
|
|
@@ -63,7 +63,7 @@ jobs:
|
|
|
63
63
|
if: github.ref_name == 'master'
|
|
64
64
|
run: CI=true npm run semantic-release
|
|
65
65
|
- name: Slack notification
|
|
66
|
-
uses: 8398a7/action-slack@
|
|
66
|
+
uses: 8398a7/action-slack@v3
|
|
67
67
|
with:
|
|
68
68
|
status: ${{ job.status }}
|
|
69
69
|
fields: repo,message,author,job,ref
|
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
v20.14.0
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { getEslintRulesForJs } = require('@emartech/rti-server-tools');
|
|
4
|
+
const globals = require('globals');
|
|
5
|
+
|
|
6
|
+
module.exports = [
|
|
7
|
+
...getEslintRulesForJs(),
|
|
8
|
+
{
|
|
9
|
+
languageOptions: {
|
|
10
|
+
globals: globals.node
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
files: ['**/*.spec.js', 'test-helpers/*.js'],
|
|
15
|
+
languageOptions: {
|
|
16
|
+
globals: globals.jest
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@emartech/aggregate-metric-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "aggregate metrics in memory for logging",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,21 +29,21 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@emartech/json-logger": "^8.0.
|
|
33
|
-
"@google-cloud/monitoring": "^
|
|
34
|
-
"date-fns": "2.
|
|
35
|
-
"json-stable-stringify": "^1.
|
|
32
|
+
"@emartech/json-logger": "^8.0.3",
|
|
33
|
+
"@google-cloud/monitoring": "^3.0.2",
|
|
34
|
+
"date-fns": "^2.3.0",
|
|
35
|
+
"json-stable-stringify": "^1.1.1",
|
|
36
36
|
"lodash": "^4.17.15",
|
|
37
37
|
"ms": "^2.1.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@
|
|
40
|
+
"@emartech/rti-server-tools": "^6.13.8",
|
|
41
|
+
"@sinonjs/fake-timers": "^11.2.2",
|
|
42
|
+
"@types/jest": "^29.5.12",
|
|
42
43
|
"dotenv-haphap": "^3.1.2",
|
|
43
|
-
"eslint": "
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"jest": "29.7.0",
|
|
44
|
+
"eslint": "^9.4.0",
|
|
45
|
+
"globals": "15.4.0",
|
|
46
|
+
"jest": "^29.2.2",
|
|
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', () => {
|
package/.eslintrc.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
env: {
|
|
5
|
-
es6: true,
|
|
6
|
-
browser: true,
|
|
7
|
-
node: true
|
|
8
|
-
},
|
|
9
|
-
parserOptions: {
|
|
10
|
-
ecmaVersion: 2018
|
|
11
|
-
},
|
|
12
|
-
extends: ['eslint:recommended', 'plugin:jest/recommended', 'emarsys'],
|
|
13
|
-
rules: {
|
|
14
|
-
curly: ['error', 'multi-line'],
|
|
15
|
-
'operator-linebreak': ['error', 'after', { overrides: { '?': 'before', ':': 'before' } }]
|
|
16
|
-
},
|
|
17
|
-
overrides: [
|
|
18
|
-
{
|
|
19
|
-
files: ['*.spec.js'],
|
|
20
|
-
env: {
|
|
21
|
-
jest: true
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
};
|