From 97301239aa1db2c4cd04b3dcac2cdf6b69598681 Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Tue, 12 Dec 2023 13:20:49 +0200 Subject: [PATCH] fix(redis): Fixed Redis stats collections when using Upstash Redis --- lib/tools.js | 34 ++++++++++++++++++++++++++++++---- server.js | 4 +++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/tools.js b/lib/tools.js index eb934a7b..fe913128 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -1107,9 +1107,13 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg }); infoObj.cmdstat_total = cmdstat_total; - - let slowlogLen = await redis.slowlog('len'); - infoObj.slowlog_length = formatValue(slowlogLen); + try { + let slowlogLen = await redis.slowlog('len'); + infoObj.slowlog_length = formatValue(slowlogLen); + } catch (err) { + // not supported by Upstash + infoObj.slowlog_length = 0; + } return infoObj; }, @@ -1120,13 +1124,35 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg let counters = await module.exports.getCounterValues(redis, seconds); let redisVersion; + let softwareDetails; try { let redisInfo = await module.exports.getRedisStats(redis); if (!redisInfo || typeof redisInfo.redis_version !== 'string') { throw new Error('Failed to fetch Redis INFO'); } redisVersion = redisInfo.redis_version; + + // Detect Dragonfly + if (typeof redisInfo.dragonfly_version === 'string') { + softwareDetails = `Dragonfly v${redisInfo.dragonfly_version.replace(/^[^\d]*/, '')}`; + } + + // Detect KeyDB + if (typeof redisInfo.mvcc_depth === 'number') { + softwareDetails = `KeyDB`; + } + + // Detect Upstash + if (typeof redisInfo.upstash_version === 'string') { + softwareDetails = `Upstash Redis v${redisInfo.upstash_version.replace(/^[^\d]*/, '')}`; + } + + // Detect Memurai + if (typeof redisInfo.memurai_version === 'string') { + softwareDetails = `${redisInfo.memurai_edition || 'Memurai'} v${redisInfo.memurai_version.replace(/^[^\d]*/, '')}`; + } } catch (err) { + console.log(err); // ignore redisVersion = err.message; } @@ -1166,7 +1192,7 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEV3QUiYsp13nD9suD1/ZkEXnuMoSg license: packageData.license, accounts: await redis.scard(`${REDIS_PREFIX}ia:accounts`), node: process.versions.node, - redis: redisVersion, + redis: `${redisVersion}${softwareDetails ? ` (${softwareDetails})` : ''}`, imapflow: ImapFlow.version || 'please upgrade', bullmq: bullmqPackage.version, arch: process.arch, diff --git a/server.js b/server.js index 93a96d32..b7f94a39 100644 --- a/server.js +++ b/server.js @@ -1324,7 +1324,9 @@ async function updateQueueCounters() { try { let redisInfo = await getRedisStats(redis); - metrics.redisVersion.set({ version: 'v' + redisInfo.redis_version }, 1); + if (redisInfo.redis_version) { + metrics.redisVersion.set({ version: 'v' + redisInfo.redis_version }, 1); + } metrics.redisUptimeInSeconds.set(Number(redisInfo.uptime_in_seconds) || 0);