Compare commits

...

9 Commits
2.1.0 ... 2.2.0

Author SHA1 Message Date
Konstantin Pogorelov
5b1aa494cb version 2.2.0 - normalizeStatus draft 2017-03-28 17:14:33 +02:00
The Experimentalist
65549a769b Merge pull request #4 from PauloPaquielli/feature/normalizeStatusCode 2017-03-28 17:08:57 +02:00
Paulo Duarte
de83ac09a0 Remove if unnecessary 2017-03-27 17:35:13 -03:00
Paulo Duarte
52865dfb02 Back version to prom-client 2017-03-27 17:17:59 -03:00
Paulo Duarte
5c6ed64a31 Fix lint error 2017-03-27 17:16:51 -03:00
Paulo Duarte
d8c6492163 Implement test 2017-03-27 12:03:53 -03:00
Paulo Duarte
c92b85ae96 Update prom-client 2017-03-24 11:08:29 -03:00
Paulo Duarte
48f8b992fd Make normalizeStatusCode generic 2017-03-24 02:18:41 -03:00
Paulo Duarte
61e4343a8c Implements group in status code metrics 2017-03-23 14:12:29 -03:00
5 changed files with 43 additions and 3 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "express-prom-bundle",
"version": "2.1.0",
"version": "2.2.0",
"description": "express middleware with popular prometheus metrics in one bundle",
"main": "src/index.js",
"keywords": [

View File

@@ -0,0 +1,23 @@
'use strict';
/* eslint-env jasmine */
const normalizeStatusCode = require('../src/normalizeStatusCode');
describe('normalizeStatusCode', () => {
it('returns original if disabled in opts', () => {
expect(
normalizeStatusCode({status_code: 404}, {normalizeStatusCode: false})
).toBe(404);
});
it('returns run callback if configured', () => {
expect(
normalizeStatusCode(
{status_code: 500},
{
formatStatusCode: res => String(res.status_code).slice(0, -2) + 'xx'
}
)
).toBe('5xx');
});
});

View File

@@ -2,6 +2,7 @@
const onFinished = require('on-finished');
const promClient = require('prom-client');
const normalizePath = require('./normalizePath');
const normalizeStatusCode = require('./normalizeStatusCode');
function matchVsRegExps(element, regexps) {
for (let regexp of regexps) {
@@ -116,7 +117,12 @@ function main(opts) {
labels = {'status_code': 0};
let timer = metrics[httpMtricName].startTimer(labels);
onFinished(res, () => {
labels.status_code = res.statusCode;
if (opts.normalizeStatusCode) {
labels.status_code = main.normalizeStatusCode(res, opts);
} else {
labels.status_code = res.statusCode;
}
if (opts.includeMethod) {
labels.method = req.method;
}
@@ -139,4 +145,5 @@ function main(opts) {
main.promClient = promClient;
main.normalizePath = normalizePath;
main.normalizeStatusCode = normalizeStatusCode;
module.exports = main;

View File

@@ -24,4 +24,3 @@ module.exports = function(req, opts) {
}
return urlValueParser.replacePathValues(path);
};

View File

@@ -0,0 +1,11 @@
'use strict';
module.exports = function(res, opts) {
opts = opts || {};
if (typeof opts.formatStatusCode === 'function') {
return opts.formatStatusCode(res, opts);
}
return res.status_code;
};