ESLint fixes

This commit is contained in:
Stephen Papierski 2023-11-09 13:15:32 -07:00
parent d3709802c5
commit 9dd577dc98
No known key found for this signature in database
3 changed files with 21 additions and 19 deletions

View file

@ -13,7 +13,7 @@ exports.up = function (knex) {
.alterTable("heartbeat", function (table) { .alterTable("heartbeat", function (table) {
table.integer("slow_response_count").notNullable().defaultTo(0); table.integer("slow_response_count").notNullable().defaultTo(0);
}); });
} };
exports.down = function (knex) { exports.down = function (knex) {
// remove various slow_response_notification parameters // remove various slow_response_notification parameters
@ -30,4 +30,4 @@ exports.down = function (knex) {
.alterTable("heartbeat", function (table) { .alterTable("heartbeat", function (table) {
table.dropColumn("slow_response_count"); table.dropColumn("slow_response_count");
}); });
} };

View file

@ -307,7 +307,7 @@ class Monitor extends BeanModel {
/** /**
* Is the slow response notification enabled? * Is the slow response notification enabled?
* @returns {boolean} * @returns {boolean} Slow response notification is enabled?
*/ */
isEnabledSlowResponseNotification() { isEnabledSlowResponseNotification() {
return Boolean(this.slowResponseNotification); return Boolean(this.slowResponseNotification);
@ -1444,7 +1444,7 @@ class Monitor extends BeanModel {
let actualResponseTime = 0; let actualResponseTime = 0;
let previousBeats; let previousBeats;
if (method != "last") { if (method !== "last") {
//Get recent heartbeat list with range of time //Get recent heartbeat list with range of time
const afterThisDate = new Date(Date.now() - (1000 * (monitor.slowResponseNotificationRange + 1))); // add 1 second otherwise we grab 0 previous beats when Time Range == Heartbeat Interval const afterThisDate = new Date(Date.now() - (1000 * (monitor.slowResponseNotificationRange + 1))); // add 1 second otherwise we grab 0 previous beats when Time Range == Heartbeat Interval
previousBeats = await R.getAll(` previousBeats = await R.getAll(`
@ -1482,6 +1482,8 @@ class Monitor extends BeanModel {
let threshold; let threshold;
let thresholdDescription; let thresholdDescription;
let afterThisDate;
let avgPing;
switch (thresholdMethod) { switch (thresholdMethod) {
case "threshold-static": case "threshold-static":
threshold = monitor.slowResponseNotificationThreshold; threshold = monitor.slowResponseNotificationThreshold;
@ -1490,8 +1492,8 @@ class Monitor extends BeanModel {
case "threshold-relative-24-hour": case "threshold-relative-24-hour":
//Get average response time over last 24 hours //Get average response time over last 24 hours
const afterThisDate = new Date(Date.now() - (1000 * (24 * 60 * 60))); // 24 hours in milliseconds afterThisDate = new Date(Date.now() - (1000 * (24 * 60 * 60))); // 24 hours in milliseconds
const avgPing = parseInt(await R.getCell(` avgPing = parseInt(await R.getCell(`
SELECT AVG(ping) FROM heartbeat SELECT AVG(ping) FROM heartbeat
WHERE time > datetime(?) WHERE time > datetime(?)
AND ping IS NOT NULL AND ping IS NOT NULL
@ -1512,11 +1514,11 @@ class Monitor extends BeanModel {
// Create stats to append to messages/logs // Create stats to append to messages/logs
const methodDescription = [ "average", "max" ].includes(method) ? `${method} of ${windowDuration}s` : method; const methodDescription = [ "average", "max" ].includes(method) ? `${method} of ${windowDuration}s` : method;
let msgStats = `Response: ${actualResponseTime}ms (${methodDescription}) | Threshold: ${threshold}ms (${thresholdDescription})` let msgStats = `Response: ${actualResponseTime}ms (${methodDescription}) | Threshold: ${threshold}ms (${thresholdDescription})`;
// Add window duration for methods that make sense // Add window duration for methods that make sense
// Verify valid response time was calculated // Verify valid response time was calculated
if (actualResponseTime == 0 || !Number.isInteger(actualResponseTime)) { if (actualResponseTime === 0 || !Number.isInteger(actualResponseTime)) {
log.debug("monitor", `[${this.name}] Failed to calculate valid response time`); log.debug("monitor", `[${this.name}] Failed to calculate valid response time`);
return; return;
} }
@ -1529,7 +1531,7 @@ class Monitor extends BeanModel {
// Responding normally // Responding normally
if (actualResponseTime < threshold) { if (actualResponseTime < threshold) {
if (bean.slowResponseCount == 0) { if (bean.slowResponseCount === 0) {
log.debug("monitor", `[${this.name}] Responding normally. No need to send slow response notification | ${msgStats}`); log.debug("monitor", `[${this.name}] Responding normally. No need to send slow response notification | ${msgStats}`);
} else { } else {
msgStats += ` | Slow for: ${bean.slowResponseCount * monitor.interval}s`; msgStats += ` | Slow for: ${bean.slowResponseCount * monitor.interval}s`;
@ -1546,13 +1548,13 @@ class Monitor extends BeanModel {
++bean.slowResponseCount; ++bean.slowResponseCount;
// Always send first notification // Always send first notification
if (bean.slowResponseCount == 1) { if (bean.slowResponseCount === 1) {
log.debug("monitor", `[${this.name}] Responded slowly, sending notification | ${msgStats}`); log.debug("monitor", `[${this.name}] Responded slowly, sending notification | ${msgStats}`);
let msg = `[${this.name}] Responded Slowly \n${msgStats}`; let msg = `[${this.name}] Responded Slowly \n${msgStats}`;
Monitor.sendSlowResponseNotification(monitor, bean, msg); Monitor.sendSlowResponseNotification(monitor, bean, msg);
// Send notification every x times // Send notification every x times
} else if (this.slowResponseNotificationResendInterval > 0) { } else if (this.slowResponseNotificationResendInterval > 0) {
if (((bean.slowResponseCount) % this.slowResponseNotificationResendInterval) == 0) { if (((bean.slowResponseCount) % this.slowResponseNotificationResendInterval) === 0) {
// Send notification again, because we are still responding slow // Send notification again, because we are still responding slow
msgStats += ` | Slow for: ${bean.slowResponseCount * monitor.interval}s`; msgStats += ` | Slow for: ${bean.slowResponseCount * monitor.interval}s`;
log.debug("monitor", `[${this.name}] Still responding slowly, sendSlowResponseNotification again | ${msgStats}`); log.debug("monitor", `[${this.name}] Still responding slowly, sendSlowResponseNotification again | ${msgStats}`);