Skip to content

Commit

Permalink
2.5.0 Pre-Release (#239)
Browse files Browse the repository at this point in the history
* cherry pick 2.4.10 and 2.4.9
  • Loading branch information
QilongZhang authored and straybirdzls committed Oct 11, 2018
1 parent 62fa2c1 commit 7220151
Show file tree
Hide file tree
Showing 29 changed files with 252 additions and 361 deletions.
2 changes: 1 addition & 1 deletion healthcheck-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,65 @@ public class HealthCheckConstants {
/**
* skip all readiness check
*/
public static final String SOFABOOT_SKIP_ALL_HEALTH_CHECK = "com.alipay.sofa.healthcheck.skip.all";
public static final String SOFABOOT_SKIP_ALL_HEALTH_CHECK = "com.alipay.sofa.healthcheck.skip.all";

/**
* skip all {@link com.alipay.sofa.healthcheck.core.HealthChecker} readiness check
* skip all {@literal com.alipay.sofa.healthcheck.core.HealthChecker} readiness check
*/
public static final String SOFABOOT_SKIP_COMPONENT_HEALTH_CHECK = "com.alipay.sofa.healthcheck.skip.component";
public static final String SOFABOOT_SKIP_COMPONENT_HEALTH_CHECK = "com.alipay.sofa.healthcheck.skip.component";

/**
* skip all {@link org.springframework.boot.actuate.health.HealthIndicator} readiness check
* skip all {@literal org.springframework.boot.actuate.health.HealthIndicator} readiness check
*/
public static final String SOFABOOT_SKIP_HEALTH_INDICATOR_CHECK = "com.alipay.sofa.healthcheck.skip.indicator";
public static final String SOFABOOT_SKIP_HEALTH_INDICATOR_CHECK = "com.alipay.sofa.healthcheck.skip.indicator";

/**
* health check logging space
*/
public static final String SOFABOOT_HEALTH_LOG_SPACE = "com.alipay.sofa.healthcheck";
public static final String SOFABOOT_HEALTH_LOG_SPACE = "com.alipay.sofa.healthcheck";

/**
* readiness health check endpoint name
*/
public static final String READINESS_CHECK_ENDPOINT_NAME = "sofaboot_health_readiness";
public static final String READINESS_CHECK_ENDPOINT_NAME = "sofaboot_health_readiness";

/**
* {@literal com.alipay.sofa.runtime.spring.health.SofaComponentHealthChecker} retry count config.
*/
public static final String SOFABOOT_COMPONENT_CHECK_RETRY_COUNT = "com.alipay.sofa.healthcheck.component.check.retry.count";

/**
* default {@literal com.alipay.sofa.runtime.spring.health.SofaComponentHealthChecker} retry count value.
*/
public static final int SOFABOOT_COMPONENT_CHECK_RETRY_DEFAULT_COUNT = 20;

/**
* {@literal com.alipay.sofa.runtime.spring.health.SofaComponentHealthChecker} retry time interval config.
*/
public static final String SOFABOOT_COMPONENT_CHECK_RETRY_INTERVAL = "com.alipay.sofa.healthcheck.component.check.retry.interval";

/**
* default {@literal com.alipay.sofa.runtime.spring.health.SofaComponentHealthChecker} retry time interval value.
*/
public static final long SOFABOOT_COMPONENT_CHECK_RETRY_DEFAULT_INTERVAL = 1000;

/**
* {@literal com.alipay.sofa.isle.spring.health.SofaModuleHealthChecker} retry count config.
*/
public static final String SOFABOOT_MODULE_CHECK_RETRY_COUNT = "com.alipay.sofa.healthcheck.module.check.retry.count";

/**
* default {@literal com.alipay.sofa.isle.spring.health.SofaModuleHealthChecker} retry count value.
*/
public static final int SOFABOOT_MODULE_CHECK_RETRY_DEFAULT_COUNT = 0;

/**
* {@literal com.alipay.sofa.isle.spring.health.SofaModuleHealthChecker} retry time interval config.
*/
public static final String SOFABOOT_MODULE_CHECK_RETRY_INTERVAL = "com.alipay.sofa.healthcheck.module.check.retry.interval";

/**
* default {@literal com.alipay.sofa.isle.spring.health.SofaModuleHealthChecker} retry time interval value.
*/
public static final long SOFABOOT_MODULE_CHECK_RETRY_DEFAULT_INTERVAL = 1000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
* @author liangen
* @author qilong.zql
* @since 2.3.0
* @deprecated this class is not intended for use and will be removed the next major version.
* {@link org.springframework.boot.actuate.health.HealthIndicator} is recommended to use instead.
*/
@Deprecated
public interface HealthChecker {

/**
Expand Down
2 changes: 1 addition & 1 deletion infra-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion isle-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
* yangyanzhao Exp $
*/
public abstract class AbstractDeploymentDescriptor implements DeploymentDescriptor {
private final Properties properties;
private final DeploymentDescriptorConfiguration deploymentDescriptorConfiguration;
private final ClassLoader classLoader;
private final List<String> installedSpringXml = new ArrayList<>();
private ApplicationContext applicationContext;
private long startTime;
private long elapsedTime;
final URL url;
Map<String, Resource> springResources;
final Properties properties;
final DeploymentDescriptorConfiguration deploymentDescriptorConfiguration;
private final ClassLoader classLoader;
private final List<String> installedSpringXml = new ArrayList<>();
private ApplicationContext applicationContext;
private long startTime;
private long elapsedTime;
final URL url;
Map<String, Resource> springResources;

public AbstractDeploymentDescriptor(URL url,
Properties properties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*/
package com.alipay.sofa.isle.spring.health;

import com.alipay.sofa.healthcheck.configuration.HealthCheckConstants;
import com.alipay.sofa.healthcheck.core.HealthChecker;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.health.Health;

/**
Expand All @@ -25,6 +27,15 @@
* @author xuanbei 18/5/6
*/
public class SofaModuleHealthChecker extends AbstractModuleHealthChecker implements HealthChecker {

@Value("${" + HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_COUNT + ":"
+ HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_DEFAULT_COUNT + "}")
private int retryCount;

@Value("${" + HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_INTERVAL + ":"
+ HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_DEFAULT_INTERVAL + "}")
private long retryInterval;

@Override
public Health isHealthy() {
return doHealthCheck();
Expand All @@ -37,12 +48,12 @@ public String getComponentName() {

@Override
public int getRetryCount() {
return 0;
return retryCount;
}

@Override
public long getRetryTimeInterval() {
return 0;
return retryInterval;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.alipay.sofa.isle.integration;

import com.alipay.sofa.healthcheck.configuration.HealthCheckConstants;
import com.alipay.sofa.healthcheck.core.HealthChecker;
import com.alipay.sofa.isle.ApplicationRuntimeModel;
import com.alipay.sofa.isle.constants.SofaModuleFrameworkConstants;
Expand Down Expand Up @@ -99,8 +100,10 @@ public void testHealthChecker() {
.getBean("sofaModuleHealthChecker");
Assert.assertTrue(healthChecker.isHealthy().getStatus().equals(Status.UP));
Assert.assertEquals("SOFABoot-Modules", healthChecker.getComponentName());
Assert.assertEquals(0, healthChecker.getRetryCount());
Assert.assertEquals(0, healthChecker.getRetryTimeInterval());
Assert.assertEquals(HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_DEFAULT_COUNT,
healthChecker.getRetryCount());
Assert.assertEquals(HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_DEFAULT_INTERVAL,
healthChecker.getRetryTimeInterval());
Assert.assertEquals(true, healthChecker.isStrictCheck());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.isle.spring.health;

import com.alipay.sofa.healthcheck.configuration.HealthCheckConstants;
import com.alipay.sofa.isle.spring.configuration.SofaModuleAutoConfiguration;
import com.alipay.sofa.runtime.spring.configuration.SofaRuntimeAutoConfiguration;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.boot.test.util.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
* @author abby.zh
* @since 2.4.10
*/
public class SofaModuleHealthCheckerTest {

private final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

@After
public void closeContext() {
this.applicationContext.close();
}

@Test
public void testDefaultConfig() {
this.applicationContext.register(SofaModuleAutoConfiguration.class);
this.applicationContext.refresh();
SofaModuleHealthChecker sofaModuleHealthChecker = applicationContext
.getBean(SofaModuleHealthChecker.class);
Assert.assertEquals(HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_DEFAULT_COUNT,
sofaModuleHealthChecker.getRetryCount());
Assert.assertEquals(HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_DEFAULT_INTERVAL,
sofaModuleHealthChecker.getRetryTimeInterval());
}

@Test
public void testCustomConfig() {
int customRetryCount = 10;
int customRetryInterval = 30;
this.applicationContext.register(SofaModuleAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_COUNT + "=" + customRetryCount);
EnvironmentTestUtils.addEnvironment(this.applicationContext,
HealthCheckConstants.SOFABOOT_MODULE_CHECK_RETRY_INTERVAL + "=" + customRetryInterval);
this.applicationContext.register(SofaRuntimeAutoConfiguration.class);
this.applicationContext.refresh();
SofaModuleHealthChecker sofaModuleHealthChecker = applicationContext
.getBean(SofaModuleHealthChecker.class);
Assert.assertEquals(customRetryCount, sofaModuleHealthChecker.getRetryCount());
Assert.assertEquals(customRetryInterval, sofaModuleHealthChecker.getRetryTimeInterval());
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofaboot-dependencies</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
4 changes: 2 additions & 2 deletions runtime-sofa-boot-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand All @@ -37,7 +37,7 @@
<dependency>
<groupId>com.alipay.sofa</groupId>
<artifactId>runtime-sofa-boot-starter</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion runtime-sofa-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-runtime</artifactId>
<version>2.5.0-SNAPSHOT</version>
<version>2.5.0</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
*/
package com.alipay.sofa.runtime.spring.health;

import com.alipay.sofa.healthcheck.configuration.HealthCheckConstants;
import com.alipay.sofa.healthcheck.core.HealthChecker;
import com.alipay.sofa.runtime.spi.component.SofaRuntimeContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.health.Health;

/**
Expand All @@ -27,6 +29,15 @@
*/
public class SofaComponentHealthChecker extends AbstractComponentHealthChecker implements
HealthChecker {

@Value("${" + HealthCheckConstants.SOFABOOT_COMPONENT_CHECK_RETRY_COUNT + ":"
+ HealthCheckConstants.SOFABOOT_COMPONENT_CHECK_RETRY_DEFAULT_COUNT + "}")
private int retryCount;

@Value("${" + HealthCheckConstants.SOFABOOT_COMPONENT_CHECK_RETRY_INTERVAL + ":"
+ HealthCheckConstants.SOFABOOT_COMPONENT_CHECK_RETRY_DEFAULT_INTERVAL + "}")
private int retryInterval;

public SofaComponentHealthChecker(SofaRuntimeContext sofaRuntimeContext) {
super(sofaRuntimeContext);
}
Expand All @@ -43,12 +54,12 @@ public String getComponentName() {

@Override
public int getRetryCount() {
return 0;
return retryCount;
}

@Override
public long getRetryTimeInterval() {
return 0;
return retryInterval;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.alipay.sofa.runtime.integration;

import com.alipay.sofa.healthcheck.configuration.HealthCheckConstants;
import com.alipay.sofa.healthcheck.core.HealthChecker;
import com.alipay.sofa.runtime.beans.service.SampleService;
import com.alipay.sofa.runtime.integration.aop.SampleServiceAspect;
Expand Down Expand Up @@ -62,8 +63,10 @@ public void testHealthChecker() {
HealthChecker healthChecker = (HealthChecker) context.getBean("sofaComponentHealthChecker");
Assert.assertTrue(healthChecker.isHealthy().getStatus().equals(Status.UP));
Assert.assertEquals("SOFABoot-Components", healthChecker.getComponentName());
Assert.assertEquals(0, healthChecker.getRetryCount());
Assert.assertEquals(0, healthChecker.getRetryTimeInterval());
Assert.assertEquals(HealthCheckConstants.SOFABOOT_COMPONENT_CHECK_RETRY_DEFAULT_COUNT,
healthChecker.getRetryCount());
Assert.assertEquals(HealthCheckConstants.SOFABOOT_COMPONENT_CHECK_RETRY_DEFAULT_INTERVAL,
healthChecker.getRetryTimeInterval());
Assert.assertEquals(true, healthChecker.isStrictCheck());
}

Expand Down

0 comments on commit 7220151

Please sign in to comment.