From 76ef46740a3aaad28047470402a8a13d533f9795 Mon Sep 17 00:00:00 2001 From: JinhyeokLee Date: Fri, 30 Sep 2022 21:51:49 +0900 Subject: [PATCH] feat: Add timeoutMs field --- db/patch-add-timeout-ms-monitor.sql | 7 +++++++ server/database.js | 1 + server/model/monitor.js | 5 +++-- server/server.js | 3 +++ src/pages/EditMonitor.vue | 14 ++++++++++++++ 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 db/patch-add-timeout-ms-monitor.sql diff --git a/db/patch-add-timeout-ms-monitor.sql b/db/patch-add-timeout-ms-monitor.sql new file mode 100644 index 000000000..f0d07be5a --- /dev/null +++ b/db/patch-add-timeout-ms-monitor.sql @@ -0,0 +1,7 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +ALTER TABLE monitor + ADD timeout_ms INTEGER default 0 not null; + +COMMIT; \ No newline at end of file diff --git a/server/database.js b/server/database.js index b1a23a475..89fe9a717 100644 --- a/server/database.js +++ b/server/database.js @@ -64,6 +64,7 @@ class Database { "patch-add-other-auth.sql": { parents: [ "patch-monitor-basic-auth.sql" ] }, "patch-add-radius-monitor.sql": true, "patch-monitor-add-resend-interval.sql": true, + "patch-add-timeout-ms-monitor.sql": true, }; /** diff --git a/server/model/monitor.js b/server/model/monitor.js index f96b4df06..329c6f05c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -77,6 +77,7 @@ class Monitor extends BeanModel { weight: this.weight, active: this.active, type: this.type, + timeoutMs: this.timeoutMs, interval: this.interval, retryInterval: this.retryInterval, resendInterval: this.resendInterval, @@ -252,7 +253,7 @@ class Monitor extends BeanModel { url: this.url, method: (this.method || "get").toLowerCase(), ...(this.body ? { data: JSON.parse(this.body) } : {}), - timeout: this.interval * 1000 * 0.8, + timeout: this.timeoutMs, headers: { "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9", "User-Agent": "Uptime-Kuma/" + version, @@ -446,7 +447,7 @@ class Monitor extends BeanModel { } let res = await axios.get(steamApiUrl, { - timeout: this.interval * 1000 * 0.8, + timeout: this.timeoutMs, headers: { "Accept": "*/*", "User-Agent": "Uptime-Kuma/" + version, diff --git a/server/server.js b/server/server.js index 0c9a45e6c..5267f67ce 100644 --- a/server/server.js +++ b/server/server.js @@ -668,6 +668,7 @@ let needSetup = false; bean.headers = monitor.headers; bean.basic_auth_user = monitor.basic_auth_user; bean.basic_auth_pass = monitor.basic_auth_pass; + bean.timeoutMs = monitor.timeoutMs; bean.interval = monitor.interval; bean.retryInterval = monitor.retryInterval; bean.resendInterval = monitor.resendInterval; @@ -1254,6 +1255,7 @@ let needSetup = false; // Define default values let retryInterval = 0; + let timeoutMs = monitorListData[i].interval * 1000 * 0.8; // previously hardcoded in monitor.js /* Only replace the default value with the backup file data for the specific version, where it appears the first time @@ -1278,6 +1280,7 @@ let needSetup = false; basic_auth_pass: monitorListData[i].basic_auth_pass, authWorkstation: monitorListData[i].authWorkstation, authDomain: monitorListData[i].authDomain, + timeoutMs: timeoutMs, interval: monitorListData[i].interval, retryInterval: retryInterval, resendInterval: monitorListData[i].resendInterval || 0, diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 99cbeb95f..ebbe85e22 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -254,6 +254,11 @@ +
+ + +
+
@@ -606,6 +611,10 @@ export default { if (this.monitor.retryInterval === oldValue) { this.monitor.retryInterval = value; } + // keep timeoutMs below interval, minding the unit conversion + if (!this.monitor.timeoutMs || this.monitor.timeoutMs >= value * 1000) { + this.monitor.timeoutMs = value * 1000 * 0.8; + } }, "monitor.type"() { @@ -668,6 +677,7 @@ export default { url: "https://", method: "GET", interval: 60, + timeoutMs: this.interval * 1000 * 0.8, // previous default value retryInterval: this.interval, resendInterval: 0, maxretries: 0, @@ -711,6 +721,10 @@ export default { if (this.monitor.retryInterval === 0) { this.monitor.retryInterval = this.monitor.interval; } + // Handling for monitors that are missing timeoutMs + if (!this.monitor.timeoutMs) { + this.monitor.timeoutMs = this.monitor.interval * 1000 * 0.8; + } } else { toast.error(res.msg); }