From 7dfe0f98cfef99710b6c55259f5a68750050a433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=B6=E7=8F=A5?= Date: Thu, 19 Dec 2019 14:12:42 +0800 Subject: [PATCH 1/5] delete unused imports --- .../com/alipay/sofa/rpc/boot/test/xsd/XsdTimeoutTest.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/XsdTimeoutTest.java b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/XsdTimeoutTest.java index 90b7d738a..88d8e4e11 100644 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/XsdTimeoutTest.java +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/XsdTimeoutTest.java @@ -16,14 +16,11 @@ */ package com.alipay.sofa.rpc.boot.test.xsd; -import com.alipay.sofa.rpc.boot.runtime.binding.BoltBinding; import com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding; import com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingType; import com.alipay.sofa.runtime.api.component.ComponentName; -import com.alipay.sofa.runtime.service.component.Reference; import com.alipay.sofa.runtime.service.component.ReferenceComponent; import com.alipay.sofa.runtime.service.component.ServiceComponent; -import com.alipay.sofa.runtime.spi.component.ComponentInfo; import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext; import org.junit.Assert; import org.junit.Test; @@ -34,8 +31,6 @@ import org.springframework.context.annotation.ImportResource; import org.springframework.test.context.junit4.SpringRunner; -import java.util.Collection; - /** * @author guaner.zzx * Created on 2019/12/18 From cca7cde5d9a34acc323b99158f3554920e484bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=B6=E7=8F=A5?= Date: Fri, 29 Nov 2019 12:36:38 +0800 Subject: [PATCH 2/5] component health check result display binding type --- .../impl/ComponentHealthChecker.java | 6 ++---- .../service/component/ReferenceComponent.java | 11 +---------- .../service/component/ServiceComponent.java | 8 +++----- .../spi/component/AbstractComponent.java | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/ComponentHealthChecker.java b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/ComponentHealthChecker.java index dbe52e5da..6e8cdf56c 100644 --- a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/ComponentHealthChecker.java +++ b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/ComponentHealthChecker.java @@ -57,10 +57,8 @@ public Health isHealthy() { Health.Builder builder = new Health.Builder(); for (ComponentInfo componentInfo : sofaRuntimeContext.getComponentManager().getComponents()) { HealthResult healthy = componentInfo.isHealthy(); - if (healthy.isHealthy()) { - builder.withDetail(healthy.getHealthName(), "passed"); - } else { - builder.withDetail(healthy.getHealthName(), healthy.getHealthReport()); + builder.withDetail(healthy.getHealthName(), healthy.getHealthReport()); + if (!healthy.isHealthy()) { allPassed = false; } } diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/component/ReferenceComponent.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/component/ReferenceComponent.java index 132d9c870..f38d34d3c 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/component/ReferenceComponent.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/component/ReferenceComponent.java @@ -82,10 +82,6 @@ public Map getProperties() { @Override public HealthResult isHealthy() { - if (!isActivated()) { - return super.isHealthy(); - } - HealthResult result = new HealthResult(componentName.getRawName()); List bindingHealth = new ArrayList<>(); @@ -122,14 +118,9 @@ public HealthResult isHealthy() { if (failedBindingHealth.size() == 0) { result.setHealthy(true); } else { - StringBuilder healthReport = new StringBuilder("|"); - for (HealthResult healthResult : failedBindingHealth) { - healthReport.append(healthResult.getHealthName()).append("#") - .append(healthResult.getHealthReport()); - } - result.setHealthReport(healthReport.substring(1, healthReport.length())); result.setHealthy(false); } + result.setHealthReport(aggregateBindingHealth(reference.getBindings())); return result; } diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/component/ServiceComponent.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/component/ServiceComponent.java index 4d1a2c467..37d8ed909 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/component/ServiceComponent.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/component/ServiceComponent.java @@ -158,6 +158,7 @@ private void activateBinding() { getContext()); } catch (Throwable t) { allPassed = false; + binding.setHealthy(false); SofaLogger.error(t, " < bindings) { + List healthResult = new ArrayList<>(); + for (Binding binding : bindings) { + HealthResult result = binding.healthCheck(); + String report = "[" + + result.getHealthName() + + "," + + (result.getHealthReport() == null ? (result.isHealthy() ? "passed" + : "failed") : result.getHealthReport()) + "]"; + healthResult.add(report); + } + return String.join(" ", healthResult); + } + @Override public boolean canBeDuplicate() { return true; From adce6d7e0a32bb253cc958a52fdeb7f9cf9b03a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=B6=E7=8F=A5?= Date: Tue, 3 Dec 2019 17:44:04 +0800 Subject: [PATCH 3/5] reference component healthcheck result persist --- .../com/alipay/sofa/runtime/service/binding/JvmBinding.java | 3 ++- .../alipay/sofa/runtime/service/binding/JvmBindingAdapter.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/binding/JvmBinding.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/binding/JvmBinding.java index 7d7906364..a1dbbaac4 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/binding/JvmBinding.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/binding/JvmBinding.java @@ -36,6 +36,8 @@ public class JvmBinding extends AbstractBinding { private JvmBindingParam jvmBindingParam = new JvmBindingParam(); + private HealthResult healthResult = new HealthResult(getName()); + public JvmBinding() { } @@ -92,7 +94,6 @@ public int getBindingHashCode() { @Override public HealthResult healthCheck() { - HealthResult healthResult = new HealthResult(getName()); healthResult.setHealthy(isHealthy); return healthResult; } diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/binding/JvmBindingAdapter.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/binding/JvmBindingAdapter.java index 03e7463c2..d7c01e8da 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/binding/JvmBindingAdapter.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/service/binding/JvmBindingAdapter.java @@ -178,7 +178,7 @@ public Object doInvoke(MethodInvocation invocation) throws Throwable { } } - if ((targetObj == null || ((targetObj instanceof Proxy) && binding.hasBackupProxy()))) { + if (targetObj == null || ((targetObj instanceof Proxy) && binding.hasBackupProxy())) { targetObj = binding.getBackupProxy(); SofaLogger.debug("<<{0}.{1} backup proxy invoke.", getInterfaceName().getName(), invocation.getMethod().getName()); From 5274382f07f92c361f36905f3197a708c2cbbf89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=B6=E7=8F=A5?= Date: Thu, 19 Dec 2019 18:48:48 +0800 Subject: [PATCH 4/5] add component health check test --- .../test/misc/ComponentHealthCheckerTest.java | 66 +++++++++++++++++++ .../test/{xsd => misc}/WhateverClass.java | 2 +- .../test/{xsd => misc}/WhateverInterface.java | 2 +- .../test/{xsd => misc}/XsdTimeoutTest.java | 4 +- .../spring/{xsd.xml => service_reference.xml} | 6 +- 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/ComponentHealthCheckerTest.java rename sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/{xsd => misc}/WhateverClass.java (95%) rename sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/{xsd => misc}/WhateverInterface.java (95%) rename sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/{xsd => misc}/XsdTimeoutTest.java (97%) rename sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/spring/{xsd.xml => service_reference.xml} (88%) diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/ComponentHealthCheckerTest.java b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/ComponentHealthCheckerTest.java new file mode 100644 index 000000000..7339da5b2 --- /dev/null +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/ComponentHealthCheckerTest.java @@ -0,0 +1,66 @@ +/* + * 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 com.alipay.sofa.rpc.boot.test.misc; + +import com.alipay.sofa.healthcheck.impl.ComponentHealthChecker; +import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Map; + +/** + * @author guaner.zzx + * Created on 2019/12/19 + */ +@SpringBootApplication +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ComponentHealthCheckerTest.class, properties = { "timeout=10000" }) +@ImportResource("/spring/service_reference.xml") +public class ComponentHealthCheckerTest { + @Autowired + private ApplicationContext applicationContext; + + @Test + public void componentHealthCheckerTest() { + ComponentHealthChecker componentHealthChecker = applicationContext + .getBean(ComponentHealthChecker.class); + Health health = componentHealthChecker.isHealthy(); + Map details = health.getDetails(); + for (String key : details.keySet()) { + Assert.assertTrue(((String) details.get(key)).contains("bolt")); + } + } + + @Configuration + static class ComponentHealthCheckerTestConfiguration { + @Bean + public ComponentHealthChecker sofaComponentHealthChecker(SofaRuntimeContext sofaRuntimeContext) { + return new ComponentHealthChecker(sofaRuntimeContext); + } + } +} diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/WhateverClass.java b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/WhateverClass.java similarity index 95% rename from sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/WhateverClass.java rename to sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/WhateverClass.java index ec7165469..75a9447ef 100644 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/WhateverClass.java +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/WhateverClass.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.rpc.boot.test.xsd; +package com.alipay.sofa.rpc.boot.test.misc; /** * @author guaner.zzx diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/WhateverInterface.java b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/WhateverInterface.java similarity index 95% rename from sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/WhateverInterface.java rename to sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/WhateverInterface.java index e45546bf5..0056ea3e0 100644 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/WhateverInterface.java +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/WhateverInterface.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.rpc.boot.test.xsd; +package com.alipay.sofa.rpc.boot.test.misc; /** * @author guaner.zzx diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/XsdTimeoutTest.java b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/XsdTimeoutTest.java similarity index 97% rename from sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/XsdTimeoutTest.java rename to sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/XsdTimeoutTest.java index 88d8e4e11..9237a82fb 100644 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/xsd/XsdTimeoutTest.java +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/java/com/alipay/sofa/rpc/boot/test/misc/XsdTimeoutTest.java @@ -14,7 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.alipay.sofa.rpc.boot.test.xsd; +package com.alipay.sofa.rpc.boot.test.misc; import com.alipay.sofa.rpc.boot.runtime.binding.RpcBinding; import com.alipay.sofa.rpc.boot.runtime.binding.RpcBindingType; @@ -38,7 +38,7 @@ @SpringBootApplication @RunWith(SpringRunner.class) @SpringBootTest(classes = XsdTimeoutTest.class, properties = { "timeout=10000" }) -@ImportResource("/spring/xsd.xml") +@ImportResource("/spring/service_reference.xml") public class XsdTimeoutTest { @Autowired WhateverInterface whatever; diff --git a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/spring/xsd.xml b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/spring/service_reference.xml similarity index 88% rename from sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/spring/xsd.xml rename to sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/spring/service_reference.xml index b443e5afc..8a13ff0d6 100644 --- a/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/spring/xsd.xml +++ b/sofa-boot-project/sofa-boot-core/rpc-sofa-boot/src/test/resources/spring/service_reference.xml @@ -4,14 +4,14 @@ xmlns:sofa="http://sofastack.io/schema/sofaboot" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://sofastack.io/schema/sofaboot http://sofastack.io/schema/sofaboot.xsd"> - - + + - + From 7de405c61b8cf222f6adf25e5e1c05ff56a180db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=B6=E7=8F=A5?= Date: Thu, 19 Dec 2019 19:32:52 +0800 Subject: [PATCH 5/5] compatibility check --- .../sofa/healthcheck/impl/ComponentHealthChecker.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/ComponentHealthChecker.java b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/ComponentHealthChecker.java index 6e8cdf56c..6fe983f0a 100644 --- a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/ComponentHealthChecker.java +++ b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/ComponentHealthChecker.java @@ -16,6 +16,7 @@ */ package com.alipay.sofa.healthcheck.impl; +import com.alipay.sofa.boot.util.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.Status; @@ -57,7 +58,12 @@ public Health isHealthy() { Health.Builder builder = new Health.Builder(); for (ComponentInfo componentInfo : sofaRuntimeContext.getComponentManager().getComponents()) { HealthResult healthy = componentInfo.isHealthy(); - builder.withDetail(healthy.getHealthName(), healthy.getHealthReport()); + String healthReport = healthy.getHealthReport(); + if (StringUtils.hasText(healthReport)) { + builder.withDetail(healthy.getHealthName(), healthy.getHealthReport()); + } else { + builder.withDetail(healthy.getHealthName(), "passed"); + } if (!healthy.isHealthy()) { allPassed = false; }