Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parallel healthcheck #1052

Merged
merged 23 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
514919d
add a minor changes to log the missing modules in SpringContextInstal…
Aug 23, 2022
81fc954
add a minor changes to log the missing modules in SpringContextInstal…
Aug 23, 2022
2ab9871
add a minor changes to log the missing modules in SpringContextInstal…
Aug 23, 2022
c8e353f
add a minor changes to log the missing modules in SpringContextInstal…
Aug 23, 2022
0a5070c
Merge branch 'sofastack:master' into master
crazysaltfish Aug 29, 2022
c043f3b
Add a function that can remove the corresponding components when modu…
Sep 7, 2022
49d7821
Add test case for removing the components when module install failure
Sep 7, 2022
4518cce
Add test case for removing the components when module install failure
Sep 8, 2022
dd8a793
Add test case for removing the components when module install failure
Sep 8, 2022
b0b0035
Add a function that can remove the corresponding components when modu…
Sep 13, 2022
8d7acd1
Add a function that can remove the corresponding components when modu…
Sep 13, 2022
f09d825
Add a function that can remove the corresponding components when modu…
Sep 14, 2022
a211835
Merge branch 'sofastack:master' into master
crazysaltfish Sep 29, 2022
8a4cbb3
Merge branch 'sofastack:master' into master
crazysaltfish Oct 8, 2022
9825a70
Merge branch 'sofastack:master' into master
crazysaltfish Oct 17, 2022
07f2a5e
Merge branch 'sofastack:master' into master
crazysaltfish Oct 24, 2022
522c4c8
Merge branch 'sofastack:master' into master
crazysaltfish Oct 26, 2022
e4e28ef
Merge branch 'sofastack:master' into master
crazysaltfish Nov 11, 2022
3bf09c6
Merge branch 'sofastack:master' into master
crazysaltfish Nov 17, 2022
7bc7fff
Merge branch 'sofastack:master' into master
crazysaltfish Dec 27, 2022
116ab9a
Merge branch 'sofastack:master' into master
crazysaltfish Jan 5, 2023
2f264a6
fix parallelHealthcheck timeout bug;
Jan 9, 2023
df8fb61
update sofa-boot version 3.16.2 to 3.16.3
Jan 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<description>SOFABoot Build</description>

