Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't break memcached.getMulti with instrumentation #190

Closed
Closed
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
6 changes: 4 additions & 2 deletions lib/instrumentation/memcached.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,13 @@ module.exports = function initialize(agent, memcached) {
})
})

var newArgs = Array.prototype.slice.call(arguments)

// re-wrap the meta-call for the command object
var rewrapped = function rewrapped() { return metacall; }
newArgs[0] = function rewrapped() { return metacall; }

// finally, execute the original command
return command.call(this, rewrapped)
return command.apply(this, newArgs)
})
})
}
41 changes: 32 additions & 9 deletions test/integration/instrumentation/memcached.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var path = require('path')
test("memcached instrumentation should find memcached calls in the transaction trace",
{timeout : 5000},
function (t) {
t.plan(29)
t.plan(32)

var self = this
helper.bootstrapMemcached(function cb_bootstrapMemcached(error, app) {
Expand All @@ -19,7 +19,22 @@ test("memcached instrumentation should find memcached calls in the transaction t
var agent = helper.instrumentMockedAgent()
var Memcached = require('memcached')

var memcached = new Memcached(params.memcached_host + ':' + params.memcached_port)
var servers = [
params.memcached_host + ':' + params.memcached_port,
params.memcached_host + ':' + params.memcached_port_2
]

var memcached = new Memcached(servers)

// Here we fake out the hash ring so we can artificially force our
// two keys to spread across the two different servers and thus
// prove we can support a multi-server setup.
var fakeHashRing = {
get: function get(key) {
return key === 'otherkey' ? servers[1] : servers[0]
}
}
memcached.HashRing = fakeHashRing

// need to capture parameters
agent.config.capture_params = true
Expand Down Expand Up @@ -105,15 +120,23 @@ test("memcached instrumentation should find memcached calls in the transaction t
"should register the set")
t.equals(setSegment.parameters.key, "[\"otherkey\"]",
"should have the set key as a parameter")
t.equals(setSegment.children.length, 1,
"set should have an only child")
t.equals(setSegment.children.length, 2,
"set should have the two gets as children")

var getSegment = setSegment.children[0]
t.equals(getSegment.name, "Datastore/operation/Memcache/get",
"should register the get")
t.equals(getSegment.parameters.key, "[[\"testkey\",\"otherkey\"]]",
var getSegment1 = setSegment.children[0]
t.equals(getSegment1.name, "Datastore/operation/Memcache/get",
"should register the first get")
t.equals(getSegment1.parameters.key, "[[\"testkey\",\"otherkey\"]]",
"should have the multiple keys fetched as a parameter")
t.equals(getSegment.children.length, 0,
t.equals(getSegment1.children.length, 0,
"get should leave us here at the end")

var getSegment2 = setSegment.children[1]
t.equals(getSegment2.name, "Datastore/operation/Memcache/get",
"should register the second get")
t.equals(getSegment2.parameters.key, "[[\"testkey\",\"otherkey\"]]",
"should have the multiple keys fetched as a parameter")
t.equals(getSegment2.children.length, 0,
"get should leave us here at the end")
})
})
Expand Down
1 change: 1 addition & 0 deletions test/lib/params.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
memcached_host: process.env.NR_NODE_TEST_MEMCACHED_HOST || 'localhost',
memcached_port: process.env.NR_NODE_TEST_MEMCACHED_PORT || 11211,
memcached_port_2: process.env.NR_NODE_TEST_MEMCACHED_PORT_2 || 11212,

mongodb_host: process.env.NR_NODE_TEST_MONGODB_HOST || 'localhost',
mongodb_port: process.env.NR_NODE_TEST_MONGODB_PORT || 27017,
Expand Down