-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
208 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
{ | ||
"extends": "eslint:recommended", | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"semi": [2, "always"], | ||
"strict": ["error", "global"], | ||
"no-unused-vars": ["error", { "vars": "all", "args": "none" }], | ||
"quotes": ["error", "single", { "avoidEscape": true } ], | ||
"space-before-function-paren": ["error", "never"] | ||
} | ||
} | ||
{ | ||
"extends": "eslint:recommended", | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"semi": ["error", "always"], | ||
"no-console": 0, | ||
"no-var": "error", | ||
"prefer-const": "error", | ||
"strict": ["error", "global"], | ||
"no-unused-vars": ["error", { "vars": "all", "args": "none" }], | ||
"quotes": ["error", "single", { "avoidEscape": true } ], | ||
"space-before-function-paren": ["error", "never"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# miniprofiler-redis | ||
|
||
A [redis](https://www.npmjs.com/package/redis) provider for [miniprofiler](https://www.npmjs.com/package/miniprofiler) timing analysis. | ||
|
||
Pending documentation and examples... | ||
# miniprofiler-redis | ||
|
||
A [redis](https://www.npmjs.com/package/redis) provider for [miniprofiler](https://www.npmjs.com/package/miniprofiler) timing analysis. | ||
|
||
For more information, please visit https://github.com/MiniProfiler/node. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
'use strict'; | ||
|
||
var redisSendCommand; | ||
var blacklist = ['info']; | ||
|
||
module.exports = function(redis) { | ||
redisSendCommand = redisSendCommand || redis.RedisClient.prototype.internal_send_command; | ||
|
||
return { | ||
name: 'redis', | ||
handler: function(req, res, next) { | ||
|
||
redis.RedisClient.prototype.internal_send_command = !req.miniprofiler || !req.miniprofiler.enabled ? redisSendCommand : function(cmd) { | ||
if (this.ready && blacklist.indexOf(cmd.command) == -1) { | ||
var callback = cmd.callback; | ||
if (callback && req && req.miniprofiler) { | ||
var query = `${cmd.command} ${cmd.args.join(', ')}`.trim(); | ||
var timing = req.miniprofiler.startTimeQuery('redis', query); | ||
cmd.callback = function() { | ||
req.miniprofiler.stopTimeQuery(timing); | ||
callback.apply(this, arguments); | ||
}; | ||
} | ||
} | ||
redisSendCommand.call(this, cmd); | ||
}; | ||
|
||
next(); | ||
} | ||
}; | ||
}; | ||
'use strict'; | ||
|
||
let redisSendCommand; | ||
const blacklist = ['info']; | ||
|
||
module.exports = function(redis) { | ||
redisSendCommand = redisSendCommand || redis.RedisClient.prototype.internal_send_command; | ||
|
||
return { | ||
name: 'redis', | ||
handler: function(req, res, next) { | ||
|
||
redis.RedisClient.prototype.internal_send_command = !req.miniprofiler || !req.miniprofiler.enabled ? redisSendCommand : function(cmd) { | ||
if (this.ready && blacklist.indexOf(cmd.command) == -1) { | ||
const callback = cmd.callback; | ||
if (callback && req && req.miniprofiler) { | ||
const query = `${cmd.command} ${cmd.args.join(', ')}`.trim(); | ||
const timing = req.miniprofiler.startTimeQuery('redis', query); | ||
cmd.callback = function() { | ||
req.miniprofiler.stopTimeQuery(timing); | ||
callback.apply(this, arguments); | ||
}; | ||
} | ||
} | ||
redisSendCommand.call(this, cmd); | ||
}; | ||
|
||
next(); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,92 @@ | ||
'use strict'; | ||
|
||
var expect = require('chai').expect; | ||
var request = require('request'); | ||
var server = require('./server'); | ||
|
||
describe('Redis Tests', function() { | ||
|
||
before((done) => { server.listen(8080, done); }); | ||
after((done) => { server.close(done); }); | ||
|
||
it('should profile redis SET command', function(done) { | ||
request('http://localhost:8080/redis-set-key', (err, response, body) => { | ||
var ids = JSON.parse(response.headers['x-miniprofiler-ids']); | ||
expect(ids).to.have.lengthOf(1); | ||
|
||
request.post({url: 'http://localhost:8080/mini-profiler-resources/results/', form: { id: ids[0], popup: 1 } }, (err, response, body) => { | ||
var result = JSON.parse(body); | ||
|
||
expect(result.Id).to.equal(ids[0]); | ||
expect(result.Name).to.equal('/redis-set-key'); | ||
expect(result.Root.Children).to.be.empty; | ||
expect(result.Root.CustomTimings).to.have.property('redis'); | ||
expect(result.Root.CustomTimings.redis).to.have.lengthOf(1); | ||
|
||
expect(result.Root.CustomTimings.redis[0].ExecuteType).to.be.equal('redis'); | ||
expect(result.Root.CustomTimings.redis[0].CommandString).to.be.equal('set key, Awesome!'); | ||
expect(result.Root.CustomTimings.redis[0].DurationMilliseconds).to.be.below(result.DurationMilliseconds); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
it('should profile redis SET and GET command', function(done) { | ||
request('http://localhost:8080/redis-set-get-key', (err, response, body) => { | ||
var ids = JSON.parse(response.headers['x-miniprofiler-ids']); | ||
expect(body).to.be.equal('Awesome!'); | ||
expect(ids).to.have.lengthOf(1); | ||
|
||
request.post({url: 'http://localhost:8080/mini-profiler-resources/results/', form: { id: ids[0], popup: 1 } }, (err, response, body) => { | ||
var result = JSON.parse(body); | ||
|
||
expect(result.Id).to.equal(ids[0]); | ||
expect(result.Name).to.equal('/redis-set-get-key'); | ||
expect(result.Root.Children).to.be.empty; | ||
expect(result.Root.CustomTimings).to.have.property('redis'); | ||
expect(result.Root.CustomTimings.redis).to.have.lengthOf(2); | ||
|
||
expect(result.Root.CustomTimings.redis[0].ExecuteType).to.be.equal('redis'); | ||
expect(result.Root.CustomTimings.redis[0].CommandString).to.be.equal('set key, Awesome!'); | ||
expect(result.Root.CustomTimings.redis[0].DurationMilliseconds).to.be.below(result.DurationMilliseconds); | ||
|
||
expect(result.Root.CustomTimings.redis[1].ExecuteType).to.be.equal('redis'); | ||
expect(result.Root.CustomTimings.redis[1].CommandString).to.be.equal('get key'); | ||
expect(result.Root.CustomTimings.redis[1].DurationMilliseconds).to.be.below(result.DurationMilliseconds); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not profile redis when used fire and forget', function(done) { | ||
request('http://localhost:8080/redis-set-without-callback', (err, response, body) => { | ||
var ids = JSON.parse(response.headers['x-miniprofiler-ids']); | ||
expect(body).to.be.equal(''); | ||
expect(ids).to.have.lengthOf(1); | ||
|
||
request.post({url: 'http://localhost:8080/mini-profiler-resources/results/', form: { id: ids[0], popup: 1 } }, (err, response, body) => { | ||
var result = JSON.parse(body); | ||
|
||
expect(result.Id).to.equal(ids[0]); | ||
expect(result.Name).to.equal('/redis-set-without-callback'); | ||
expect(result.Root.Children).to.be.empty; | ||
expect(result.Root.CustomTimings).to.not.have.property('redis'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not profile INFO as a custom command', function(done) { | ||
request('http://localhost:8080/redis-info', (err, response) => { | ||
var ids = JSON.parse(response.headers['x-miniprofiler-ids']); | ||
expect(ids).to.have.lengthOf(1); | ||
|
||
request.post({url: 'http://localhost:8080/mini-profiler-resources/results/', form: { id: ids[0], popup: 1 } }, (err, response, body) => { | ||
var result = JSON.parse(body); | ||
expect(result.Root.CustomTimings).to.not.have.property('redis'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not break redis usage on unprofiled routes', function(done) { | ||
request('http://localhost:8080/unprofiled', (err, response, body) => { | ||
expect(response.headers).to.not.include.keys('x-miniprofiler-ids'); | ||
expect(body).to.be.equal('Some value'); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const request = require('request'); | ||
const server = require('./server'); | ||
|
||
describe('Redis Tests', function() { | ||
|
||
before((done) => { server.listen(8080, done); }); | ||
after((done) => { server.close(done); }); | ||
|
||
it('should profile redis SET command', function(done) { | ||
request('http://localhost:8080/redis-set-key', (err, response, body) => { | ||
const ids = JSON.parse(response.headers['x-miniprofiler-ids']); | ||
|
||
request.post({url: 'http://localhost:8080/mini-profiler-resources/results/', form: { id: ids[0], popup: 1 } }, (err, response, body) => { | ||
const result = JSON.parse(body); | ||
|
||
expect(result.Root.CustomTimings).to.have.property('redis'); | ||
expect(result.Root.CustomTimings.redis).to.have.lengthOf(1); | ||
|
||
expect(result.Root.CustomTimings.redis[0].ExecuteType).to.be.equal('redis'); | ||
expect(result.Root.CustomTimings.redis[0].CommandString).to.be.equal('set key, Awesome!'); | ||
expect(result.Root.CustomTimings.redis[0].DurationMilliseconds).to.be.below(result.DurationMilliseconds); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
it('should profile redis SET and GET command', function(done) { | ||
request('http://localhost:8080/redis-set-get-key', (err, response, body) => { | ||
const ids = JSON.parse(response.headers['x-miniprofiler-ids']); | ||
expect(body).to.be.equal('Awesome!'); | ||
|
||
request.post({url: 'http://localhost:8080/mini-profiler-resources/results/', form: { id: ids[0], popup: 1 } }, (err, response, body) => { | ||
const result = JSON.parse(body); | ||
|
||
expect(result.Root.CustomTimings).to.have.property('redis'); | ||
expect(result.Root.CustomTimings.redis).to.have.lengthOf(2); | ||
|
||
expect(result.Root.CustomTimings.redis[0].ExecuteType).to.be.equal('redis'); | ||
expect(result.Root.CustomTimings.redis[0].CommandString).to.be.equal('set key, Awesome!'); | ||
expect(result.Root.CustomTimings.redis[0].DurationMilliseconds).to.be.below(result.DurationMilliseconds); | ||
|
||
expect(result.Root.CustomTimings.redis[1].ExecuteType).to.be.equal('redis'); | ||
expect(result.Root.CustomTimings.redis[1].CommandString).to.be.equal('get key'); | ||
expect(result.Root.CustomTimings.redis[1].DurationMilliseconds).to.be.below(result.DurationMilliseconds); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not profile redis when used fire and forget', function(done) { | ||
request('http://localhost:8080/redis-set-without-callback', (err, response, body) => { | ||
const ids = JSON.parse(response.headers['x-miniprofiler-ids']); | ||
expect(body).to.be.equal(''); | ||
expect(ids).to.have.lengthOf(1); | ||
|
||
request.post({url: 'http://localhost:8080/mini-profiler-resources/results/', form: { id: ids[0], popup: 1 } }, (err, response, body) => { | ||
const result = JSON.parse(body); | ||
|
||
expect(result.Id).to.equal(ids[0]); | ||
expect(result.Name).to.equal('/redis-set-without-callback'); | ||
expect(result.Root.Children).to.be.empty; | ||
expect(result.Root.CustomTimings).to.not.have.property('redis'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not profile INFO as a custom command', function(done) { | ||
request('http://localhost:8080/redis-info', (err, response) => { | ||
const ids = JSON.parse(response.headers['x-miniprofiler-ids']); | ||
|
||
request.post({url: 'http://localhost:8080/mini-profiler-resources/results/', form: { id: ids[0], popup: 1 } }, (err, response, body) => { | ||
const result = JSON.parse(body); | ||
expect(result.Root.CustomTimings).to.not.have.property('redis'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('should not break redis usage on unprofiled routes', function(done) { | ||
request('http://localhost:8080/unprofiled', (err, response, body) => { | ||
expect(response.headers).to.not.include.keys('x-miniprofiler-ids'); | ||
expect(body).to.be.equal('Some value'); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); |
Oops, something went wrong.