express-prom-bundle
Advanced tools
Comparing version 6.3.0 to 6.3.1
{ | ||
"name": "express-prom-bundle", | ||
"version": "6.3.0", | ||
"version": "6.3.1", | ||
"description": "express middleware with popular prometheus metrics in one bundle", | ||
@@ -39,3 +39,3 @@ "main": "src/index.js", | ||
"koa-connect": "^2.0.1", | ||
"prom-client": "^12.0.0", | ||
"prom-client": "^13.0.0", | ||
"supertest": "^3.3.0", | ||
@@ -46,3 +46,3 @@ "supertest-koa-agent": "^0.3.0", | ||
"peerDependencies": { | ||
"prom-client": "^12.0.0" | ||
"prom-client": "^13.0.0" | ||
}, | ||
@@ -49,0 +49,0 @@ "repository": { |
@@ -23,10 +23,27 @@ const onFinished = require('on-finished'); | ||
const metricsMiddleware = function(req, res) { | ||
aggregatorRegistry.clusterMetrics((err, clusterMetrics) => { | ||
function sendClusterMetrics(clusterMetrics) { | ||
res.set('Content-Type', aggregatorRegistry.contentType); | ||
res.send(clusterMetrics); | ||
} | ||
function sendClusterMetricsError(err) { | ||
console.error(err); | ||
return res.sendStatus(500); | ||
} | ||
// since prom-client@13 clusterMetrics() method doesn't take cb param, | ||
// but we provide it anyway, as at this stage it's unknown which version of prom-client is used | ||
const response = aggregatorRegistry.clusterMetrics((err, clusterMetrics) => { | ||
if (err) { | ||
console.error(err); | ||
return res.sendStatus(500); | ||
return sendClusterMetricsError(err); | ||
} | ||
res.set('Content-Type', aggregatorRegistry.contentType); | ||
res.send(clusterMetrics); | ||
sendClusterMetrics(clusterMetrics); | ||
}); | ||
// if we find out that it was a promise and our cb was useless... | ||
if (response && response.then) { | ||
response | ||
.then(result => sendClusterMetrics(result)) | ||
.catch(err => sendClusterMetricsError(err)); | ||
} | ||
}; | ||
@@ -126,5 +143,15 @@ | ||
const metricsMiddleware = function(req, res) { | ||
const metricsMiddleware = function(req, res, next) { | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
res.end(opts.promRegistry.metrics()); | ||
const metricsResponse = opts.promRegistry.metrics(); | ||
// starting from prom-client@13 .metrics() returns a Promise | ||
if (metricsResponse.then) { | ||
metricsResponse | ||
.then(output => res.end(output)) | ||
.catch(err => next(err)); | ||
} else { | ||
// compatibility fallback for previous versions of prom-client@<=12 | ||
res.end(metricsResponse); | ||
} | ||
}; | ||
@@ -131,0 +158,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22150
266