Skip to content

Commit

Permalink
fix(redis): Fixed Redis stats collections when using Upstash Redis
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Dec 12, 2023
1 parent 4418a33 commit 9730123
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
34 changes: 30 additions & 4 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand All @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 9730123

Please sign in to comment.