Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion lib/hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions lib/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};

Expand Down
5 changes: 3 additions & 2 deletions lib/restify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion test/assert-expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"')
Expand Down
4 changes: 3 additions & 1 deletion test/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ 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()
epithemeus.instrument(app, 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)
Expand Down
4 changes: 3 additions & 1 deletion test/hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -22,7 +24,7 @@ function setup (options) {
})
this.server.route({
method: 'GET',
path: '/resource/101',
path: options.routePath,
handler: (req, resp) => {
resp()
}
Expand Down
2 changes: 2 additions & 0 deletions test/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
12 changes: 6 additions & 6 deletions test/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion test/restify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
})
Expand Down