mirror of
https://github.com/BreizhHardware/express-prom-bundle.git
synced 2026-01-18 16:27:28 +01:00
codestyle: fix indentation
This commit is contained in:
56
src/index.js
56
src/index.js
@@ -17,37 +17,37 @@ function matchVsRegExps(element, regexps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function clusterMetrics() {
|
function clusterMetrics() {
|
||||||
const aggregatorRegistry = new promClient.AggregatorRegistry();
|
const aggregatorRegistry = new promClient.AggregatorRegistry();
|
||||||
|
|
||||||
const metricsMiddleware = function(req, res) {
|
const metricsMiddleware = function(req, res) {
|
||||||
function sendClusterMetrics(clusterMetrics) {
|
function sendClusterMetrics(clusterMetrics) {
|
||||||
res.set('Content-Type', aggregatorRegistry.contentType);
|
res.set('Content-Type', aggregatorRegistry.contentType);
|
||||||
res.send(clusterMetrics);
|
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) {
|
||||||
|
return sendClusterMetricsError(err);
|
||||||
}
|
}
|
||||||
|
sendClusterMetrics(clusterMetrics);
|
||||||
|
});
|
||||||
|
|
||||||
function sendClusterMetricsError(err) {
|
// if we find out that it was a promise and our cb was useless...
|
||||||
console.error(err);
|
if (response && response.then) {
|
||||||
return res.sendStatus(500);
|
response
|
||||||
}
|
.then(result => sendClusterMetrics(result))
|
||||||
|
.catch(err => sendClusterMetricsError(err));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// since prom-client@13 clusterMetrics() method doesn't take cb param,
|
return metricsMiddleware;
|
||||||
// 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) {
|
|
||||||
return sendClusterMetricsError(err);
|
|
||||||
}
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return metricsMiddleware;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function main(opts) {
|
function main(opts) {
|
||||||
@@ -161,7 +161,7 @@ function main(opts) {
|
|||||||
const path = req.originalUrl || req.url; // originalUrl gets lost in koa-connect?
|
const path = req.originalUrl || req.url; // originalUrl gets lost in koa-connect?
|
||||||
|
|
||||||
if (opts.autoregister && path.match(metricsMatch)) {
|
if (opts.autoregister && path.match(metricsMatch)) {
|
||||||
return metricsMiddleware(req, res);
|
return metricsMiddleware(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bypass() is checked only after /metrics was processed
|
// bypass() is checked only after /metrics was processed
|
||||||
|
|||||||
Reference in New Issue
Block a user