Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-prom-bundle

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-prom-bundle - npm Package Compare versions

Comparing version 6.3.0 to 6.3.1

6

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc