Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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 Down Expand Up @@ -117,6 +119,14 @@ public void testReadinessCheckSuccessAndCallbackRun() {
Assert.assertTrue(applicationHealthCheckCallback.isMark());
}

@Test
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) {
Map<String, Object> properties = new LinkedHashMap<>();
properties.put("after-readiness-check-callback-a.health", health);
Expand All @@ -128,6 +138,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 @@ -42,4 +42,4 @@ public Health onHealthy(ApplicationContext applicationContext) {
return Health.down().withDetail("server", "server is bad").build();
}
}
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-plugins</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 @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-plugins</artifactId>
<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 @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-plugins</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 @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-starters</artifactId>
<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 @@ -22,7 +22,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-starters</artifactId>
<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 @@ -5,7 +5,7 @@
<parent>
<groupId>com.alipay.sofa</groupId>
<artifactId>sofa-boot-starters</artifactId>
<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 @@ -5,7 +5,7 @@
<parent>
<artifactId>sofa-boot-starters</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-starters/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