@emartech/aggregate-metric-logger 3.0.0 → 3.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/package.json
CHANGED
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
const logger = require('@emartech/json-logger')('aggregate-metric-logger');
|
|
4
4
|
const monitoring = require('@google-cloud/monitoring');
|
|
5
|
+
const { chunk } = require('lodash');
|
|
6
|
+
|
|
7
|
+
const MAX_TIME_SERIES_COUNT = 200;
|
|
5
8
|
|
|
6
9
|
exports.publishTimeSeries = async timeSeries => {
|
|
7
10
|
try {
|
|
8
11
|
const client = getMonitoringClient();
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
for (const timeSeriesChunk of chunk(timeSeries, MAX_TIME_SERIES_COUNT)) {
|
|
14
|
+
await client.createTimeSeries({
|
|
15
|
+
name: client.projectPath(process.env.MONITORING_PROJECT_ID),
|
|
16
|
+
timeSeries: timeSeriesChunk
|
|
17
|
+
});
|
|
18
|
+
}
|
|
13
19
|
} catch (error) {
|
|
14
20
|
logger.warnFromError('pushing-metrics-failed', error, { do_not_alert: true });
|
|
15
21
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const { MetricServiceClient } = require('@google-cloud/monitoring');
|
|
4
|
+
const { range } = require('lodash');
|
|
4
5
|
const { publishTimeSeries } = require('./gcp-time-series-publisher');
|
|
5
6
|
const { stubCreateTimeSeries } = require('../../test-helpers/test-helpers');
|
|
6
7
|
|
|
@@ -8,7 +9,7 @@ jest.mock('@google-cloud/monitoring');
|
|
|
8
9
|
|
|
9
10
|
describe('gcpMetricPublisher', () => {
|
|
10
11
|
describe('publishTimeSeries', () => {
|
|
11
|
-
it('should push
|
|
12
|
+
it('should push metrics to gcp to the correct project', async () => {
|
|
12
13
|
stubCreateTimeSeries();
|
|
13
14
|
process.env.HOSTNAME = 'test-host';
|
|
14
15
|
process.env.MONITORING_PROJECT_ID = 'test-project';
|
|
@@ -21,5 +22,23 @@ describe('gcpMetricPublisher', () => {
|
|
|
21
22
|
timeSeries
|
|
22
23
|
});
|
|
23
24
|
});
|
|
25
|
+
|
|
26
|
+
it('should push metrics to gcp in batches', async () => {
|
|
27
|
+
stubCreateTimeSeries();
|
|
28
|
+
process.env.HOSTNAME = 'test-host';
|
|
29
|
+
process.env.MONITORING_PROJECT_ID = 'test-project';
|
|
30
|
+
|
|
31
|
+
await publishTimeSeries(range(1, 300));
|
|
32
|
+
|
|
33
|
+
expect(MetricServiceClient.prototype.createTimeSeries).toHaveBeenCalledWith({
|
|
34
|
+
name: 'projects/test-project',
|
|
35
|
+
timeSeries: range(1, 201)
|
|
36
|
+
});
|
|
37
|
+
expect(MetricServiceClient.prototype.createTimeSeries).toHaveBeenCalledWith({
|
|
38
|
+
name: 'projects/test-project',
|
|
39
|
+
timeSeries: range(201, 300)
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
24
43
|
});
|
|
25
44
|
});
|