Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

SOFABoot 是蚂蚁金服开源的基于 Spring Boot 的研发框架,它在 Spring Boot 的基础上,提供了诸如 Readiness Check,类隔离,日志空间隔离等等能力。在增强了 Spring Boot 的同时,SOFABoot 提供了让用户可以在 Spring Boot 中非常方便地使用 SOFA 中间件的能力。

## 3.0.0 🎉🎉🎉
SOFABoot 3.0.0 已经发布,该版本基于 Spring Boot 2.0.3.RELEASE 开发,并兼容 Spring Cloud。除此之外,SOFABoot 3.0.0 增加了支持 ReactiveHealthIndicator 健康检查扩展,支持 WebFlux 请求埋点等新功能,欢迎试用新版本。

## 一、背景

Spring Boot 是一个非常优秀的开源框架,可以非常方便地就构建出一个基于 Spring 的应用程序,但是在使用过程中,还是会遇到一些问题:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-build</artifactId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>SOFABoot Build</name>
<description>SOFABoot Build</description>
Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-build</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-actuator-autoconfigure/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-parent</artifactId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
<relativePath>../sofa-boot-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-actuator/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-parent</artifactId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
<relativePath>../sofa-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-autoconfigure/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-parent</artifactId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
<relativePath>../sofa-boot-parent</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,24 @@ public boolean afterReadinessCheckCallback(Map<String, Health> healthMap) {
logger.info("Begin ReadinessCheckCallback readiness check");
Assert.notNull(readinessCheckCallbacks, "ReadinessCheckCallbacks must not be null.");

boolean result = readinessCheckCallbacks.entrySet().stream()
.map(entry -> doHealthCheckCallback(entry.getKey(), entry.getValue(), healthMap))
.reduce(true, BinaryOperators.andBoolean());
boolean allResult = true;
for (Map.Entry<String, ReadinessCheckCallback> entry : readinessCheckCallbacks.entrySet()) {
String beanId = entry.getKey();
if (allResult) {
if (!doHealthCheckCallback(beanId, entry.getValue(), healthMap)) {
allResult = false;
}
} else {
healthMap.put(beanId, Health.down().withDetail("invoking", "skipped").build());
}
}

if (result) {
if (allResult) {
logger.info("ReadinessCheckCallback readiness check result: success.");
} else {
logger.error("ReadinessCheckCallback readiness check result: failed.");
}
return result;
return allResult;
}

private boolean doHealthCheckCallback(String beanId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@

import com.alipay.sofa.healthcheck.HealthCheckProperties;
import com.alipay.sofa.healthcheck.core.HealthChecker;
import com.alipay.sofa.healthcheck.test.bean.ApplicationHealthCheckCallback;
import com.alipay.sofa.healthcheck.test.bean.FailedHealthCheck;
import com.alipay.sofa.healthcheck.test.bean.HighestOrderReadinessCheckCallback;
import com.alipay.sofa.healthcheck.test.bean.LowestOrderReadinessCheckCallback;
import com.alipay.sofa.healthcheck.test.bean.MiddlewareHealthCheckCallback;
import com.alipay.sofa.healthcheck.test.bean.SuccessHealthCheck;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -40,8 +44,6 @@
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.ApplicationHealthCheckCallback;
import com.alipay.sofa.healthcheck.test.bean.MiddlewareHealthCheckCallback;

/**
* @author liangen
Expand All @@ -64,17 +66,17 @@ public void testAfterReadinessCheckCallbackMarked() {
boolean result = afterReadinessCheckCallbackProcessor.afterReadinessCheckCallback(hashMap);
Assert.assertTrue(result);
Assert.assertTrue(applicationHealthCheckCallback.isMark());
Assert.assertTrue(hashMap.size() == 2);
Assert.assertEquals(2, hashMap.size());
Health middleHealth = hashMap.get("middlewareHealthCheckCallback");
Health applicationHealth = hashMap.get("applicationHealthCheckCallback");
Assert.assertNotNull(middleHealth);
Assert.assertNotNull(applicationHealth);
Assert.assertTrue(middleHealth.getStatus().equals(Status.UP));
Assert.assertTrue(applicationHealth.getStatus().equals(Status.UP));
Assert.assertTrue(middleHealth.getDetails().size() == 1);
Assert.assertTrue(applicationHealth.getDetails().size() == 1);
Assert.assertTrue("server is ok".equals(middleHealth.getDetails().get("server")));
Assert.assertTrue("port is ok".equals(applicationHealth.getDetails().get("port")));
Assert.assertEquals(middleHealth.getStatus(), Status.UP);
Assert.assertEquals(applicationHealth.getStatus(), Status.UP);
Assert.assertEquals(1, middleHealth.getDetails().size());
Assert.assertEquals(1, applicationHealth.getDetails().size());
Assert.assertEquals("server is ok", middleHealth.getDetails().get("server"));
Assert.assertEquals("port is ok", applicationHealth.getDetails().get("port"));
}

@Test
Expand All @@ -88,17 +90,17 @@ public void testAfterReadinessCheckCallbackUnMarked() {
HashMap<String, Health> hashMap = new HashMap<>();
boolean result = afterReadinessCheckCallbackProcessor.afterReadinessCheckCallback(hashMap);
Assert.assertFalse(result);
Assert.assertTrue(applicationHealthCheckCallback.isMark());
Assert.assertTrue(hashMap.size() == 2);
Assert.assertFalse(applicationHealthCheckCallback.isMark());
Assert.assertEquals(2, hashMap.size());
Health middleHealth = hashMap.get("middlewareHealthCheckCallback");
Health applicationHealth = hashMap.get("applicationHealthCheckCallback");
Assert.assertNotNull(middleHealth);
Assert.assertNotNull(applicationHealth);
Assert.assertTrue(middleHealth.getStatus().equals(Status.DOWN));
Assert.assertTrue(applicationHealth.getStatus().equals(Status.UP));
Assert.assertTrue(middleHealth.getDetails().size() == 1);
Assert.assertTrue("server is bad".equals(middleHealth.getDetails().get("server")));
Assert.assertTrue("port is ok".equals(applicationHealth.getDetails().get("port")));
Assert.assertEquals(middleHealth.getStatus(), Status.DOWN);
Assert.assertEquals(applicationHealth.getStatus(), Status.DOWN);
Assert.assertEquals(1, middleHealth.getDetails().size());
Assert.assertEquals("server is bad", middleHealth.getDetails().get("server"));
Assert.assertEquals("skipped", applicationHealth.getDetails().get("invoking"));
}

@Test
Expand All @@ -110,11 +112,11 @@ public void testReadinessCheckFailedAndCallbackNotRun() {
}

@Test
public void testReadinessCheckSuccessAndCallbackRun() {
initApplicationContext(false, false, ReadinessCheckSuccessTestConfiguration.class);
ApplicationHealthCheckCallback applicationHealthCheckCallback = ctx
.getBean(ApplicationHealthCheckCallback.class);
Assert.assertTrue(applicationHealthCheckCallback.isMark());
public void testBreakingReadinessCheckCallback() {
initApplicationContext(false, false, ReadinessCheckCallbackBreakTestConfiguration.class);
LowestOrderReadinessCheckCallback callback = ctx
.getBean(LowestOrderReadinessCheckCallback.class);
Assert.assertFalse(callback.getMark());
}

private void initApplicationContext(boolean health, boolean mark, Class clazz) {
Expand All @@ -128,6 +130,20 @@ private void initApplicationContext(boolean health, boolean mark, Class clazz) {
ctx = springApplication.run();
}

@Configuration
static class ReadinessCheckCallbackBreakTestConfiguration extends
AfterHealthReadinessCheckCallbackTestConfiguration {
@Bean
public HighestOrderReadinessCheckCallback highestOrderReadinessCheckCallback() {
return new HighestOrderReadinessCheckCallback();
}

@Bean
public LowestOrderReadinessCheckCallback lowestOrderReadinessCheckCallback() {
return new LowestOrderReadinessCheckCallback();
}
}

@Configuration
@EnableConfigurationProperties(HealthCheckProperties.class)
static class AfterHealthReadinessCheckCallbackTestConfiguration {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.healthcheck.test.bean;

import com.alipay.sofa.healthcheck.startup.ReadinessCheckCallback;
import org.springframework.boot.actuate.health.Health;
import org.springframework.context.ApplicationContext;
import org.springframework.core.PriorityOrdered;

/**
* @author <a href="mailto:[email protected]">Alaneuler</a>
* Created on 2020/7/23
*/
public class HighestOrderReadinessCheckCallback implements ReadinessCheckCallback, PriorityOrdered {
@Override
public Health onHealthy(ApplicationContext applicationContext) {
return Health.down().build();
}

@Override
public int getOrder() {
return PriorityOrdered.HIGHEST_PRECEDENCE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.healthcheck.test.bean;

import com.alipay.sofa.healthcheck.startup.ReadinessCheckCallback;
import org.springframework.boot.actuate.health.Health;
import org.springframework.context.ApplicationContext;
import org.springframework.core.PriorityOrdered;

/**
* @author <a href="mailto:[email protected]">Alaneuler</a>
* Created on 2020/7/23
*/
public class LowestOrderReadinessCheckCallback implements ReadinessCheckCallback, PriorityOrdered {
private boolean mark = false;

public boolean getMark() {
return mark;
}

@Override
public Health onHealthy(ApplicationContext applicationContext) {
mark = true;
return Health.up().build();
}

@Override
public int getOrder() {
return PriorityOrdered.LOWEST_PRECEDENCE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import org.springframework.context.ApplicationContext;

import com.alipay.sofa.healthcheck.startup.ReadinessCheckCallback;
import org.springframework.core.PriorityOrdered;

/**
* @author liangen
* @author qilong.zql
* @version 2.3.0
*/
public class MiddlewareHealthCheckCallback implements ReadinessCheckCallback {
public class MiddlewareHealthCheckCallback implements ReadinessCheckCallback, PriorityOrdered {

private boolean health;

Expand All @@ -42,4 +43,9 @@ public Health onHealthy(ApplicationContext applicationContext) {
return Health.down().withDetail("server", "server is bad").build();
}
}
}

@Override
public int getOrder() {
return PriorityOrdered.HIGHEST_PRECEDENCE;
}
}
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-core/isle-sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-core/log-sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-core/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-parent</artifactId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
<relativePath>../sofa-boot-parent</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-core/rpc-sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-core/runtime-sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-core/test-sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-core/tracer-sofa-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-core</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofaboot-dependencies</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
<relativePath>../sofaboot-dependencies</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion sofa-boot-project/sofa-boot-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-parent</artifactId>
<groupId>com.alipay.sofa</groupId>
<version>3.4.1</version>
<version>3.4.2-SNAPSHOT</version>
<relativePath>../sofa-boot-parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Loading