forked from apache/incubator-uniffle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[apache#1202] improvement: Add HealthScriptChecker for execute specia…
…l health check shell script (apache#1203) ### What changes were proposed in this pull request? add HealthScriptChecker for execute special health check shell script ref: https://github.com/apache/hadoop/blob/trunk/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/health/NodeHealthScriptRunner.java ### Why are the changes needed? Fix: apache#1202 ### Does this PR introduce _any_ user-facing change? `rss.server.health.checker.script.path` : The health script file path for HealthScriptChecker, if script file should have execute permission. `rss.server.health.checker.script.execi.timeout`: The health script file execute timeout seconds ### How was this patch tested? add ut --------- Co-authored-by: jam.xu <jam.xu@vipshop.com>
- Loading branch information
Showing
8 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
server/src/main/java/org/apache/uniffle/server/HealthScriptChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.server; | ||
|
||
import org.apache.hadoop.util.NodeHealthScriptRunner; | ||
import org.apache.hadoop.util.Shell; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.apache.uniffle.common.exception.RssException; | ||
|
||
public class HealthScriptChecker extends Checker { | ||
private static final Logger LOG = LoggerFactory.getLogger(HealthScriptChecker.class); | ||
private String healthScriptPath; | ||
private static final String ERROR_PATTERN = "ERROR"; | ||
private long scriptTimeout; | ||
|
||
HealthScriptChecker(ShuffleServerConf conf) { | ||
super(conf); | ||
this.healthScriptPath = conf.getString(ShuffleServerConf.HEALTH_CHECKER_SCRIPT_PATH); | ||
if (!NodeHealthScriptRunner.shouldRun(healthScriptPath)) { | ||
LOG.error( | ||
"Rss health check script:" | ||
+ healthScriptPath | ||
+ " is not available " | ||
+ "or doesn't have execute permission, so abort server."); | ||
throw new RssException("Health script not available."); | ||
} | ||
this.scriptTimeout = conf.getLong(ShuffleServerConf.HEALTH_CHECKER_SCRIPT_EXECUTE_TIMEOUT); | ||
} | ||
|
||
@Override | ||
public boolean checkIsHealthy() { | ||
HealthCheckerExitStatus status = HealthCheckerExitStatus.SUCCESS; | ||
// always build executor is to load the latest script, the script file can update in need. | ||
Shell.ShellCommandExecutor commandExecutor = | ||
new Shell.ShellCommandExecutor(new String[] {healthScriptPath}, null, null, scriptTimeout); | ||
try { | ||
commandExecutor.execute(); | ||
} catch (Shell.ExitCodeException e) { | ||
// ignore the exit code of the script | ||
status = HealthCheckerExitStatus.FAILED_WITH_EXIT_CODE; | ||
// On Windows, we will not hit the Stream closed IOException | ||
// thrown by stdout buffered reader for timeout event. | ||
if (Shell.WINDOWS && commandExecutor.isTimedOut()) { | ||
status = HealthCheckerExitStatus.TIMED_OUT; | ||
} | ||
} catch (Exception e) { | ||
LOG.warn("execute health script exception, please check script.", e); | ||
if (!commandExecutor.isTimedOut()) { | ||
status = HealthCheckerExitStatus.FAILED_WITH_EXCEPTION; | ||
} else { | ||
status = HealthCheckerExitStatus.TIMED_OUT; | ||
} | ||
} finally { | ||
if (status == HealthCheckerExitStatus.SUCCESS) { | ||
if (hasErrors(commandExecutor.getOutput())) { | ||
status = HealthCheckerExitStatus.FAILED; | ||
} | ||
} | ||
} | ||
if (status != HealthCheckerExitStatus.SUCCESS) { | ||
LOG.warn("health script check failed. exit status : " + status); | ||
} | ||
return status == HealthCheckerExitStatus.SUCCESS; | ||
} | ||
|
||
private boolean hasErrors(String output) { | ||
String[] splits = output.split("\n"); | ||
for (String split : splits) { | ||
if (split.startsWith(ERROR_PATTERN)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private enum HealthCheckerExitStatus { | ||
SUCCESS, | ||
TIMED_OUT, | ||
FAILED_WITH_EXIT_CODE, | ||
FAILED_WITH_EXCEPTION, | ||
FAILED | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
server/src/test/java/org/apache/uniffle/server/HealthScriptCheckerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.uniffle.server; | ||
|
||
import java.io.File; | ||
import java.util.Objects; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
class HealthScriptCheckerTest { | ||
private String healthScriptTemplate1; | ||
private String healthScriptTemplate2; | ||
private String healthScriptTemplate3; | ||
private String healthScriptTemplate4; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
healthScriptTemplate1 = getScriptFilePath("healthy-script1.sh"); | ||
healthScriptTemplate2 = getScriptFilePath("healthy-script2.sh"); | ||
healthScriptTemplate3 = getScriptFilePath("healthy-script3.sh"); | ||
healthScriptTemplate4 = getScriptFilePath("healthy-script4.sh"); | ||
setExecutable(healthScriptTemplate1); | ||
setExecutable(healthScriptTemplate2); | ||
setExecutable(healthScriptTemplate3); | ||
setExecutable(healthScriptTemplate4); | ||
} | ||
|
||
@Test | ||
void checkIsHealthy() { | ||
ShuffleServerConf conf = new ShuffleServerConf(); | ||
conf.setString(ShuffleServerConf.HEALTH_CHECKER_SCRIPT_PATH, healthScriptTemplate1); | ||
HealthScriptChecker checker = new HealthScriptChecker(conf); | ||
assertTrue(checker.checkIsHealthy()); | ||
|
||
conf.setString(ShuffleServerConf.HEALTH_CHECKER_SCRIPT_PATH, healthScriptTemplate2); | ||
checker = new HealthScriptChecker(conf); | ||
assertFalse(checker.checkIsHealthy()); | ||
|
||
conf.setString(ShuffleServerConf.HEALTH_CHECKER_SCRIPT_PATH, healthScriptTemplate3); | ||
checker = new HealthScriptChecker(conf); | ||
assertFalse(checker.checkIsHealthy()); | ||
|
||
conf.setString(ShuffleServerConf.HEALTH_CHECKER_SCRIPT_PATH, healthScriptTemplate4); | ||
conf.setLong(ShuffleServerConf.HEALTH_CHECKER_SCRIPT_EXECUTE_TIMEOUT, 3000L); | ||
checker = new HealthScriptChecker(conf); | ||
assertFalse(checker.checkIsHealthy()); | ||
} | ||
|
||
private String getScriptFilePath(String fileName) { | ||
return Objects.requireNonNull(this.getClass().getClassLoader().getResource(fileName)).getFile(); | ||
} | ||
|
||
private boolean setExecutable(String filePath) { | ||
File file = new File(filePath); | ||
file.setExecutable(true); | ||
return file.canExecute(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
echo "NORMAL: Check Disk is Normal" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
echo "ERROR(disk_io): disk with Input/output error" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
sleep 5s |