Skip to content

Commit

Permalink
reference component health check support more deails when failed (#1121)
Browse files Browse the repository at this point in the history
Co-authored-by: yuanxuan <wt150181@antgroup.com>
  • Loading branch information
taobaorun and yuanxuan committed Mar 16, 2023
1 parent aeddd95 commit 081a24c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"com.alipay.sofa.boot.skipExtensionHealthCheck=true",
"com.alipay.sofa.boot.extensionFailureInsulating=true",
"com.alipay.sofa.boot.serviceInterfaceTypeCheck=true",
"com.alipay.sofa.boot.referenceHealthCheckMoreDetailEnable=true",
"com.alipay.sofa.boot.skipJvmReferenceHealthCheckList=com.alipay.sofa.isle.sample.facade.SampleJvmService:annotationImpl,com.alipay.sofa.isle.sample.facade.SampleJvmService" })
public class SofaRuntimePropertiesTest {

Expand Down Expand Up @@ -112,6 +113,14 @@ public void testSkipJvmReferenceHealthCheckList() {
.getSkipJvmReferenceHealthCheckList().toArray(new String[] {}));
}

@Test
public void testReferenceHealthCheckMoreDetailEnable() {
SofaRuntimeConfigurationProperties configurationProperties = ctx
.getBean(SofaRuntimeConfigurationProperties.class);
Assert.assertTrue(configurationProperties.isReferenceHealthCheckMoreDetailEnable());

}

@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
static class SofaRuntimePropertiesTestConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,24 @@
*/
public class SofaRuntimeProperties {

private static final ConcurrentHashMap<ClassLoader, Boolean> skipJvmReferenceHealthCheckMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipExtensionHealthCheckMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> disableJvmFirstMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipJvmSerializeMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> extensionFailureInsulatingMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> manualReadinessCallbackMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipAllComponentShutdownMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipCommonComponentShutdownMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipJvmReferenceHealthCheckMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipExtensionHealthCheckMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> disableJvmFirstMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipJvmSerializeMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> extensionFailureInsulatingMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> manualReadinessCallbackMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipAllComponentShutdownMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, Boolean> skipCommonComponentShutdownMap = new ConcurrentHashMap<>();

private static final ConcurrentHashMap<ClassLoader, List<String>> skipJvmReferenceHealthCheckListMap = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<ClassLoader, List<String>> skipJvmReferenceHealthCheckListMap = new ConcurrentHashMap<>();

private static boolean jvmFilterEnable = false;
private static boolean serviceInterfaceTypeCheck = false;
private static boolean dynamicJvmServiceCacheEnable = false;
private static boolean jvmFilterEnable = false;
private static boolean serviceInterfaceTypeCheck = false;
private static boolean dynamicJvmServiceCacheEnable = false;

private static boolean serviceNameWithBeanId = false;
private static boolean serviceNameWithBeanId = false;

private static boolean referenceHealthCheckMoreDetailEnable = false;

public static boolean isManualReadinessCallback(ClassLoader classLoader) {
return manualReadinessCallbackMap.get(classLoader) != null
Expand Down Expand Up @@ -179,4 +181,12 @@ public static List<String> getSkipJvmReferenceHealthCheckList(ClassLoader classL
return skipJvmReferenceHealthCheckListMap.get(classLoader);

}

public static boolean isReferenceHealthCheckMoreDetailEnable() {
return referenceHealthCheckMoreDetailEnable;
}

public static void setReferenceHealthCheckMoreDetailEnable(boolean referenceHealthCheckMoreDetailEnable) {
SofaRuntimeProperties.referenceHealthCheckMoreDetailEnable = referenceHealthCheckMoreDetailEnable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,13 @@ public List<String> getSkipJvmReferenceHealthCheckList() {
.getContextClassLoader());
}

public boolean isReferenceHealthCheckMoreDetailEnable() {
return SofaRuntimeProperties.isReferenceHealthCheckMoreDetailEnable();
}

public void setReferenceHealthCheckMoreDetailEnable(boolean referenceHealthCheckMoreDetailEnable) {
SofaRuntimeProperties
.setReferenceHealthCheckMoreDetailEnable(referenceHealthCheckMoreDetailEnable);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.alipay.sofa.runtime.spi.binding.BindingAdapter;
import com.alipay.sofa.runtime.spi.binding.BindingAdapterFactory;
import com.alipay.sofa.runtime.spi.component.AbstractComponent;
import com.alipay.sofa.runtime.spi.component.ComponentDefinitionInfo;
import com.alipay.sofa.runtime.spi.component.ComponentInfo;
import com.alipay.sofa.runtime.spi.component.DefaultImplementation;
import com.alipay.sofa.runtime.spi.component.Implementation;
Expand Down Expand Up @@ -104,7 +105,26 @@ public HealthResult isHealthy() {
Object serviceTarget = getServiceTarget();
if (serviceTarget == null && !jvmBinding.hasBackupProxy()) {
jvmBindingHealthResult.setHealthy(false);
jvmBindingHealthResult.setHealthReport("can not find corresponding jvm service");
StringBuilder healthReport = new StringBuilder(64);
healthReport.append("can not find corresponding jvm service");
if (SofaRuntimeProperties.isReferenceHealthCheckMoreDetailEnable()) {
Property sourceProperty = getProperties().get(ComponentDefinitionInfo.SOURCE);
if (sourceProperty != null && sourceProperty.getValue() != null
&& sourceProperty.getValue() instanceof ComponentDefinitionInfo) {
ComponentDefinitionInfo definitionInfo = (ComponentDefinitionInfo) sourceProperty
.getValue();
healthReport.append(".");
healthReport
.append(String
.format(
"Which first declared through:%s beanId:%s,beanClassName:%s,location:%s",
definitionInfo.getInterfaceMode(),
definitionInfo.info(ComponentDefinitionInfo.BEAN_ID),
definitionInfo.info(ComponentDefinitionInfo.BEAN_CLASS_NAME),
definitionInfo.info(ComponentDefinitionInfo.LOCATION)));
}
}
jvmBindingHealthResult.setHealthReport(healthReport.toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ public void putInfo(String key, String value) {
}

public String info(String key) {
return info.get(key);
return info.getOrDefault(key, "");
}
}

0 comments on commit 081a24c

Please sign in to comment.