-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Refactor Redis connections to use Redis URL - closes #7421 #7736
Changes from 3 commits
158ab70
4d15012
0ec9d12
655265c
2ed4704
9112b6c
68c8612
551f789
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,8 +25,7 @@ services: | |
PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default | ||
SERVER_URL: ${SERVER_URL} | ||
FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL} | ||
REDIS_PORT: ${REDIS_PORT:-6379} | ||
REDIS_HOST: ${REDIS_HOST:-redis} | ||
REDIS_URL: ${REDIS_URL:-redis://localhost:6379} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using the redis service name instead of localhost in the default URL |
||
|
||
ENABLE_DB_MIGRATIONS: "true" | ||
|
||
|
@@ -59,8 +58,7 @@ services: | |
PG_DATABASE_URL: postgres://twenty:twenty@${PG_DATABASE_HOST}/default | ||
SERVER_URL: ${SERVER_URL} | ||
FRONT_BASE_URL: ${FRONT_BASE_URL:-$SERVER_URL} | ||
REDIS_PORT: ${REDIS_PORT:-6379} | ||
REDIS_HOST: ${REDIS_HOST:-redis} | ||
REDIS_URL: ${REDIS_URL:-redis://localhost:6379} | ||
|
||
ENABLE_DB_MIGRATIONS: "false" # it already runs on the server | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,12 +61,8 @@ resource "kubernetes_deployment" "twentycrm_server" { | |
value = "postgres://twenty:${var.twentycrm_pgdb_admin_password}@${kubernetes_service.twentycrm_db.metadata.0.name}.${kubernetes_namespace.twentycrm.metadata.0.name}.svc.cluster.local/default" | ||
} | ||
env { | ||
name = "REDIS_HOST" | ||
value = "${kubernetes_service.twentycrm_redis.metadata.0.name}.${kubernetes_namespace.twentycrm.metadata.0.name}.svc.cluster.local" | ||
} | ||
env { | ||
name = "REDIS_PORT" | ||
value = 6379 | ||
name = "REDIS_URL" | ||
value = "redis://${kubernetes_service.twentycrm_redis.metadata.0.name}.${kubernetes_namespace.twentycrm.metadata.0.name}.svc.cluster.local:6379" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The Redis URL format doesn't include authentication. If Redis requires auth, update the URL to include username and password |
||
} | ||
env { | ||
name = "ENABLE_DB_MIGRATIONS" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,13 +59,8 @@ resource "kubernetes_deployment" "twentycrm_worker" { | |
} | ||
|
||
env { | ||
name = "REDIS_HOST" | ||
value = "${kubernetes_service.twentycrm_redis.metadata.0.name}.${kubernetes_namespace.twentycrm.metadata.0.name}.svc.cluster.local" | ||
} | ||
|
||
env { | ||
name = "REDIS_PORT" | ||
value = 6379 | ||
name = "REDIS_URL" | ||
value = "redis://${kubernetes_service.twentycrm_redis.metadata.0.name}.${kubernetes_namespace.twentycrm.metadata.0.name}.svc.cluster.local:6379" | ||
Comment on lines
+62
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using a separate variable for the Redis URL instead of constructing it inline. This would improve maintainability and allow for easier configuration changes. |
||
} | ||
|
||
env { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,26 +20,19 @@ export const cacheStorageModuleFactory = ( | |
return cacheModuleOptions; | ||
} | ||
case CacheStorageType.Redis: { | ||
const host = environmentService.get('REDIS_HOST'); | ||
const port = environmentService.get('REDIS_PORT'); | ||
const connectionString = environmentService.get('REDIS_URL'); | ||
|
||
if (!(host && port)) { | ||
if (!connectionString) { | ||
throw new Error( | ||
`${cacheStorageType} cache storage requires host: ${host} and port: ${port} to be defined, check your .env file`, | ||
`${cacheStorageType} cache storage requires ${connectionString} to be defined, check your .env file`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Error message uses connectionString variable, which could be undefined. Use 'REDIS_URL' string instead
thomasmol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
|
||
const username = environmentService.get('REDIS_USERNAME'); | ||
const password = environmentService.get('REDIS_PASSWORD'); | ||
|
||
return { | ||
...cacheModuleOptions, | ||
store: redisStore, | ||
socket: { | ||
host, | ||
port, | ||
username, | ||
password, | ||
connectionString, | ||
}, | ||
}; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
MessageQueueDriverType, | ||
MessageQueueModuleOptions, | ||
} from 'src/engine/core-modules/message-queue/interfaces'; | ||
import IORedis from 'ioredis'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider adding a comment explaining why IORedis is being imported and used |
||
|
||
/** | ||
* MessageQueue Module factory | ||
|
@@ -32,20 +33,12 @@ export const messageQueueModuleFactory = async ( | |
}; | ||
} | ||
case MessageQueueDriverType.BullMQ: { | ||
const host = environmentService.get('REDIS_HOST'); | ||
const port = environmentService.get('REDIS_PORT'); | ||
const username = environmentService.get('REDIS_USERNAME'); | ||
const password = environmentService.get('REDIS_PASSWORD'); | ||
const connectionString = environmentService.get('REDIS_URL'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Validate REDIS_URL before using it to prevent potential runtime errors |
||
|
||
return { | ||
type: MessageQueueDriverType.BullMQ, | ||
options: { | ||
connection: { | ||
host, | ||
port, | ||
username, | ||
password, | ||
}, | ||
connection: new IORedis(connectionString) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this seems wrong actually, we should not instanciate here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true, i changed it to just pass the connection string here. It works but there is a type error. Unsure why that is since passing a string should be OK as per: https://redis.github.io/ioredis/classes/Redis.html#constructor |
||
}, | ||
}; | ||
} | ||
|
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.
style: Add a comment explaining the REDIS_URL format for clarity