Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add http/http keyword timeout option #2142

Merged
merged 24 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
76ef467
feat: Add timeoutMs field
zenyr Sep 30, 2022
349331a
chore: Update Languages (incl. ko-KR)
zenyr Sep 30, 2022
d05324c
Revert "chore: Update Languages (incl. ko-KR)"
zenyr Sep 30, 2022
65fb26e
chore: Update ko-KR selectively
zenyr Oct 2, 2022
24749ce
chore: Update en selectively
zenyr Oct 2, 2022
f4fb95d
Merge branch 'master' into feat-http-timeout
zenyr Nov 9, 2022
25d0977
Merge remote-tracking branch 'origin/master' into feat-http-timeout
louislam Jan 30, 2023
794e1e6
Merge manually
louislam Jan 30, 2023
0c74b5d
Reorder and show only if http related monitors
louislam Jan 30, 2023
8b7d5f1
Merge remote-tracking branch 'upstream/master' into feat-http-timeout
zenyr May 30, 2023
2daa39e
fix: Update Korean translation
zenyr May 30, 2023
510e0ac
fix: Rename timeoutMs to timeout, rename label, make DOUBLE
zenyr May 30, 2023
08cf998
fix: Change minimum step to 0.1, matching DOUBLE type
zenyr May 30, 2023
bb8a2e2
Merge remote-tracking branch 'origin/master' into feat-http-timeout
louislam Jul 8, 2023
c6d8b21
Put the sql patch at the end
louislam Jul 8, 2023
0f5c72b
Merge branch 'master' into feat-http-timeout
zenyr Jul 14, 2023
47814f3
Update EditMonitor.vue
zenyr Jul 14, 2023
a3a5e7e
Merge remote-tracking branch 'upstream/master' into feat-http-timeout
zenyr Jul 17, 2023
9ace741
Colocate timeout with retry, fix clampTimeout logic, show default on 0
zenyr Jul 18, 2023
d774855
Merge remote-tracking branch 'upstream/master' into feat-http-timeout
zenyr Jul 18, 2023
e1ee816
Update src/pages/EditMonitor.vue to remove a comment
zenyr Jul 27, 2023
6d0bec3
Merge branch 'master' into feat-http-timeout
louislam Aug 6, 2023
7d683be
Fix merge issue
louislam Aug 6, 2023
38bb4a4
Update the timeout value while finished editing the interval value
louislam Aug 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions db/patch-add-timeout-monitor.sql
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions server/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Database {
"patch-add-parent-monitor.sql": true,
"patch-add-invert-keyword.sql": true,
"patch-added-json-query.sql": true,
"patch-add-timeout-monitor.sql": true,
};

/**
Expand Down
5 changes: 3 additions & 2 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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,
Expand Down Expand Up @@ -363,7 +364,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,
Expand Down Expand Up @@ -582,7 +583,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,
Expand Down
3 changes: 3 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,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.tlsCa = monitor.tlsCa;
bean.tlsCert = monitor.tlsCert;
bean.tlsKey = monitor.tlsKey;
Expand Down Expand Up @@ -1348,6 +1349,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
Expand All @@ -1373,6 +1375,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,
Expand Down
2 changes: 2 additions & 0 deletions src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/lang/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@
"RadiusCalledStationIdDescription": "접속 스테이션의 식별자",
"RadiusCallingStationId": "접속 요청 스테이션의 Id",
"RadiusCallingStationIdDescription": "접속 요청 스테이션의 식별자",
"timeoutAfter": "{0}초 후 타임아웃",
"Request Timeout": "요청 타임아웃",
"Query": "쿼리",
"settingsCertificateExpiry": "TLS 인증서 만료",
"certificationExpiryDescription": "HTTPS 모니터링 TLS 인증서가 만료되면 알림을 활성화해요:",
Expand Down
26 changes: 26 additions & 0 deletions src/pages/EditMonitor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@
</div>
</template>

<!-- Timeout: HTTP / Keyword only -->
<div v-if="monitor.type === 'http' || monitor.type === 'keyword'" class="my-3">
<label for="timeout" class="form-label">{{ $t("Request Timeout") }} ({{ $t("timeoutAfter", [ monitor.timeout ]) }})</label>
<input id="timeout" v-model="monitor.timeout" type="number" class="form-control" required min="0" step="0.1">
</div>

<!-- Description -->
<div class="my-3">
<label for="description" class="form-label">{{ $t("Description") }}</label>
Expand Down Expand Up @@ -906,6 +912,13 @@ message HealthCheckResponse {
if (this.monitor.retryInterval === oldValue) {
this.monitor.retryInterval = value;
}
// keep timeout within 80% range
this.clampTimeout(this.monitor.timeout);
},

"monitor.timeout"(value, oldValue) {
// keep timeout within 80% range
this.clampTimeout(value);
},

"monitor.type"() {
Expand Down Expand Up @@ -1006,6 +1019,7 @@ message HealthCheckResponse {
url: "https://",
method: "GET",
interval: 60,
timeout: this.interval * 0.8, // previous default value
zenyr marked this conversation as resolved.
Show resolved Hide resolved
retryInterval: this.interval,
resendInterval: 0,
maxretries: 1,
Expand Down Expand Up @@ -1085,6 +1099,10 @@ message HealthCheckResponse {
if (this.monitor.retryInterval === 0) {
this.monitor.retryInterval = this.monitor.interval;
}
// Handling for monitors that are missing/zeroed timeout
if (!this.monitor.timeout) {
this.monitor.timeout = this.monitor.interval * 0.8;
}
} else {
toast.error(res.msg);
}
Expand Down Expand Up @@ -1201,6 +1219,14 @@ message HealthCheckResponse {
addedDockerHost(id) {
this.monitor.docker_host = id;
},

// Clamp timeout
clampTimeout(timeout) {
// limit to 80% of interval
const maxTimeout = this.monitor.interval * 0.8;
// 0 will be treated as 80% of interval
this.monitor.timeout = Math.Max(0, Math.min(timeout, maxTimeout));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very amateur like mistake from my side. My bad!

}
},
};
</script>
Expand Down