Skip to content
Merged
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
157 changes: 128 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@
"@hapi/hapi": "21.4.3",
"@ibm/tekton-lint": "1.1.0",
"@koa/router": "14.0.0",
"@redis/client": "5.8.3",
"@redis/client": "5.9.0",
"@redis/client-v4": "npm:@redis/[email protected]",
"@redis/client-v583": "npm:@redis/[email protected]",
"@types/chai": "4.3.0",
"@types/detect-libc": "1.0.0",
"@types/event-loop-lag": "1.0.30",
Expand Down Expand Up @@ -228,9 +229,10 @@
"proxyquire": "2.1.3",
"read-pkg-up": "7.0.1",
"recursive-copy": "2.0.14",
"redis": "5.8.3",
"redis": "5.9.0",
"redis-v3": "npm:[email protected]",
"redis-v4": "npm:[email protected]",
"redis-v583": "npm:[email protected]",
"restify": "11.1.0",
"rimraf": "3.0.2",
"semver": "7.5.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/collector/test/tracing/databases/redis/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ app.get('/blocking', async (req, res) => {
});

app.get('/scan-iterator', async (req, res) => {
if (redisVersion === 'latest') {
// v5: SCAN iterators return collection of keys, enabling multi-key commands like mGet
// v5: SCAN iterators return collection of keys, enabling multi-key commands like mGet
if (redisVersion === 'latest' || redisVersion === 'v583') {
// eslint-disable-next-line no-restricted-syntax
for await (const keys of connection.scanIterator()) {
try {
Expand Down
13 changes: 7 additions & 6 deletions packages/collector/test/tracing/databases/redis/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const globalAgent = require('../../../globalAgent');
// Clustering support was officially introduced in v4
// Redis Sentinel support was added in v5.
const legacyVersion = 'v3';
const versionsSinceV5 = ['latest', 'v583'];

/**
* Supported Redis setups for local testing:
Expand All @@ -52,7 +53,7 @@ const allSetupTypes = ['default', 'cluster', 'sentinel'];
const selectedSetupType = false;
const setupTypesToRun = allSetupTypes.includes(selectedSetupType) ? [selectedSetupType] : allSetupTypes;

const allVersions = ['latest', 'v4', 'v3'];
const allVersions = ['latest', 'v583', 'v4', 'v3'];
const selectedVersion = false;
const versionsToRun = allVersions.includes(selectedVersion) ? [selectedVersion] : allVersions;

Expand All @@ -68,7 +69,7 @@ setupTypesToRun.forEach(setupType => {

const shouldSkipCluster = setupType === 'cluster' && redisVersion === legacyVersion;
// NOTE: sentinel support added in v5(latest).
const shouldSkipSentinel = setupType === 'sentinel' && redisVersion !== 'latest';
const shouldSkipSentinel = setupType === 'sentinel' && !versionsSinceV5.includes(redisVersion);

if (shouldSkipCluster || shouldSkipSentinel) {
mochaSuiteFn = describe.skip;
Expand Down Expand Up @@ -127,7 +128,7 @@ setupTypesToRun.forEach(setupType => {
// In v5, Redis moved “Isolation Pool” into RedisClientPool.
// see: https://github.com/redis/node-redis/blob/master/docs/pool.md
// Only for this test the connection is established via the pool.
if (redisVersion === 'latest' && setupType === 'default') {
if (versionsSinceV5.includes(redisVersion) && setupType === 'default') {
mochaSuiteFn('When connected via clientpool', function () {
globalAgent.setUpCleanUpHooks();
let controls;
Expand Down Expand Up @@ -801,8 +802,8 @@ setupTypesToRun.forEach(setupType => {
]);
// NOTE: v5 SCAN iterators yield collection of keys, enabling multi-key commands like MGET.
// See: https://github.com/redis/node-redis/blob/master/docs/v4-to-v5.md#scan-iterators
const expectedSpanCount = redisVersion === 'latest' ? 1 : 4;
const expectedRedisCommand = redisVersion === 'latest' ? 'mGet' : 'get';
const expectedSpanCount = versionsSinceV5.includes(redisVersion) ? 1 : 4;
const expectedRedisCommand = versionsSinceV5.includes(redisVersion) ? 'mGet' : 'get';

expectExactlyNMatching(spans, expectedSpanCount, [
span => expect(span.t).to.equal(entrySpan.t),
Expand All @@ -828,7 +829,7 @@ setupTypesToRun.forEach(setupType => {
// The "Isolation Pool" was introduced via RedisClientPool in v5.
// This new pool type requires a different connection mechanism.
// As a result, this test is being skipped.
if (redisVersion !== 'latest') {
if (!versionsSinceV5.includes(redisVersion)) {
it('blocking', () => testBlockingCommand(controls, setupType));
}
}
Expand Down
16 changes: 7 additions & 9 deletions packages/core/src/tracing/instrumentation/databases/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,17 @@ function instrument(redis) {
};
};

const creatPoolWrap = originalCreatePool => {
const createPoolWrap = originalCreatePool => {
return function instrumentedCreateRedisPool(poolOptions) {
const redisPoolInstance = originalCreatePool.apply(this, arguments);
const redisUrl = poolOptions?.url;
const redisPoolPrototype = Object.getPrototypeOf(redisPoolInstance);

shimAllCommands(redisPoolPrototype, redisUrl, false, redisCommandList);
shimAllCommands(redisPoolInstance, redisUrl, false, redisCommandList);

if (typeof redisPoolPrototype.multi === 'function') {
shimmer.wrap(redisPoolPrototype, 'multi', wrapMulti(redisUrl, false));
if (typeof redisPoolInstance.multi === 'function') {
shimmer.wrap(redisPoolInstance, 'multi', wrapMulti(redisUrl, false));
}

return redisPoolPrototype;
return redisPoolInstance;
};
};

Expand Down Expand Up @@ -191,11 +189,11 @@ function instrument(redis) {
configurable: true,
enumerable: true,
get() {
return creatPoolWrap(poolDescriptor.get.call(this));
return createPoolWrap(poolDescriptor.get.call(this));
}
});
} else {
shimmer.wrap(redis, 'createClientPool', creatPoolWrap);
shimmer.wrap(redis, 'createClientPool', createPoolWrap);
}
}
};
Expand Down