diff --git a/lib/express.js b/lib/express.js index 921a5cc..833d514 100644 --- a/lib/express.js +++ b/lib/express.js @@ -4,7 +4,7 @@ function middleware (request, response, done) { var start = process.hrtime() response.on('finish', function () { - metrics.observe(request.method, request.path, response.statusCode, start) + metrics.observe(request.method, request.route.path, response.statusCode, start) }) return done() diff --git a/lib/hapi.js b/lib/hapi.js index bc3f3e5..50d3d3c 100644 --- a/lib/hapi.js +++ b/lib/hapi.js @@ -20,7 +20,7 @@ function plugin (options) { }) server.on('response', (response) => { - metrics.observe(response.method, response.path, response.response.statusCode, response.epimetheus.start) + metrics.observe(response.method, response.route.path, response.response.statusCode, response.epimetheus.start) }) return done() diff --git a/lib/labels.js b/lib/labels.js index 8460b5f..1873d29 100644 --- a/lib/labels.js +++ b/lib/labels.js @@ -2,12 +2,9 @@ function parse (path) { var ret = { path: path, cardinality: 'many' - } + }; if (path[path.length - 1] != '/') { - if (!path.includes('.')) { - ret.path = path.substr(0, path.lastIndexOf('/') + 1) - } ret.cardinality = 'one' }; diff --git a/lib/restify.js b/lib/restify.js index ad76785..1767609 100644 --- a/lib/restify.js +++ b/lib/restify.js @@ -4,10 +4,11 @@ function middleware (request, response, done) { var start = process.hrtime() response.on('finish', function () { + var path = request.route.path; if (typeof request.path === 'function') { // restify - request.path = request.path() + path = request.path() } - metrics.observe(request.method, request.path, response.statusCode, start) + metrics.observe(request.method, path, response.statusCode, start) }) return done() diff --git a/test/assert-expectations.js b/test/assert-expectations.js index f7abd01..6ccd905 100644 --- a/test/assert-expectations.js +++ b/test/assert-expectations.js @@ -22,7 +22,7 @@ module.exports = function (options) { should.exist(r.headers['content-type']) r.headers['content-type'].should.equal('text/plain; charset=utf-8') b.should.have.string('# HELP ') - b.should.have.string('"/resource/"') + b.should.have.string('"' + options.routePath + '"') b.should.have.string('cardinality="one"') b.should.have.string('cardinality="many"') b.should.have.string('status="200"') diff --git a/test/express.js b/test/express.js index 327d933..ebb94fa 100644 --- a/test/express.js +++ b/test/express.js @@ -6,6 +6,8 @@ const assert = require('chai').assert const libExpress = require('../lib/express') function setup (options) { + options.routePath = '/resource/:id'; + return describe('express ' + options.url, () => { before((done) => { const app = express() @@ -13,7 +15,7 @@ function setup (options) { app.get('/', (req, res) => { res.send() }) - app.get('/resource/:id', (req, res) => { + app.get(options.routePath, (req, res) => { res.send() }) this.server = app.listen(3000, done) diff --git a/test/hapi.js b/test/hapi.js index 04031ef..7e2e2ff 100644 --- a/test/hapi.js +++ b/test/hapi.js @@ -6,6 +6,8 @@ const epithemeus = require('../index') const assertExpectations = require('./assert-expectations') function setup (options) { + options.routePath = '/resource/{id}'; + return describe('hapi ' + options.url, () => { before((done) => { this.server = new Hapi.Server() @@ -22,7 +24,7 @@ function setup (options) { }) this.server.route({ method: 'GET', - path: '/resource/101', + path: options.routePath, handler: (req, resp) => { resp() } diff --git a/test/http.js b/test/http.js index 4758104..06bc6aa 100644 --- a/test/http.js +++ b/test/http.js @@ -4,6 +4,8 @@ const epithemeus = require('../index') const assertExpectations = require('./assert-expectations') function setup (options) { + options.routePath = '/resource/101'; + return describe('native ' + options.url, () => { before((done) => { this.server = http.createServer((req, res) => { diff --git a/test/labels.js b/test/labels.js index d0a6a0e..6dcf94b 100644 --- a/test/labels.js +++ b/test/labels.js @@ -6,17 +6,17 @@ describe('labels', () => { labels.parse('/users/').path.should.equal('/users/') labels.parse('/users/').cardinality.should.equal('many') }) - it('should parse /users/freddie', () => { - labels.parse('/users/freddie').path.should.equal('/users/') - labels.parse('/users/freddie').cardinality.should.equal('one') + it('should parse /users/:freddie', () => { + labels.parse('/users/:freddie').path.should.equal('/users/:freddie') + labels.parse('/users/:freddie').cardinality.should.equal('one') }) it('should parse /staff/users/', () => { labels.parse('/staff/users/').path.should.equal('/staff/users/') labels.parse('/staff/users/').cardinality.should.equal('many') }) - it('should parse /staff/users/freddie', () => { - labels.parse('/staff/users/freddie').path.should.equal('/staff/users/') - labels.parse('/staff/users/freddie').cardinality.should.equal('one') + it('should parse /staff/users/:freddie', () => { + labels.parse('/staff/users/:freddie').path.should.equal('/staff/users/:freddie') + labels.parse('/staff/users/:freddie').cardinality.should.equal('one') }) it('should parse /static/page.css', () => { labels.parse('/static/page.css').path.should.equal('/static/page.css') diff --git a/test/restify.js b/test/restify.js index 41b0cab..2f214a9 100644 --- a/test/restify.js +++ b/test/restify.js @@ -4,6 +4,8 @@ const epithemeus = require('../index') const assertExpectations = require('./assert-expectations') function setup (options) { + options.routePath = '/resource/:id'; + describe('restify ' + options.url, () => { before((done) => { this.server = restify.createServer() @@ -12,7 +14,7 @@ function setup (options) { res.send() done() }) - this.server.get('/resource/:id', (req, res, done) => { + this.server.get(options.routePath, (req, res, done) => { res.send() done() })