Foreword
Last week (2020.02.12) we wrote an article on "Spring Cloud Alibaba V2.2.0 release" characteristics related, v2.2.0
is based on the Spring Cloud Hoxton
version. The following summarize the Spring Cloud Alibaba v2.1.0
upgrade to v2.2.0
the problems encountered.
The main issues involved sentinel
in the issue.
Destructive, not backward compatible
Spring Cloud Alibaba Sentinel
No longer dependent on sentinel-web-servlet
implementation, but rather rely on sentinel-spring-webmvc-dapter
Spring-based Interceptor
interceptors resources, instead CommonFilter
.
Downgrade policy modification
Found that implements the interface changes
// 之前版本
public class PigxUrlBlockHandler implements UrlBlockHandler {
@Override
public void blocked(HttpServletRequest request, HttpServletResponse response, BlockException e) throws IOException {
// 降级业务处理
}
}
// v2.2.0
public class PigxUrlBlockHandler implements BlockExceptionHandler {
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
// 降级业务处理
}
}复制代码
Request parser
The package implements the interface changes
//旧版本
import com.alibaba.csp.sentinel.adapter.servlet.callback.RequestOriginParser;
// v2.2.0
import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
// 请求解析器实现
public class PigxHeaderRequestOriginParser implements RequestOriginParser {
private static final String ALLOW = "Allow";
@Override
public String parseOrigin(HttpServletRequest request) {
return request.getHeader(ALLOW);
}
}复制代码
By default, only interception /*
request
Mentioned above V2.2.0
is based on the Interceptor
realization, the default rule for the interception /*
, which is the only request URI is /, / a sentinel request can be processed, dashboard
it will only display the intercepted resource, need to configure blocking rules. This issue has been submitted to us pull request
fix Modify the sentinelInterceptor default interception rule and backward
spring:
cloud:
sentinel:
filter:
url-patterns: /**复制代码
Involved Source: SentinelWebAutoConfiguration.addInterceptors()
Default: spring boot admin
displayed as part of the service down
, the console will display only part of the service
Access Services IP:PORT/actuator/health
display sentinel state down
, by default sentinel is lazy loaded at startup will not immediately to sentinel-server
send heartbeat, leading to SentinelHealthIndicator
a state ruled false
, leading to Spring Boot Admin
read actuator
informationdown
Hunger can be set to load, it will be loaded at startup to load, and send the heartbeat
spring:
cloud:
sentinel:
eager: true复制代码
Source can refer: SentinelAutoConfiguration.init()
by SPI
loading a corresponding service
to sum up
Spring Cloud Alibaba Sentinel
Source module, the processing logic read relatively straightforward recommendations. The core is the initialization sentinel
of dapter
, and injected the default demotion or the like.