Skip to content

Commit d50d777

Browse files
authored
Fix extension healthcheck bug (#697)
* Fix extension healthcheck bug (#694)
1 parent 035f12a commit d50d777

5 files changed

Lines changed: 45 additions & 5 deletions

File tree

sofa-boot-project/sofa-boot-autoconfigure/src/test/java/com/alipay/sofa/autoconfigure/test/runtime/SofaRuntimePropertiesTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
@RunWith(SpringRunner.class)
3939
@TestPropertySource(properties = { "com.alipay.sofa.boot.disableJvmFirst=true",
4040
"com.alipay.sofa.boot.skipJvmReferenceHealthCheck=true",
41-
"com.alipay.sofa.boot.skipJvmSerialize=true", })
41+
"com.alipay.sofa.boot.skipJvmSerialize=true",
42+
"com.alipay.sofa.boot.skipExtensionHealthCheck=true" })
4243
public class SofaRuntimePropertiesTest {
4344

4445
@Autowired
@@ -72,6 +73,15 @@ public void testSkipJvmSerializeProperty() {
7273
Assert.assertTrue(configurationProperties.isSkipJvmSerialize());
7374
}
7475

76+
@Test
77+
public void testSkipExtensionHealthCheckProperty() {
78+
SofaRuntimeConfigurationProperties configurationProperties = ctx
79+
.getBean(SofaRuntimeConfigurationProperties.class);
80+
81+
Assert.assertTrue(SofaRuntimeProperties.isSkipExtensionHealthCheck(ctx.getClassLoader()));
82+
Assert.assertTrue(configurationProperties.isSkipExtensionHealthCheck());
83+
}
84+
7585
@Configuration
7686
@EnableAutoConfiguration
7787
static class SofaRuntimePropertiesTestConfiguration {

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/SofaRuntimeProperties.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
public class SofaRuntimeProperties {
2828

2929
private static ConcurrentHashMap<ClassLoader, Boolean> skipJvmReferenceHealthCheckMap = new ConcurrentHashMap<>();
30+
private static ConcurrentHashMap<ClassLoader, Boolean> skipExtensionHealthCheckMap = new ConcurrentHashMap<>();
3031
private static ConcurrentHashMap<ClassLoader, Boolean> disableJvmFirstMap = new ConcurrentHashMap<>();
31-
3232
private static ConcurrentHashMap<ClassLoader, Boolean> skipJvmSerializeMap = new ConcurrentHashMap<>();
3333

3434
public static boolean isSkipJvmReferenceHealthCheck(SofaRuntimeContext sofaRuntimeContext) {
@@ -45,6 +45,20 @@ public static void setSkipJvmReferenceHealthCheck(ClassLoader classLoader,
4545
skipJvmReferenceHealthCheckMap.putIfAbsent(classLoader, skipJvmReferenceHealthCheck);
4646
}
4747

48+
public static boolean isSkipExtensionHealthCheck(SofaRuntimeContext sofaRuntimeContext) {
49+
return isSkipExtensionHealthCheck(sofaRuntimeContext.getAppClassLoader());
50+
}
51+
52+
public static boolean isSkipExtensionHealthCheck(ClassLoader classLoader) {
53+
return skipExtensionHealthCheckMap.get(classLoader) != null
54+
&& skipExtensionHealthCheckMap.get(classLoader);
55+
}
56+
57+
public static void setSkipExtensionHealthCheck(ClassLoader classLoader,
58+
boolean skipExtensionHealthCheck) {
59+
skipExtensionHealthCheckMap.putIfAbsent(classLoader, skipExtensionHealthCheck);
60+
}
61+
4862
public static boolean isDisableJvmFirst(SofaRuntimeContext sofaRuntimeContext) {
4963
return isDisableJvmFirst(sofaRuntimeContext.getAppClassLoader());
5064
}

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/configure/SofaRuntimeConfigurationProperties.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,14 @@ public void setSkipJvmSerialize(boolean skipJvmSerialize) {
5353
public boolean isSkipJvmSerialize() {
5454
return SofaRuntimeProperties.isSkipJvmSerialize(this.getClass().getClassLoader());
5555
}
56+
57+
public void setSkipExtensionHealthCheck(boolean skipExtensionHealthCheck) {
58+
SofaRuntimeProperties.setSkipExtensionHealthCheck(this.getClass().getClassLoader(),
59+
skipExtensionHealthCheck);
60+
}
61+
62+
public boolean isSkipExtensionHealthCheck() {
63+
return SofaRuntimeProperties.isSkipExtensionHealthCheck(this.getClass().getClassLoader());
64+
}
65+
5666
}

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/ext/component/ExtensionComponent.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.lang.reflect.Method;
2020
import java.util.Map;
2121

22+
import com.alipay.sofa.runtime.SofaRuntimeProperties;
2223
import org.springframework.util.ObjectUtils;
2324
import org.springframework.util.ReflectionUtils;
2425

@@ -125,9 +126,12 @@ public void activate() throws ServiceRuntimeException {
125126

126127
@Override
127128
public HealthResult isHealthy() {
128-
HealthResult healthResult = new HealthResult(componentName.getRawName());
129-
healthResult.setHealthy(true);
130-
return healthResult;
129+
if (SofaRuntimeProperties.isSkipExtensionHealthCheck(sofaRuntimeContext)) {
130+
HealthResult healthResult = new HealthResult(componentName.getRawName());
131+
healthResult.setHealthy(true);
132+
return healthResult;
133+
}
134+
return super.isHealthy();
131135
}
132136

133137
public Extension getExtension() {

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/test/java/com/alipay/sofa/runtime/test/SofaEventHandlerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public void before() {
7575
Properties properties = new Properties();
7676
properties.setProperty("com.alipay.sofa.boot.disableJvmFirst", "true");
7777
properties.setProperty("com.alipay.sofa.boot.skipJvmReferenceHealthCheck", "true");
78+
properties.setProperty("com.alipay.sofa.boot.skipExtensionHealthCheck", "true");
7879
properties.setProperty("com.alipay.sofa.boot.skipJvmSerialize", "true");
7980
properties.setProperty("spring.application.name", "tSofaEventHandlerTest");
8081
SofaFramework.getRuntimeSet().forEach(value -> SofaFramework.unRegisterSofaRuntimeManager(value));
@@ -102,6 +103,7 @@ public void testUninstallEvent() {
102103
Assert.assertFalse(SofaRuntimeProperties.isDisableJvmFirst(ctx.getClassLoader()));
103104
Assert
104105
.assertFalse(SofaRuntimeProperties.isSkipJvmReferenceHealthCheck(ctx.getClassLoader()));
106+
Assert.assertFalse(SofaRuntimeProperties.isSkipExtensionHealthCheck(ctx.getClassLoader()));
105107
Assert.assertFalse(SofaRuntimeProperties.isSkipJvmSerialize(ctx.getClassLoader()));
106108
Assert.assertTrue(SofaFramework.getRuntimeSet().isEmpty());
107109
Assert.assertFalse(ctx.isActive());

0 commit comments

Comments
 (0)