Skip to content

Commit

Permalink
fix(redis-latency): show latency for Redis commands in the dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Nov 29, 2023
1 parent aba2dab commit 65fa362
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 69 deletions.
2 changes: 1 addition & 1 deletion data/google-crawlers.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"creationTime": "2023-11-21T23:00:59.000000",
"creationTime": "2023-11-28T23:00:37.000000",
"prefixes": [
{
"ipv6Prefix": "2001:4860:4801:2008::/64"
Expand Down
2 changes: 1 addition & 1 deletion lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2847,7 +2847,7 @@ class Connection {
let jobData = Object.assign({}, meta || {}, {
account: this.account,
queueId,
gateway: gatewayData && gatewayData.gateway,
gateway: (gatewayData && gatewayData.gateway) || null,
messageId,
envelope,
subject,
Expand Down
4 changes: 2 additions & 2 deletions lib/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ module.exports = {

NONCE_BYTES: 16,

// milliseconds
ALLOWED_REDIS_LATENCY: 15,
// nanoseconds
ALLOWED_REDIS_LATENCY: 5 * 1000000,

generateWebhookTable() {
let entries = [];
Expand Down
4 changes: 2 additions & 2 deletions lib/routes-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ function applyRoutes(server, call) {
title: 'Redis Latency',
color: typeof stats.redisPing !== 'number' ? 'warning' : stats.redisPing < ALLOWED_REDIS_LATENCY ? 'success' : 'danger',
icon: 'clock',
comment: 'How many milliseconds does it take to run Redis commands',
value: typeof stats.redisPing !== 'number' ? '\u2013' : humanize.numberFormat(stats.redisPing || 0, 0, '.', ' ')
comment: 'How many milliseconds does it take to run a Redis command',
value: typeof stats.redisPing !== 'number' ? '\u2013' : humanize.numberFormat(stats.redisPing / 1000000, 3, '.', ' ')
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"ace-builds": "1.31.2",
"base32.js": "0.1.0",
"bull-arena": "4.1.0",
"bullmq": "4.14.2",
"bullmq": "4.14.4",
"compare-versions": "6.1.0",
"dotenv": "16.3.1",
"encoding-japanese": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion sbom.json

Large diffs are not rendered by default.

49 changes: 34 additions & 15 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ const metrics = {

redisPing: new promClient.Gauge({
name: 'redis_latency',
help: 'Redis latency in milliseconds'
help: 'Redis latency in nanoseconds'
}),

redisRejectedConnectionsTotal: new promClient.Gauge({
Expand Down Expand Up @@ -1222,19 +1222,22 @@ function checkUpgrade() {
let redisPingCounter = [];

function getRedisPing() {
if (redisPingCounter.length < 14) {
if (!redisPingCounter.length) {
return null;
}
let entries = redisPingCounter

let entries = []
.concat(redisPingCounter)
.slice(-34)
.map(entry => entry[1])
.sort((a, b) => a - b);

// remove 2 highest and lowest
entries.shift();
entries.shift();
entries.pop();
entries.pop();
// remove 2 highest and lowest if possible
for (let i = 0; i < 2; i++) {
if (entries.length > 4) {
entries.shift();
entries.pop();
}
}

let sum = 0;
for (let entry of entries) {
Expand All @@ -1246,13 +1249,29 @@ function getRedisPing() {

const REDIS_PING_TIMEOUT = 10 * 1000;
let redisPingTimer = false;
const processRedisPing = async () => {

const getCurrentRedisPing = async () => {
try {
let startTime = Date.now();
// this request is not timed, it is to ensure that there is an open connection
await redis.ping();
let endTime = Date.now();
let duration = endTime - startTime;
redisPingCounter.push([endTime, duration]);

let startTime = process.hrtime.bigint();
await redis.ping();
let endTime = process.hrtime.bigint();

let duration = Number(endTime - startTime);

return duration;
} catch (err) {
logger.error({ msg: 'Failed to run Redis ping', err });
}
return 0;
};

const processRedisPing = async () => {
try {
let duration = await getCurrentRedisPing();
redisPingCounter.push(duration);
if (redisPingCounter.length > 300) {
redisPingCounter = redisPingCounter.slice(0, 150);
}
Expand Down Expand Up @@ -1309,7 +1328,7 @@ async function updateQueueCounters() {

metrics.redisUptimeInSeconds.set(Number(redisInfo.uptime_in_seconds) || 0);

metrics.redisPing.set((await processRedisPing()) || 0);
metrics.redisPing.set((await getCurrentRedisPing()) || 0);

metrics.redisRejectedConnectionsTotal.set(Number(redisInfo.rejected_connections) || 0);
metrics.redisConfigMaxclients.set(Number(redisInfo.maxclients) || 0);
Expand Down
4 changes: 2 additions & 2 deletions static/licenses.html
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ <h1>EmailEngine v2.39.1</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/bullmq">bullmq</a></td>
<td>4.14.2</td>
<td>4.14.4</td>
<td>MIT</td>
<td>Taskforce.sh Inc.</td>
<td></td>
Expand Down Expand Up @@ -5385,7 +5385,7 @@ <h1>EmailEngine v2.39.1</h1><p>EmailEngine includes code from the following soft
</tr>
<tr>
<td><a href="https://npmjs.com/package/msgpackr">msgpackr</a></td>
<td>1.9.9</td>
<td>1.10.0</td>
<td>MIT</td>
<td>Kris Zyp</td>
<td></td>
Expand Down
88 changes: 44 additions & 44 deletions translations/messages.pot
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=ascii\n"
"POT-Creation-Date: 2023-11-27 14:28+0000\n"
"POT-Creation-Date: 2023-11-29 09:09+0000\n"

#: views/config/license.hbs:48
msgid "%d day"
msgid_plural "%d days"
msgstr[0] ""
msgstr[1] ""

#: views/redirect.hbs:1
msgid "Click <a href=\"%s\">here</a> to continue&mldr;"
msgstr ""

#: views/unsubscribe.hbs:1
#: views/unsubscribe.hbs:79
msgid "Unsubscribe"
Expand Down Expand Up @@ -53,33 +57,6 @@ msgstr ""
msgid "Enter your email address"
msgstr ""

#: views/redirect.hbs:1
msgid "Click <a href=\"%s\">here</a> to continue&mldr;"
msgstr ""

#: views/accounts/register/imap.hbs:11
msgid "Your name"
msgstr ""

#: views/accounts/register/imap.hbs:17
msgid "Enter your full name"
msgstr ""

#: views/accounts/register/imap.hbs:31
#: views/accounts/register/imap-server.hbs:35
#: views/accounts/register/imap-server.hbs:114
msgid "Password"
msgstr ""

#: views/accounts/register/imap.hbs:37
msgid "Enter your account password"
msgstr ""

#: views/accounts/register/imap.hbs:51
#: views/accounts/register/imap-server.hbs:192
msgid "Continue"
msgstr ""

#: views/accounts/register/imap-server.hbs:18
msgid "IMAP"
msgstr ""
Expand All @@ -89,6 +66,12 @@ msgstr ""
msgid "Username"
msgstr ""

#: views/accounts/register/imap-server.hbs:35
#: views/accounts/register/imap-server.hbs:114
#: views/accounts/register/imap.hbs:31
msgid "Password"
msgstr ""

#: views/accounts/register/imap-server.hbs:41
#: views/accounts/register/imap-server.hbs:46
#: views/accounts/register/imap-server.hbs:120
Expand Down Expand Up @@ -149,6 +132,11 @@ msgstr ""
msgid "Test settings"
msgstr ""

#: views/accounts/register/imap-server.hbs:192
#: views/accounts/register/imap.hbs:51
msgid "Continue"
msgstr ""

#: views/accounts/register/imap-server.hbs:200
msgid "Continue without testing"
msgstr ""
Expand Down Expand Up @@ -181,6 +169,18 @@ msgstr ""
msgid "HTTP error!"
msgstr ""

#: views/accounts/register/imap.hbs:11
msgid "Your name"
msgstr ""

#: views/accounts/register/imap.hbs:17
msgid "Enter your full name"
msgstr ""

#: views/accounts/register/imap.hbs:37
msgid "Enter your account password"
msgstr ""

#: views/accounts/register/index.hbs:2
msgid "Choose your email account provider"
msgstr ""
Expand All @@ -189,40 +189,40 @@ msgstr ""
msgid "Standard IMAP"
msgstr ""

#: lib/routes-ui.js:600
#: lib/routes-ui.js:601
msgid "Invalid API key for OpenAI"
msgstr ""

#: lib/routes-ui.js:4612
#: lib/routes-ui.js:6534
#: lib/routes-ui.js:6545
#: lib/routes-ui.js:4621
#: lib/routes-ui.js:6543
#: lib/routes-ui.js:6554
msgid "Server hostname was not found"
msgstr ""

#: lib/routes-ui.js:4615
#: lib/routes-ui.js:6537
#: lib/routes-ui.js:6548
#: lib/routes-ui.js:4624
#: lib/routes-ui.js:6546
#: lib/routes-ui.js:6557
msgid "Invalid username or password"
msgstr ""

#: lib/routes-ui.js:4619
#: lib/routes-ui.js:6552
#: lib/routes-ui.js:4628
#: lib/routes-ui.js:6561
msgid "TLS protocol error"
msgstr ""

#: lib/routes-ui.js:6346
#: lib/routes-ui.js:6386
#: lib/routes-ui.js:9080
#: lib/routes-ui.js:6355
#: lib/routes-ui.js:6395
#: lib/routes-ui.js:9089
msgid "Failed to validate request arguments"
msgstr ""

#: lib/routes-ui.js:6472
#: lib/routes-ui.js:6726
#: lib/routes-ui.js:6481
#: lib/routes-ui.js:6735
msgid "Failed to process account"
msgstr ""

#: lib/routes-ui.js:9180
#: lib/routes-ui.js:9213
#: lib/routes-ui.js:9189
#: lib/routes-ui.js:9222
msgid "Failed to process request"
msgstr ""

Expand Down

0 comments on commit 65fa362

Please sign in to comment.