From 439b6517d1da600accde4459e4c6dc4479526ced Mon Sep 17 00:00:00 2001 From: Jinhyeok Lee Date: Mon, 7 Aug 2023 01:14:56 +0900 Subject: [PATCH] Feat: Add http/http keyword timeout option (#2142) * feat: Add timeoutMs field * chore: Update Languages (incl. ko-KR) * Revert "chore: Update Languages (incl. ko-KR)" This reverts commit 349331a00b6a7b1a59935442df8e9e50176baf17. * chore: Update ko-KR selectively * chore: Update en selectively * Merge manually * Reorder and show only if http related monitors * fix: Update Korean translation * fix: Rename timeoutMs to timeout, rename label, make DOUBLE * fix: Change minimum step to 0.1, matching DOUBLE type * Put the sql patch at the end * Update EditMonitor.vue * Colocate timeout with retry, fix clampTimeout logic, show default on 0 * Update src/pages/EditMonitor.vue to remove a comment Co-authored-by: Frank Elsinga * Fix merge issue * Update the timeout value while finished editing the interval value --------- Co-authored-by: Louis Lam Co-authored-by: Frank Elsinga --- db/patch-add-timeout-monitor.sql | 6 +++++ server/database.js | 1 + server/model/monitor.js | 5 ++-- server/server.js | 3 +++ src/lang/en.json | 2 ++ src/lang/ko-KR.json | 2 ++ src/pages/EditMonitor.vue | 41 ++++++++++++++++++++++++++++++-- 7 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 db/patch-add-timeout-monitor.sql diff --git a/db/patch-add-timeout-monitor.sql b/db/patch-add-timeout-monitor.sql new file mode 100644 index 000000000..32d49d1e2 --- /dev/null +++ b/db/patch-add-timeout-monitor.sql @@ -0,0 +1,6 @@ +-- 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 DOUBLE default 0 not null; +COMMIT; \ No newline at end of file diff --git a/server/database.js b/server/database.js index ba20663fb..ed4e4d1b1 100644 --- a/server/database.js +++ b/server/database.js @@ -79,6 +79,7 @@ class Database { "patch-added-kafka-producer.sql": true, "patch-add-certificate-expiry-status-page.sql": true, "patch-monitor-oauth-cc.sql": true, + "patch-add-timeout-monitor.sql": true, }; /** diff --git a/server/model/monitor.js b/server/model/monitor.js index a8f3d898a..152a2c72a 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -102,6 +102,7 @@ class Monitor extends BeanModel { active: await this.isActive(), forceInactive: !await Monitor.isParentActive(this.id), type: this.type, + timeout: this.timeout, interval: this.interval, retryInterval: this.retryInterval, resendInterval: this.resendInterval, @@ -428,7 +429,7 @@ class Monitor extends BeanModel { const options = { url: this.url, method: (this.method || "get").toLowerCase(), - timeout: this.interval * 1000 * 0.8, + timeout: this.timeout, 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, @@ -648,7 +649,7 @@ class Monitor extends BeanModel { } let res = await axios.get(steamApiUrl, { - timeout: this.interval * 1000 * 0.8, + timeout: this.timeout, headers: { "Accept": "*/*", "User-Agent": "Uptime-Kuma/" + version, diff --git a/server/server.js b/server/server.js index ad01eab2f..b5f15f67d 100644 --- a/server/server.js +++ b/server/server.js @@ -716,6 +716,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.timeout = monitor.timeout; bean.oauth_client_id = monitor.oauth_client_id, bean.oauth_client_secret = monitor.oauth_client_secret, bean.oauth_auth_method = this.oauth_auth_method, @@ -1372,6 +1373,7 @@ let needSetup = false; // Define default values let retryInterval = 0; + let timeout = monitorListData[i].timeout || (monitorListData[i].interval * 0.8); // fallback to old value /* Only replace the default value with the backup file data for the specific version, where it appears the first time @@ -1397,6 +1399,7 @@ let needSetup = false; basic_auth_pass: monitorListData[i].basic_auth_pass, authWorkstation: monitorListData[i].authWorkstation, authDomain: monitorListData[i].authDomain, + timeout, interval: monitorListData[i].interval, retryInterval: retryInterval, resendInterval: monitorListData[i].resendInterval || 0, diff --git a/src/lang/en.json b/src/lang/en.json index 8a894e5c7..003e7596b 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -59,6 +59,8 @@ "Hostname": "Hostname", "Port": "Port", "Heartbeat Interval": "Heartbeat Interval", + "Request Timeout": "Request Timeout", + "timeoutAfter": "Timeout after {0} seconds", "Retries": "Retries", "Heartbeat Retry Interval": "Heartbeat Retry Interval", "Resend Notification if Down X times consecutively": "Resend Notification if Down X times consecutively", diff --git a/src/lang/ko-KR.json b/src/lang/ko-KR.json index 052e08092..f3fff8d0a 100644 --- a/src/lang/ko-KR.json +++ b/src/lang/ko-KR.json @@ -589,6 +589,8 @@ "RadiusCalledStationIdDescription": "접속 스테이션의 식별자", "RadiusCallingStationId": "접속 요청 스테이션의 Id", "RadiusCallingStationIdDescription": "접속 요청 스테이션의 식별자", + "timeoutAfter": "{0}초 후 타임아웃", + "Request Timeout": "요청 타임아웃", "Query": "쿼리", "settingsCertificateExpiry": "TLS 인증서 만료", "certificationExpiryDescription": "HTTPS 모니터링 TLS 인증서가 만료되면 알림을 활성화해요:", diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 515f84d90..c13ecc7a6 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -393,7 +393,7 @@
- +
@@ -412,6 +412,12 @@
+ +
+ + +
+