Skip to content

Commit

Permalink
dependencies update, linter and v1
Browse files Browse the repository at this point in the history
  • Loading branch information
goenning committed Jul 8, 2016
1 parent 4927019 commit 44e23a5
Show file tree
Hide file tree
Showing 6 changed files with 208 additions and 208 deletions.
33 changes: 18 additions & 15 deletions .eslintrc.json
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"]
}
}
10 changes: 5 additions & 5 deletions README.md
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.
62 changes: 31 additions & 31 deletions index.js
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();
}
};
};
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miniprofiler-redis",
"version": "0.0.4",
"version": "1.0.0",
"description": "A redis provider for miniprofiler timing analysis",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -32,11 +32,11 @@
"chai": "^3.5.0",
"coveralls": "^2.11.9",
"docker-ip": "^2.0.1",
"eslint": "^2.11.0",
"istanbul": "^0.4.3",
"miniprofiler": "^0.2.3",
"eslint": "^3.0.1",
"istanbul": "^0.4.4",
"miniprofiler": "^1.2.0",
"mocha": "^2.5.3",
"redis": "^2.6.1",
"redis": "^2.6.2",
"request": "^2.72.0"
}
}
193 changes: 92 additions & 101 deletions tests/index.js
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();
});
});

});
Loading

0 comments on commit 44e23a5

Please sign in to comment.