-
Notifications
You must be signed in to change notification settings - Fork 37
feat: added support for ioredis cluster #1292
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
51 changes: 51 additions & 0 deletions
51
packages/collector/test/tracing/database/ioredis/connect-via/cluster.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2024 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// NOTE: We run the tests locally and on CI against azure redis cluster. | ||
// NOTE: We cannot run redis cluster on Tekton https://github.com/bitnami/charts/issues/28894 | ||
// NOTE: We cannot use a docker based redis cluster at the moment! | ||
// See https://github.com/redis/node-redis/issues/2815. | ||
// These commands are useful as soon as we switch to a docker based cluster. | ||
// node bin/start-test-containers.js --redis-node-0 --redis-node-1 --redis-node-2 | ||
// docker exec -it 2aaaac7b9112 redis-cli -p 6379 cluster info | ||
module.exports = async function connect(ioredis, log) { | ||
if (!process.env.AZURE_REDIS_CLUSTER || !process.env.AZURE_REDIS_CLUSTER_PWD) { | ||
log( | ||
'Please set the environment variables AZURE_REDIS_CLUSTER and AZURE_REDIS_CLUSTER_PWD ' + | ||
'to connect to the cloud redis cluster.' | ||
); | ||
|
||
process.exit(1); | ||
} | ||
|
||
const hostAndPort = process.env.AZURE_REDIS_CLUSTER.split(':'); | ||
const cluster = new ioredis.Cluster( | ||
[ | ||
{ | ||
host: hostAndPort[0], | ||
port: hostAndPort[1] | ||
} | ||
], | ||
{ | ||
redisOptions: { | ||
tls: true, | ||
password: process.env.AZURE_REDIS_CLUSTER_PWD, | ||
connectTimeout: 10000 | ||
}, | ||
retryDelayOnFailover: 1000, | ||
maxRetriesPerRequest: 10 | ||
} | ||
); | ||
|
||
log(`Connecting to cluster host: ${hostAndPort[0]}, port: ${hostAndPort[1]}.`); | ||
|
||
return new Promise(resolve => { | ||
cluster.on('ready', () => { | ||
log('Connected to cluster.'); | ||
resolve({ connection: cluster }); | ||
}); | ||
}); | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/collector/test/tracing/database/ioredis/connect-via/default.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2024 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = async function (ioredis, log) { | ||
const client = new ioredis(`//${process.env.REDIS}`); | ||
const client2 = new ioredis(`//${process.env.REDIS_ALTERNATIVE}`); | ||
|
||
return new Promise(resolve => { | ||
let clientReady = false; | ||
let client2Ready = false; | ||
|
||
client.on('ready', () => { | ||
clientReady = true; | ||
log(`Connected to client 1 (${process.env.REDIS}).`); | ||
|
||
if (client2Ready) { | ||
resolve({ | ||
connection: client, | ||
connection2: client2 | ||
}); | ||
} | ||
}); | ||
|
||
client2.on('ready', () => { | ||
client2Ready = true; | ||
log(`Connected to client 2 (${process.env.REDIS_ALTERNATIVE}).`); | ||
|
||
if (clientReady) { | ||
resolve({ | ||
connection: client, | ||
connection2: client2 | ||
}); | ||
} | ||
}); | ||
}); | ||
}; |
13 changes: 13 additions & 0 deletions
13
packages/collector/test/tracing/database/ioredis/connect-via/index.js
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* (c) Copyright IBM Corp. 2024 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = function (redis, log) { | ||
if (process.env.REDIS_CLUSTER === 'true') { | ||
return require('./cluster')(redis, log); | ||
} | ||
|
||
return require('./default')(redis, log); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While running the tests locally, I initially encountered the following issue:
The issue seems to have resolved itself after some time. It might be related to the cluster since we use the same cluster for both Redis and ioredis testing. Running tests in parallel could potentially cause conflicts. We should consider alternative solutions, such as using namespaces, to prevent this issue in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: We can create a card for now and do it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://jsw.ibm.com/browse/INSTA-14042