<properties>
<revision>3.16.2</revision>
<revision>3.16.3</revision>
<sofa.boot.version>${revision}</sofa.boot.version>
<!--maven plugin-->
<maven.staging.plugin>1.6.7</maven.staging.plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ public boolean readinessHealthCheck(Map<String, Health> healthMap) {
} catch (InterruptedException e) {
logger.error(ErrorCode.convert("01-22005"), e);
}
if (!finished) {
healthMap.put(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY, Health.unknown().withDetail(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY,SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_MSG).build());
}
result = finished && parallelResult.get();
} else {
result = readinessHealthCheckers.entrySet().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ public boolean readinessHealthCheck(Map<String, Health> healthMap) {
} catch (InterruptedException e) {
logger.error(ErrorCode.convert("01-21004"), e);
}
if (!finished) {
healthMap.put(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY, Health.unknown().withDetail(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY,SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_MSG).build());
}
result = finished && parallelResult.get();
} else {
result = healthIndicators.entrySet().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,30 @@ public Health aggregateReadinessHealth() {
SofaBootConstants.SOFABOOT_HEALTH_CHECK_NOT_READY_MSG).build());
} else {
boolean healthCheckerStatus = getHealthCheckerStatus();
boolean healthIndicatorStatus = getHealthIndicatorStatus();
boolean afterReadinessCheckCallbackStatus = getHealthCallbackStatus();
Map<String, Health> healthCheckerDetails = getHealthCheckerDetails();
Map<String, Health> healthIndicatorDetails = getHealthIndicatorDetails();

boolean afterReadinessCheckCallbackStatus = getHealthCallbackStatus();
Map<String, Health> afterReadinessCheckCallbackDetails = getHealthCallbackDetails();

Health.Builder builder;
if (healthCheckerStatus && afterReadinessCheckCallbackStatus) {
builder = Health.up();
} else {
builder = Health.down();
}
builder = healthCheckerStatus ? Health.up():Health.down();
if (!CollectionUtils.isEmpty(healthCheckerDetails)) {
builder = builder.withDetail("HealthChecker", healthCheckerDetails);
builder = builder.withDetails(healthCheckerDetails);
}
if (!CollectionUtils.isEmpty(afterReadinessCheckCallbackDetails)) {
builder = builder.withDetail("ReadinessCheckCallback",
afterReadinessCheckCallbackDetails);
healths.put("HealthCheckerInfo", builder.build());

builder = healthIndicatorStatus ? Health.up():Health.down();
if (!CollectionUtils.isEmpty(healthIndicatorDetails)) {
builder = builder.withDetails(healthIndicatorDetails);
}
healths.put("SOFABootReadinessHealthCheckInfo", builder.build());
healths.put("HealthIndicatorInfo", builder.build());

// HealthIndicator
healths.putAll(healthIndicatorDetails);
builder = afterReadinessCheckCallbackStatus ? Health.up():Health.down();
if (!CollectionUtils.isEmpty(afterReadinessCheckCallbackDetails)) {
builder = builder.withDetails(afterReadinessCheckCallbackDetails);
}
healths.put("ReadinessCheckCallbackInfo", builder.build());
}
Status overallStatus = this.statusAggregator.getAggregateStatus(
healths.values().stream().map(Health::getStatus).collect(Collectors.toSet()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,21 @@ public void testComponentHealthCheckerFailedFirst() {
}
}

@Test
public void testHealthCheckerParallelTimeout() {
initApplicationContextTimeout(0, false, 4);

HashMap<String, Health> hashMap = new HashMap<>();
HealthCheckerProcessor healthCheckerProcessor = applicationContext
.getBean(HealthCheckerProcessor.class);
boolean result = healthCheckerProcessor.readinessHealthCheck(hashMap);
Assert.assertFalse(result);
Health timeoutHealth = hashMap.get(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY);
Assert.assertEquals(Status.UNKNOWN, timeoutHealth.getStatus());
Assert.assertEquals(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_MSG, timeoutHealth
.getDetails().get(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY));
}

private void initApplicationContext(int count, boolean strict, int retryCount) {
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("memory-health-checker.count", count);
Expand All @@ -237,4 +252,20 @@ private void initApplicationContext(int count, boolean strict, int retryCount) {
springApplication.setWebApplicationType(WebApplicationType.NONE);
applicationContext = springApplication.run();
}

private void initApplicationContextTimeout(int count, boolean strict, int retryCount) {
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("memory-health-checker.count", count);
properties.put("memory-health-checker.strict", strict);
properties.put("memory-health-checker.retry-count", retryCount);
properties.put("spring.application.name", "HealthCheckerProcessorTest");
properties.put(SofaBootConstants.SOFABOOT_SKIP_COMPONENT_HEALTH_CHECK, true);
properties.put("com.alipay.sofa.boot.health-check-parallel-timeout", "1");

SpringApplication springApplication = new SpringApplication(
HealthCheckerProcessorTestConfiguration.class);
springApplication.setDefaultProperties(properties);
springApplication.setWebApplicationType(WebApplicationType.NONE);
applicationContext = springApplication.run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.alipay.sofa.healthcheck.test;

import com.alipay.sofa.boot.constant.SofaBootConstants;
import com.alipay.sofa.healthcheck.AfterReadinessCheckCallbackProcessor;
import com.alipay.sofa.healthcheck.HealthCheckProperties;
import com.alipay.sofa.healthcheck.HealthCheckerProcessor;
Expand All @@ -30,6 +31,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -121,10 +123,39 @@ public void testCheckIndicatorFailed() {
Assert.assertEquals(2, hashMap.size());
}

@Test
public void testCheckIndicatorParallelTimeout() {
initApplicationContextTimeout();
ReadinessCheckListener readinessCheckListener = applicationContext
.getBean(ReadinessCheckListener.class);
Health health = readinessCheckListener.aggregateReadinessHealth();
Health healthIndicatorInfo = (Health) health.getDetails().get("HealthIndicatorInfo");
Health timeoutHealth = (Health) healthIndicatorInfo.getDetails().get(
SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY);
Assert.assertEquals(Status.DOWN, health.getStatus());
Assert.assertEquals(Status.UNKNOWN, timeoutHealth.getStatus());
Assert.assertEquals(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_MSG, timeoutHealth
.getDetails().get(SofaBootConstants.SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY));
}

private void initApplicationContext(boolean health) {
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("disk-health-indicator.health", health);
properties.put("spring.application.name", "HealthIndicatorCheckProcessorTest");
properties.put(SofaBootConstants.SOFABOOT_SKIP_HEALTH_INDICATOR_CHECK, "true");
SpringApplication springApplication = new SpringApplication(
HealthIndicatorConfiguration.class);
springApplication.setDefaultProperties(properties);
springApplication.setWebApplicationType(WebApplicationType.NONE);
applicationContext = springApplication.run();
}

private void initApplicationContextTimeout() {
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("disk-health-indicator.health", true);
properties.put("spring.application.name", "HealthIndicatorCheckProcessorTest");
// properties.put(SofaBootConstants.SOFABOOT_SKIP_HEALTH_INDICATOR_CHECK, "true");
properties.put("com.alipay.sofa.boot.health-check-parallel-timeout", "1");
SpringApplication springApplication = new SpringApplication(
HealthIndicatorConfiguration.class);
springApplication.setDefaultProperties(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@
*/
package com.alipay.sofa.healthcheck.test;

import com.alipay.sofa.healthcheck.AfterReadinessCheckCallbackProcessor;
import com.alipay.sofa.healthcheck.HealthCheckProperties;
import com.alipay.sofa.healthcheck.HealthCheckerProcessor;
import com.alipay.sofa.healthcheck.HealthIndicatorProcessor;
import com.alipay.sofa.healthcheck.ReadinessCheckListener;
import com.alipay.sofa.healthcheck.core.HealthCheckExecutor;
import com.alipay.sofa.healthcheck.test.bean.DiskHealthIndicator;
import com.alipay.sofa.healthcheck.test.bean.MemoryHealthChecker;
import com.alipay.sofa.healthcheck.test.bean.MiddlewareHealthCheckCallback;
import com.alipay.sofa.runtime.SofaRuntimeProperties;
import com.alipay.sofa.runtime.configure.SofaRuntimeConfigurationProperties;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.BeansException;
Expand All @@ -40,13 +49,9 @@
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

import com.alipay.sofa.healthcheck.AfterReadinessCheckCallbackProcessor;
import com.alipay.sofa.healthcheck.HealthCheckerProcessor;
import com.alipay.sofa.healthcheck.HealthIndicatorProcessor;
import com.alipay.sofa.healthcheck.ReadinessCheckListener;
import com.alipay.sofa.healthcheck.test.bean.DiskHealthIndicator;
import com.alipay.sofa.healthcheck.test.bean.MemoryHealthChecker;
import com.alipay.sofa.healthcheck.test.bean.MiddlewareHealthCheckCallback;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.concurrent.ConcurrentHashMap;

/**
* @author liangen
Expand Down Expand Up @@ -120,6 +125,20 @@ public HealthCheckExecutor healthCheckExecutor(HealthCheckProperties properties)
}
}

@BeforeClass
public static void beforeClass() {
try {
Field f1 = SofaRuntimeProperties.class.getDeclaredField("manualReadinessCallbackMap");
f1.setAccessible(true);
Field modifiers = f1.getClass().getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(f1, f1.getModifiers() & ~Modifier.FINAL);
f1.set(SofaRuntimeProperties.class, new ConcurrentHashMap<>());
} catch (Exception e) {
System.out.println(e);
}
}

@Test
public void testReadinessCheck() throws BeansException {
ReadinessCheckListener readinessCheckListener = applicationContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,21 @@ public class SofaBootConstants {
*/
public static final String SOFABOOT_HEALTH_CHECK_NOT_READY_KEY = "HEALTH-CHECK-NOT-READY";

/**
* health check timeout key
*/
public static final String SOFABOOT_HEALTH_CHECK_TIMEOUT_KEY = "HEALTH-CHECK-TIMEOUT";

/**
* health check not ready result
*/
public static final String SOFABOOT_HEALTH_CHECK_NOT_READY_MSG = "App is still in startup process, please try later!";

/**
* health check timeout result
*/
public static final String SOFABOOT_HEALTH_CHECK_TIMEOUT_MSG = "Timeout when wait for readiness check result!";

/** framework constants **/
public static String APPLICATION = "SOFABOOT-APPLICATION";
public static String PROCESSORS_OF_ROOT_APPLICATION_CONTEXT = "PROCESSORS_OF_ROOT_APPLICATION_CONTEXT";
Expand Down