[Improvement-18034][alert] Add configurable timeout for script alert plugin#18050
[Improvement-18034][alert] Add configurable timeout for script alert plugin#18050asadjan4611 wants to merge 15 commits intoapache:devfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a configurable execution timeout to the Script Alert Plugin to prevent hung scripts from permanently blocking alert-sender threads, aligning behavior with the HTTP alert plugin’s timeout pattern.
Changes:
- Introduce script timeout plugin parameter (default 60s) and expose it via the Script plugin channel factory params.
- Update script execution to use
waitFor(timeout, TimeUnit.SECONDS)and return a dedicated timeout exit code. - Add/adjust unit tests for the new timeout parameter and timeout behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java | Adds timed waiting for script processes and timeout handling. |
| dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java | Parses timeout config and maps timeout exit code to a clearer alert result message. |
| dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptParamsConstants.java | Adds timeout-related constants and default value. |
| dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java | Exposes timeout as an InputNumberParam in the Script plugin UI params. |
| dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java | Updates tests to use the new timeout API and adds a timeout test case. |
| dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java | Adds basic tests for default/custom timeout configuration. |
| dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactoryTest.java | Updates expected param count after adding timeout. |
Comments suppressed due to low confidence (1)
dolphinscheduler-alert/dolphinscheduler-alert-plugins/dolphinscheduler-alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java:64
- The catch block interrupts the current thread for both
InterruptedExceptionandIOException. Interrupting the thread on anIOExceptioncan cause unrelated higher-level code to behave as if it was interrupted. Split the catch and only callThread.currentThread().interrupt()when the exception is actually anInterruptedException.
} catch (IOException | InterruptedException e) {
log.error("execute alert script error {}", e.getMessage());
Thread.currentThread().interrupt();
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
...alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java
Show resolved
Hide resolved
...t-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java
Outdated
Show resolved
Hide resolved
...t-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
Show resolved
Hide resolved
...t-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
Show resolved
Hide resolved
...alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java
Outdated
Show resolved
Hide resolved
...alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java
Outdated
Show resolved
Hide resolved
|
@SbloodyS I have resolved all the copilot issue's please review it again. |
e902f7e to
124bf56
Compare
| closeProcessStreams(process); | ||
| joinGobbler(inputStreamGobbler); | ||
| joinGobbler(errorStreamGobbler); | ||
| return -2; |
There was a problem hiding this comment.
It's better to use positive integer here.
| .build(); | ||
|
|
||
| return Arrays.asList(scriptUserParam, scriptPathParam, scriptTypeParams); | ||
| InputNumberParam scriptTimeoutParam = |
There was a problem hiding this comment.
It is best to tell the user the meaning of the exit code in the document.
| ? config.get(ScriptParamsConstants.NAME_SCRIPT_USER_PARAMS) | ||
| : ""; | ||
| String timeoutConfig = config.get(ScriptParamsConstants.NAME_SCRIPT_TIMEOUT); | ||
| if (StringUtils.isNotBlank(timeoutConfig)) { |
There was a problem hiding this comment.
| if (StringUtils.isNotBlank(timeoutConfig)) { | |
| if (StringUtils.isNotEmpty(timeoutConfig)) { |
| try { | ||
| parsedTimeout = Long.parseLong(timeoutConfig); | ||
| } catch (NumberFormatException ex) { | ||
| log.warn("Invalid script timeout config value: '{}', using default: {}", |
There was a problem hiding this comment.
We should return alertResult here.
| private String[] cmd = {"/bin/sh", "-c", shellFilPath + " -t 1"}; | ||
|
|
||
| @Test | ||
| @DisabledOnOs(OS.WINDOWS) |
There was a problem hiding this comment.
We don't need to do this since we've decleared in the document that windows is not supported.
| } | ||
|
|
||
| @Test | ||
| @DisabledOnOs(OS.WINDOWS) |
| @Slf4j | ||
| public final class ProcessUtils { | ||
|
|
||
| static final int EXECUTE_ERROR_EXIT_CODE = -1; |
There was a problem hiding this comment.
Do not use negative number here.
| } | ||
|
|
||
| private String[] cmd = {"/bin/sh", "-c", shellFilPath + " -t 1"}; | ||
| private static String getJavaBin() { |
| } | ||
|
|
||
| @Test | ||
| @DisabledOnOs(OS.WINDOWS) |
|
|
||
| private String[] cmd = {"/bin/sh", "-c", shellFilPath + " -t 1"}; | ||
| private static String getJavaBin() { | ||
| String executableName = System.getProperty("os.name").toLowerCase().contains("win") |
| AlertResult alertResult; | ||
| alertResult = scriptSender.sendScriptAlert("test user params NPE", "test content"); | ||
| Assertions.assertTrue(alertResult.isSuccess()); | ||
| if (isWindows()) { |
| AlertResult alertResult; | ||
| alertResult = scriptSender.sendScriptAlert("test title Kris", "test content"); | ||
| Assertions.assertTrue(alertResult.isSuccess()); | ||
| if (isWindows()) { |
| alertResult = scriptSender.sendScriptAlert("test path NPE", "test content"); | ||
| assertFalse(alertResult.isSuccess()); | ||
| Assertions.assertTrue(alertResult.getMessage().contains("shell script is invalid, only support .sh file")); | ||
| if (isWindows()) { |
| public void testDefaultTimeout() { | ||
| ScriptSender scriptSender = new ScriptSender(scriptConfig); | ||
| AlertResult alertResult = scriptSender.sendScriptAlert("test title Kris", "test content"); | ||
| if (isWindows()) { |
| scriptConfig.put(ScriptParamsConstants.NAME_SCRIPT_TIMEOUT, "30"); | ||
| ScriptSender scriptSender = new ScriptSender(scriptConfig); | ||
| AlertResult alertResult = scriptSender.sendScriptAlert("test title Kris", "test content"); | ||
| if (isWindows()) { |
| ScriptSender scriptSender = new ScriptSender(scriptConfig); | ||
| AlertResult alertResult = scriptSender.sendScriptAlert("test title Kris", "test content"); | ||
| Assertions.assertFalse(alertResult.isSuccess()); | ||
| if (isWindows()) { |
...t-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
...alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtils.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptAlertChannelFactory.java
Outdated
Show resolved
Hide resolved
...alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
Show resolved
Hide resolved
...alert-script/src/main/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSender.java
Outdated
Show resolved
Hide resolved
...t-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
Show resolved
Hide resolved
...t-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ScriptSenderTest.java
Show resolved
Hide resolved
...t-script/src/test/java/org/apache/dolphinscheduler/plugin/alert/script/ProcessUtilsTest.java
Show resolved
Hide resolved
|
@SbloodyS i have fix all the issue's please again review it . |
|
CI still failed. @asadjan4611 |
|
@SbloodyS |
|
You should run |
|
okay @SbloodyS |
SbloodyS
left a comment
There was a problem hiding this comment.
There are still many unaddressed comments, you should check them yourself first.
...scheduler-alert-plugins/dolphinscheduler-alert-script/src/test/script/shell/scriptExample.sh
Outdated
Show resolved
Hide resolved
|


Purpose of the pull request
Close: #18034
The Script Alert Plugin executes external scripts to send alerts. Currently, ProcessUtils.executeScript() calls process.waitFor() with no timeout. If a script hangs (network stall, deadlock, etc.), it permanently blocks a thread in the alert sender thread pool, degrading or blocking all alert delivery.
This PR adds a configurable timeout parameter (default: 60 seconds) to the Script Alert Plugin following the same pattern used by the HTTP Alert Plugin.
Brief change log
Verify this pull request
This change added tests and can be verified as follows:
mvn clean compile