aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorkontrollanten <6680299+kontrollanten@users.noreply.github.com>2023-05-10 09:52:50 +0200
committerGitHub <noreply@github.com>2023-05-10 09:52:50 +0200
commit674f8ddd415ff4faf100ff35cf2511f84f60fea9 (patch)
treeab4f8b6b42172f5cdafc87c50b6202ea547429ae
parent5170f492b95dc81b75230312411c5fdb0019eed2 (diff)
downloadPeerTube-674f8ddd415ff4faf100ff35cf2511f84f60fea9.tar.gz
PeerTube-674f8ddd415ff4faf100ff35cf2511f84f60fea9.tar.zst
PeerTube-674f8ddd415ff4faf100ff35cf2511f84f60fea9.zip
feat(server): add redis sentinel support (#5593)
* feat(server): add redis sentinel support closes #5141 * Styling --------- Co-authored-by: Chocobozzz <me@florianbigard.com>
-rw-r--r--config/default.yaml9
-rw-r--r--config/production.yaml.example9
-rw-r--r--server/initializers/checker-before-init.ts3
-rw-r--r--server/initializers/config.ts8
-rw-r--r--server/lib/redis.ts24
5 files changed, 45 insertions, 8 deletions
diff --git a/config/default.yaml b/config/default.yaml
index 14bb8d060..5d0eab4f5 100644
--- a/config/default.yaml
+++ b/config/default.yaml
@@ -65,8 +65,15 @@ database:
65redis: 65redis:
66 hostname: 'localhost' 66 hostname: 'localhost'
67 port: 6379 67 port: 6379
68 auth: null 68 auth: null # Used by both standalone and sentinel
69 db: 0 69 db: 0
70 sentinel:
71 enabled: false
72 enable_tls: false
73 master_name: ''
74 sentinels:
75 - hostname: ''
76 port: 26379
70 77
71# SMTP server to send emails 78# SMTP server to send emails
72smtp: 79smtp:
diff --git a/config/production.yaml.example b/config/production.yaml.example
index db9c18cb8..5514f1af6 100644
--- a/config/production.yaml.example
+++ b/config/production.yaml.example
@@ -63,8 +63,15 @@ database:
63redis: 63redis:
64 hostname: 'localhost' 64 hostname: 'localhost'
65 port: 6379 65 port: 6379
66 auth: null 66 auth: null # Used by both standalone and sentinel
67 db: 0 67 db: 0
68 sentinel:
69 enabled: false
70 enable_tls: false
71 master_name: ''
72 sentinels:
73 - hostname: ''
74 port: 26379
68 75
69# SMTP server to send emails 76# SMTP server to send emails
70smtp: 77smtp:
diff --git a/server/initializers/checker-before-init.ts b/server/initializers/checker-before-init.ts
index 2f5a274e4..0a315ea70 100644
--- a/server/initializers/checker-before-init.ts
+++ b/server/initializers/checker-before-init.ts
@@ -84,7 +84,8 @@ function checkMissedConfig () {
84 const requiredAlternatives = [ 84 const requiredAlternatives = [
85 [ // set 85 [ // set
86 [ 'redis.hostname', 'redis.port' ], // alternative 86 [ 'redis.hostname', 'redis.port' ], // alternative
87 [ 'redis.socket' ] 87 [ 'redis.socket' ],
88 [ 'redis.sentinel.master_name', 'redis.sentinel.sentinels[0].hostname', 'redis.sentinel.sentinels[0].port' ]
88 ] 89 ]
89 ] 90 ]
90 const miss: string[] = [] 91 const miss: string[] = []
diff --git a/server/initializers/config.ts b/server/initializers/config.ts
index 9c2705689..51ac5d0ce 100644
--- a/server/initializers/config.ts
+++ b/server/initializers/config.ts
@@ -39,7 +39,13 @@ const CONFIG = {
39 PORT: config.has('redis.port') ? config.get<number>('redis.port') : null, 39 PORT: config.has('redis.port') ? config.get<number>('redis.port') : null,
40 SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null, 40 SOCKET: config.has('redis.socket') ? config.get<string>('redis.socket') : null,
41 AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null, 41 AUTH: config.has('redis.auth') ? config.get<string>('redis.auth') : null,
42 DB: config.has('redis.db') ? config.get<number>('redis.db') : null 42 DB: config.has('redis.db') ? config.get<number>('redis.db') : null,
43 SENTINEL: {
44 ENABLED: config.has('redis.sentinel.enabled') ? config.get<boolean>('redis.sentinel.enabled') : false,
45 ENABLE_TLS: config.has('redis.sentinel.enable_tls') ? config.get<boolean>('redis.sentinel.enable_tls') : false,
46 SENTINELS: config.has('redis.sentinel.sentinels') ? config.get<{ hostname: string, port: number }[]>('redis.sentinel.sentinels') : [],
47 MASTER_NAME: config.has('redis.sentinel.master_name') ? config.get<string>('redis.sentinel.master_name') : null
48 }
43 }, 49 },
44 SMTP: { 50 SMTP: {
45 TRANSPORT: config.has('smtp.transport') ? config.get<string>('smtp.transport') : 'smtp', 51 TRANSPORT: config.has('smtp.transport') ? config.get<string>('smtp.transport') : 'smtp',
diff --git a/server/lib/redis.ts b/server/lib/redis.ts
index 3706d2228..8430b2227 100644
--- a/server/lib/redis.ts
+++ b/server/lib/redis.ts
@@ -32,7 +32,8 @@ class Redis {
32 if (this.initialized === true) return 32 if (this.initialized === true) return
33 this.initialized = true 33 this.initialized = true
34 34
35 logger.info('Connecting to redis...') 35 const redisMode = CONFIG.REDIS.SENTINEL.ENABLED ? 'sentinel' : 'standalone'
36 logger.info('Connecting to redis ' + redisMode + '...')
36 37
37 this.client = new IoRedis(Redis.getRedisClientOptions('', { enableAutoPipelining: true })) 38 this.client = new IoRedis(Redis.getRedisClientOptions('', { enableAutoPipelining: true }))
38 this.client.on('error', err => logger.error('Redis failed to connect', { err })) 39 this.client.on('error', err => logger.error('Redis failed to connect', { err }))
@@ -56,10 +57,25 @@ class Redis {
56 this.prefix = 'redis-' + WEBSERVER.HOST + '-' 57 this.prefix = 'redis-' + WEBSERVER.HOST + '-'
57 } 58 }
58 59
59 static getRedisClientOptions (connectionName?: string, options: RedisOptions = {}): RedisOptions { 60 static getRedisClientOptions (name?: string, options: RedisOptions = {}): RedisOptions {
61 const connectionName = [ 'PeerTube', name ].join('')
62 const connectTimeout = 20000 // Could be slow since node use sync call to compile PeerTube
63
64 if (CONFIG.REDIS.SENTINEL.ENABLED) {
65 return {
66 connectionName,
67 connectTimeout,
68 enableTLSForSentinelMode: CONFIG.REDIS.SENTINEL.ENABLE_TLS,
69 sentinelPassword: CONFIG.REDIS.AUTH,
70 sentinels: CONFIG.REDIS.SENTINEL.SENTINELS,
71 name: CONFIG.REDIS.SENTINEL.MASTER_NAME,
72 ...options
73 }
74 }
75
60 return { 76 return {
61 connectionName: [ 'PeerTube', connectionName ].join(''), 77 connectionName,
62 connectTimeout: 20000, // Could be slow since node use sync call to compile PeerTube 78 connectTimeout,
63 password: CONFIG.REDIS.AUTH, 79 password: CONFIG.REDIS.AUTH,
64 db: CONFIG.REDIS.DB, 80 db: CONFIG.REDIS.DB,
65 host: CONFIG.REDIS.HOSTNAME, 81 host: CONFIG.REDIS.HOSTNAME,