Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Improve redis logging

Chocobozzz8745c915d5b0
diff --git a/server/core/lib/redis.ts b/server/core/lib/redis.ts
index 156f20c8de..9092db08d4 100644
--- a/server/core/lib/redis.ts
+++ b/server/core/lib/redis.ts
@@ -1,7 +1,7 @@
-import { Redis as IoRedis, RedisOptions } from 'ioredis'
-import { exists } from '@server/helpers/custom-validators/misc.js'
import { sha256 } from '@peertube/peertube-node-utils'
-import { logger } from '../helpers/logger.js'
+import { exists } from '@server/helpers/custom-validators/misc.js'
+import { Redis as IoRedis, RedisOptions } from 'ioredis'
+import { logger, loggerTagsFactory } from '../helpers/logger.js'
import { generateRandomString } from '../helpers/utils.js'
import { CONFIG } from '../initializers/config.js'
import {
@@ -16,6 +16,8 @@ import {
WEBSERVER
} from '../initializers/constants.js'
+const lTags = loggerTagsFactory('redis')
+
class Redis {
private static instance: Redis
@@ -33,25 +35,25 @@ class Redis {
this.initialized = true
const redisMode = CONFIG.REDIS.SENTINEL.ENABLED ? 'sentinel' : 'standalone'
- logger.info('Connecting to redis ' + redisMode + '...')
+ logger.info(`Connecting to Redis in "${redisMode}" mode...`, lTags())
this.client = new IoRedis(Redis.getRedisClientOptions('', { enableAutoPipelining: true }))
- this.client.on('error', err => logger.error('Redis failed to connect', { err }))
+ this.client.on('error', err => logger.error('Redis failed to connect', { err, ...lTags() }))
this.client.on('connect', () => {
- logger.info('Connected to redis.')
+ logger.info('Connected to redis.', lTags())
this.connected = true
})
this.client.on('reconnecting', (ms) => {
- logger.error(`Reconnecting to redis in ${ms}.`)
+ logger.error(`Reconnecting to redis in ${ms}.`, lTags())
})
this.client.on('close', () => {
- logger.error('Connection to redis has closed.')
+ logger.error('Connection to redis has closed.', lTags())
this.connected = false
})
this.client.on('end', () => {
- logger.error('Connection to redis has closed and no more reconnects will be done.')
+ logger.error('Connection to redis has closed and no more reconnects will be done.', lTags())
})
this.prefix = 'redis-' + WEBSERVER.HOST + '-'
@@ -62,6 +64,11 @@ class Redis {
const connectTimeout = 20000 // Could be slow since node use sync call to compile PeerTube
if (CONFIG.REDIS.SENTINEL.ENABLED) {
+ logger.info(
+ `Using sentinel redis options`,
+ { sentinels: CONFIG.REDIS.SENTINEL.SENTINELS, name: CONFIG.REDIS.SENTINEL.MASTER_NAME, ...lTags() }
+ )
+
return {
connectionName,
connectTimeout,
@@ -73,6 +80,11 @@ class Redis {
}
}
+ logger.info(
+ `Using standalone redis options`,
+ { db: CONFIG.REDIS.DB, host: CONFIG.REDIS.HOSTNAME, port: CONFIG.REDIS.PORT, path: CONFIG.REDIS.SOCKET, ...lTags() }
+ )
+
return {
connectionName,
connectTimeout,
@@ -202,7 +214,7 @@ class Redis {
const valueInt = parseInt(valueString, 10)
if (isNaN(valueInt)) {
- logger.error('Cannot get videos views stats of video %d in hour %d: views number is NaN (%s).', videoId, hour, valueString)
+ logger.error(`Cannot get videos views stats of video ${videoId} in hour ${hour}: views number is NaN (${valueString}).`, lTags())
return undefined
}
@@ -243,7 +255,7 @@ class Redis {
const valueInt = parseInt(valueString, 10)
if (isNaN(valueInt)) {
- logger.error('Cannot get videos views of video %d: views number is NaN (%s).', videoId, valueString)
+ logger.error(`Cannot get videos views of video ${videoId}: views number is NaN (${valueString}).`, lTags())
return undefined
}