From 51334d8a8c2c7d5ed3b9578c829bca8f9d4aa85a Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Tue, 24 Sep 2024 16:44:01 +0100 Subject: [PATCH] Increase retry attempts to 10 for all monitor types and enhance timeout error handling to provide detailed failure reasons --- Probe/Utils/Monitors/Monitor.ts | 12 ++++++------ Probe/Utils/Monitors/MonitorTypes/ApiMonitor.ts | 6 +++++- Probe/Utils/Monitors/MonitorTypes/PingMonitor.ts | 8 +++++++- Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts | 3 ++- Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts | 8 +++++++- Probe/Utils/Monitors/MonitorTypes/WebsiteMonitor.ts | 8 +++++++- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Probe/Utils/Monitors/Monitor.ts b/Probe/Utils/Monitors/Monitor.ts index 1b5024af8c7..a5bc7a2ecf4 100644 --- a/Probe/Utils/Monitors/Monitor.ts +++ b/Probe/Utils/Monitors/Monitor.ts @@ -150,7 +150,7 @@ export default class MonitorUtil { monitorStep.data?.monitorDestination, new Port(80), // use port 80 by default. { - retry: 5, + retry: 10, monitorId: monitor.id!, timeout: new PositiveNumber(60000), // 60 seconds }, @@ -167,7 +167,7 @@ export default class MonitorUtil { const response: PingResponse | null = await PingMonitor.ping( monitorStep.data?.monitorDestination, { - retry: 5, + retry: 10, monitorId: monitor.id!, timeout: new PositiveNumber(60000), // 60 seconds }, @@ -204,7 +204,7 @@ export default class MonitorUtil { monitorStep.data?.monitorDestination, monitorStep.data.monitorDestinationPort, { - retry: 5, + retry: 10, monitorId: monitor.id!, timeout: new PositiveNumber(60000), // 60 seconds }, @@ -280,7 +280,7 @@ export default class MonitorUtil { const response: SslResponse | null = await SSLMonitor.ping( monitorStep.data?.monitorDestination as URL, { - retry: 5, + retry: 10, monitorId: monitor.id!, timeout: new PositiveNumber(60000), // 60 seconds }, @@ -309,7 +309,7 @@ export default class MonitorUtil { { isHeadRequest: MonitorUtil.isHeadRequest(monitorStep), monitorId: monitor.id!, - retry: 5, + retry: 10, timeout: new PositiveNumber(60000), // 60 seconds }, ); @@ -350,7 +350,7 @@ export default class MonitorUtil { requestBody: requestBody || undefined, monitorId: monitor.id!, requestType: monitorStep.data?.requestType || HTTPMethod.GET, - retry: 5, + retry: 10, timeout: new PositiveNumber(60000), // 60 seconds }, ); diff --git a/Probe/Utils/Monitors/MonitorTypes/ApiMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/ApiMonitor.ts index 99dfe8a1854..3628f7e0e23 100644 --- a/Probe/Utils/Monitors/MonitorTypes/ApiMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/ApiMonitor.ts @@ -187,7 +187,11 @@ export default class ApiMonitor { `API Monitor - Timeout exceeded ${options.monitorId?.toString()} ${requestType} ${url.toString()} - ERROR: ${err}`, ); - return null; // timeout exceeded + apiResponse.failureCause = + "Request was tried " + + options.currentRetryCount + + " times and it timed out."; + apiResponse.isOnline = false; } logger.error( diff --git a/Probe/Utils/Monitors/MonitorTypes/PingMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/PingMonitor.ts index 30737105653..76b01456492 100644 --- a/Probe/Utils/Monitors/MonitorTypes/PingMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/PingMonitor.ts @@ -124,7 +124,13 @@ export default class PingMonitor { `Ping Monitor - Timeout exceeded ${pingOptions.monitorId?.toString()} ${host.toString()} - ERROR: ${err}`, ); - return null; + return { + isOnline: false, + failureCause: + "Request was tried " + + pingOptions.currentRetryCount + + " times and it timed out.", + }; } // check if the probe is online. diff --git a/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts index 5b3bfe0674e..6b3a9c525b9 100644 --- a/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/PortMonitor.ts @@ -2,6 +2,7 @@ import OnlineCheck from "../../OnlineCheck"; import Hostname from "Common/Types/API/Hostname"; import URL from "Common/Types/API/URL"; import BadDataException from "Common/Types/Exception/BadDataException"; +import UnableToReachServer from "Common/Types/Exception/UnableToReachServer"; import { PromiseRejectErrorFunction } from "Common/Types/FunctionTypes"; import IPv4 from "Common/Types/IP/IPv4"; import IPv6 from "Common/Types/IP/IPv6"; @@ -114,7 +115,7 @@ export default class PortMonitor { logger.debug("Ping timeout"); if (!hasPromiseResolved) { - resolve(new PositiveNumber(timeout)); + reject(new UnableToReachServer("Ping timeout")); } hasPromiseResolved = true; diff --git a/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts index 59b4dae13a2..79af6e310b6 100644 --- a/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/SslMonitor.ts @@ -88,7 +88,13 @@ export default class SSLMonitor { `Ping Monitor - Timeout exceeded ${pingOptions.monitorId?.toString()} ${url.toString()} - ERROR: ${err}`, ); - return null; + return { + isOnline: false, + failureCause: + "Request was tried " + + pingOptions.currentRetryCount + + " times and it timed out.", + }; } // check if the probe is online. diff --git a/Probe/Utils/Monitors/MonitorTypes/WebsiteMonitor.ts b/Probe/Utils/Monitors/MonitorTypes/WebsiteMonitor.ts index 36745d818b3..375a3e33156 100644 --- a/Probe/Utils/Monitors/MonitorTypes/WebsiteMonitor.ts +++ b/Probe/Utils/Monitors/MonitorTypes/WebsiteMonitor.ts @@ -162,7 +162,13 @@ export default class WebsiteMonitor { `Website Monitor - Timeout exceeded ${options.monitorId?.toString()} ${requestType} ${url.toString()} - ERROR: ${err}`, ); - return null; + probeWebsiteResponse.failureCause = + "Request was tried " + + options.currentRetryCount + + " times and it timed out."; + probeWebsiteResponse.isOnline = false; + + return probeWebsiteResponse; } if (!options.isOnlineCheckRequest) {