From e51e158a7f317809852f2f417cb9ed19e81fc4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=B6=E7=8F=A5?= Date: Mon, 9 Mar 2020 11:30:51 +0800 Subject: [PATCH 1/2] fix MultiApplicationHealthIndicator bug --- .../health/MultiApplicationHealthIndicator.java | 14 ++++++++------ .../healthcheck/impl/SofaRuntimeHealthChecker.java | 4 ++++ .../invoke/DynamicJvmServiceProxyFinder.java | 4 ++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/health/MultiApplicationHealthIndicator.java b/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/health/MultiApplicationHealthIndicator.java index 443c08988..6ca346c1b 100644 --- a/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/health/MultiApplicationHealthIndicator.java +++ b/sofa-boot-project/sofa-boot-actuator/src/main/java/com/alipay/sofa/boot/actuator/health/MultiApplicationHealthIndicator.java @@ -16,6 +16,7 @@ */ package com.alipay.sofa.boot.actuator.health; +import com.alipay.sofa.ark.spi.model.Biz; import org.springframework.boot.actuate.health.Health; import org.springframework.boot.actuate.health.HealthIndicator; @@ -35,16 +36,17 @@ public Health health() { boolean allPassed = true; Health.Builder builder = new Health.Builder(); for (SofaRuntimeManager sofaRuntimeManager : SofaFramework.getRuntimeSet()) { + Biz biz = DynamicJvmServiceProxyFinder.getBiz(sofaRuntimeManager); + if (biz == null) { + continue; + } + if (!sofaRuntimeManager.isLivenessHealth()) { allPassed = false; - builder.withDetail( - String.format("Biz: %s health check", - DynamicJvmServiceProxyFinder.getBiz(sofaRuntimeManager).getIdentity()), + builder.withDetail(String.format("Biz: %s health check", biz.getIdentity()), "failed"); } else { - builder.withDetail( - String.format("Biz: %s health check", - DynamicJvmServiceProxyFinder.getBiz(sofaRuntimeManager).getIdentity()), + builder.withDetail(String.format("Biz: %s health check", biz.getIdentity()), "passed"); } } diff --git a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/SofaRuntimeHealthChecker.java b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/SofaRuntimeHealthChecker.java index 08c73da6b..6e2917f8e 100644 --- a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/SofaRuntimeHealthChecker.java +++ b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/SofaRuntimeHealthChecker.java @@ -49,6 +49,10 @@ public boolean isReadinessHealth() { @Override public boolean isLivenessHealth() { for (HealthIndicator healthIndicator : healthIndicators) { + if (healthIndicator.getClass().getSimpleName() + .equals("MultiApplicationHealthIndicator")) { + continue; + } if (healthIndicator.health().getStatus().equals(Status.DOWN)) { return false; } diff --git a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/invoke/DynamicJvmServiceProxyFinder.java b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/invoke/DynamicJvmServiceProxyFinder.java index c516d32de..0b832189b 100644 --- a/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/invoke/DynamicJvmServiceProxyFinder.java +++ b/sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/invoke/DynamicJvmServiceProxyFinder.java @@ -150,6 +150,10 @@ private ServiceComponent findServiceComponent(String uniqueId, String interfaceT * @return */ public static Biz getBiz(SofaRuntimeManager sofaRuntimeManager) { + if (getDynamicJvmServiceProxyFinder().bizManagerService == null) { + return null; + } + for (Biz biz : getDynamicJvmServiceProxyFinder().bizManagerService.getBizInOrder()) { if (sofaRuntimeManager.getAppClassLoader().equals(biz.getBizClassLoader())) { return biz; From b2e859d72ba68c0566cac561216ee2732c3bbd4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BA=B6=E7=8F=A5?= Date: Mon, 9 Mar 2020 14:13:03 +0800 Subject: [PATCH 2/2] change to class fqn --- .../sofa/healthcheck/impl/SofaRuntimeHealthChecker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/SofaRuntimeHealthChecker.java b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/SofaRuntimeHealthChecker.java index 6e2917f8e..f8753dfc8 100644 --- a/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/SofaRuntimeHealthChecker.java +++ b/sofa-boot-project/sofa-boot-core/healthcheck-sofa-boot/src/main/java/com/alipay/sofa/healthcheck/impl/SofaRuntimeHealthChecker.java @@ -49,8 +49,8 @@ public boolean isReadinessHealth() { @Override public boolean isLivenessHealth() { for (HealthIndicator healthIndicator : healthIndicators) { - if (healthIndicator.getClass().getSimpleName() - .equals("MultiApplicationHealthIndicator")) { + if (healthIndicator.getClass().getName() + .equals("com.alipay.sofa.boot.actuator.health.MultiApplicationHealthIndicator")) { continue; } if (healthIndicator.health().getStatus().equals(Status.DOWN)) {