feat: add interval-based validation for screenshot_delay
- Validate screenshot_delay < 0.8 × timeout (page.goto timeout) - Validate screenshot_delay < 0.5 × interval (prevent blocking next check) - Update UI to dynamically calculate max value based on interval - Add descriptive error messages showing calculated limits - Add translation key for max value info display Addresses CommanderStorm's validation requirements from issue #6471
This commit is contained in:
parent
262d2aa0dd
commit
2e0cebb3fb
@ -1769,8 +1769,20 @@ class Monitor extends BeanModel {
|
||||
// screenshot_delay validation
|
||||
if (this.screenshot_delay !== undefined && this.screenshot_delay !== null) {
|
||||
const delay = Number(this.screenshot_delay);
|
||||
if (isNaN(delay) || delay < 0 || delay > 30000) {
|
||||
throw new Error("Screenshot delay must be between 0 and 30000 milliseconds");
|
||||
if (isNaN(delay) || delay < 0) {
|
||||
throw new Error("Screenshot delay must be a non-negative number");
|
||||
}
|
||||
|
||||
// Must not exceed 0.8 * timeout (page.goto timeout is interval * 1000 * 0.8)
|
||||
const maxDelayFromTimeout = this.interval * 1000 * 0.8;
|
||||
if (delay >= maxDelayFromTimeout) {
|
||||
throw new Error(`Screenshot delay must be less than ${maxDelayFromTimeout}ms (0.8 × interval)`);
|
||||
}
|
||||
|
||||
// Must not exceed 0.5 * interval to prevent blocking next check
|
||||
const maxDelayFromInterval = this.interval * 1000 * 0.5;
|
||||
if (delay >= maxDelayFromInterval) {
|
||||
throw new Error(`Screenshot delay must be less than ${maxDelayFromInterval}ms (0.5 × interval)`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1058,6 +1058,7 @@
|
||||
"Screenshot Delay ({ms})": "Screenshot Delay ({ms})",
|
||||
"ms": "ms",
|
||||
"screenshotDelayDescription": "Wait this many milliseconds before taking the screenshot.",
|
||||
"screenshotDelayMaxInfo": "Maximum: {max}ms (0.5 × interval).",
|
||||
"screenshotDelayWarning": "Higher values keep the browser open longer, which may increase memory usage with many concurrent monitors.",
|
||||
"GrafanaOncallUrl": "Grafana Oncall URL",
|
||||
"systemService": "System Service",
|
||||
|
||||
@ -274,11 +274,12 @@
|
||||
type="number"
|
||||
class="form-control"
|
||||
min="0"
|
||||
max="30000"
|
||||
:max="Math.floor(monitor.interval * 1000 * 0.5)"
|
||||
step="100"
|
||||
/>
|
||||
<div class="form-text">
|
||||
{{ $t("screenshotDelayDescription") }}
|
||||
{{ $t("screenshotDelayMaxInfo", { max: Math.floor(monitor.interval * 1000 * 0.5) }) }}
|
||||
</div>
|
||||
<div class="form-text text-warning">
|
||||
{{ $t("screenshotDelayWarning") }}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user