@tryghost/metrics 0.2.2 → 0.2.6

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.
Files changed (2) hide show
  1. package/lib/GhostMetrics.js +17 -3
  2. package/package.json +12 -8
@@ -1,6 +1,13 @@
1
1
  const jsonStringifySafe = require('json-stringify-safe');
2
2
  const GhostPrettyStream = require('@tryghost/pretty-stream');
3
3
 
4
+ try {
5
+ const allSettled = require('promise.allsettled');
6
+ allSettled.shim();
7
+ } catch (err) {
8
+ // no-op - shim not required
9
+ }
10
+
4
11
  /**
5
12
  * @description Metric shipper class built on the loggingrc config used in Ghost projects
6
13
  */
@@ -62,6 +69,8 @@ class GhostMetrics {
62
69
  msg: `Metric ${name}: ${jsonStringifySafe(value)}`,
63
70
  level: 30 // Magic number, log level for info
64
71
  });
72
+
73
+ return Promise.resolve();
65
74
  };
66
75
  }
67
76
 
@@ -78,7 +87,9 @@ class GhostMetrics {
78
87
  auth: {
79
88
  username: this.elasticsearch.username,
80
89
  password: this.elasticsearch.password
81
- }
90
+ },
91
+ requestTimeout: 5000,
92
+ proxy: 'proxy' in this.elasticsearch ? this.elasticsearch.proxy : null
82
93
  });
83
94
 
84
95
  this.shippers.elasticsearch = (name, value) => {
@@ -91,7 +102,7 @@ class GhostMetrics {
91
102
  value.metadata = this.metadata;
92
103
  }
93
104
 
94
- elasticSearch.index(value, `metrics-${name}`);
105
+ return elasticSearch.index(value, `metrics-${name}`);
95
106
  };
96
107
  }
97
108
 
@@ -101,9 +112,12 @@ class GhostMetrics {
101
112
  * @param {any} value Value of metric, will be co-erced to an object before being shipped
102
113
  */
103
114
  metric(name, value) {
115
+ const promises = [];
104
116
  for (const metricShipper of Object.values(this.shippers)) {
105
- metricShipper(name, value);
117
+ promises.push(metricShipper(name, value));
106
118
  }
119
+
120
+ return Promise.allSettled(promises).then(() => null);
107
121
  }
108
122
  }
109
123
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@tryghost/metrics",
3
- "version": "0.2.2",
3
+ "version": "0.2.6",
4
4
  "repository": "https://github.com/TryGhost/framework/tree/main/packages/metrics",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "dev": "echo \"Implement me!\"",
10
- "test": "NODE_ENV=testing c8 --check-coverage mocha './test/**/*.test.js'",
10
+ "test": "NODE_ENV=testing c8 --reporter text --reporter cobertura --check-coverage mocha './test/**/*.test.js'",
11
11
  "lint": "eslint . --ext .js --cache",
12
12
  "posttest": "yarn lint"
13
13
  },
@@ -20,15 +20,19 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "c8": "7.10.0",
23
- "mocha": "9.1.2",
24
- "rewire": "^5.0.0",
23
+ "mocha": "9.1.3",
24
+ "rewire": "5.0.0",
25
25
  "should": "13.2.3",
26
26
  "sinon": "11.1.2"
27
27
  },
28
28
  "dependencies": {
29
- "@tryghost/elasticsearch": "^0.1.2",
30
- "@tryghost/pretty-stream": "^0.1.1",
31
- "@tryghost/root-utils": "^0.3.6"
29
+ "@tryghost/elasticsearch": "^0.1.3",
30
+ "@tryghost/pretty-stream": "^0.1.2",
31
+ "@tryghost/root-utils": "^0.3.7",
32
+ "json-stringify-safe": "^5.0.1"
32
33
  },
33
- "gitHead": "4d1564df4c15a78be73c9473c6ac64a9f57c0fe8"
34
+ "optionalDependencies": {
35
+ "promise.allsettled": "^1.0.5"
36
+ },
37
+ "gitHead": "9442fb16ba42077cd3d6dc751beaf7470302ef14"
34
38
  }