mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Polish alibaba/spring-cloud-alibaba#1739 : Sync the Sentinel from master
This commit is contained in:
parent
1040206269
commit
b2407823af
@ -94,4 +94,5 @@ public class ConsulDataSourceProperties extends AbstractDataSourceProperties {
|
|||||||
public void setWaitTimeoutInSecond(int waitTimeoutInSecond) {
|
public void setWaitTimeoutInSecond(int waitTimeoutInSecond) {
|
||||||
this.waitTimeoutInSecond = waitTimeoutInSecond;
|
this.waitTimeoutInSecond = waitTimeoutInSecond;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -88,4 +88,5 @@ public class ConsulDataSourceFactoryBean implements FactoryBean<ConsulDataSource
|
|||||||
public void setConverter(Converter converter) {
|
public void setConverter(Converter converter) {
|
||||||
this.converter = converter;
|
this.converter = converter;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,8 @@ public class SentinelSCGAutoConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initAppType() {
|
private void initAppType() {
|
||||||
System.setProperty(SentinelConfig.APP_TYPE, ConfigConstants.APP_TYPE_SCG_GATEWAY);
|
System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY,
|
||||||
|
ConfigConstants.APP_TYPE_SCG_GATEWAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initFallback() {
|
private void initFallback() {
|
||||||
|
@ -64,7 +64,7 @@ public class SentinelZuulAutoConfiguration {
|
|||||||
private void init() {
|
private void init() {
|
||||||
requestOriginParserOptional
|
requestOriginParserOptional
|
||||||
.ifPresent(ZuulGatewayCallbackManager::setOriginParser);
|
.ifPresent(ZuulGatewayCallbackManager::setOriginParser);
|
||||||
System.setProperty(SentinelConfig.APP_TYPE,
|
System.setProperty(SentinelConfig.APP_TYPE_PROP_KEY,
|
||||||
String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY));
|
String.valueOf(ConfigConstants.APP_TYPE_ZUUL_GATEWAY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,11 +103,6 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
|
||||||
<artifactId>spring-cloud-circuitbreaker-sentinel</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.csp</groupId>
|
<groupId>com.alibaba.csp</groupId>
|
||||||
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
|
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
|
||||||
|
@ -31,7 +31,6 @@ import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
|||||||
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
|
||||||
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
import com.alibaba.csp.sentinel.slots.system.SystemRule;
|
||||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||||
import com.alibaba.csp.sentinel.util.AppNameUtil;
|
|
||||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||||
|
@ -63,7 +63,7 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
|||||||
private SentinelProperties sentinelProperties;
|
private SentinelProperties sentinelProperties;
|
||||||
|
|
||||||
public SentinelHealthIndicator(DefaultListableBeanFactory beanFactory,
|
public SentinelHealthIndicator(DefaultListableBeanFactory beanFactory,
|
||||||
SentinelProperties sentinelProperties) {
|
SentinelProperties sentinelProperties) {
|
||||||
this.beanFactory = beanFactory;
|
this.beanFactory = beanFactory;
|
||||||
this.sentinelProperties = sentinelProperties;
|
this.sentinelProperties = sentinelProperties;
|
||||||
}
|
}
|
||||||
@ -150,4 +150,5 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
|||||||
builder.unknown().withDetails(detailMap);
|
builder.unknown().withDetails(detailMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,10 @@ import com.alibaba.csp.sentinel.config.SentinelConfig;
|
|||||||
import com.alibaba.csp.sentinel.log.LogBase;
|
import com.alibaba.csp.sentinel.log.LogBase;
|
||||||
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
import com.alibaba.csp.sentinel.slots.block.BlockException;
|
||||||
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
|
||||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
|
|
||||||
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||||
|
import com.alibaba.csp.sentinel.util.function.Tuple2;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -115,13 +114,6 @@ public class SentinelAutoConfigurationTests {
|
|||||||
rule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
|
rule.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_DEFAULT);
|
||||||
rule.setStrategy(RuleConstant.STRATEGY_DIRECT);
|
rule.setStrategy(RuleConstant.STRATEGY_DIRECT);
|
||||||
FlowRuleManager.loadRules(Arrays.asList(rule));
|
FlowRuleManager.loadRules(Arrays.asList(rule));
|
||||||
|
|
||||||
DegradeRule degradeRule = new DegradeRule();
|
|
||||||
degradeRule.setGrade(RuleConstant.DEGRADE_GRADE_EXCEPTION_COUNT);
|
|
||||||
degradeRule.setResource("GET:" + degradeUrl);
|
|
||||||
degradeRule.setCount(0);
|
|
||||||
degradeRule.setTimeWindow(60);
|
|
||||||
DegradeRuleManager.loadRules(Arrays.asList(degradeRule));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -142,7 +134,9 @@ public class SentinelAutoConfigurationTests {
|
|||||||
Map<String, Object> map = sentinelEndpoint.invoke();
|
Map<String, Object> map = sentinelEndpoint.invoke();
|
||||||
|
|
||||||
assertThat(map.get("logUsePid")).isEqualTo(Boolean.TRUE);
|
assertThat(map.get("logUsePid")).isEqualTo(Boolean.TRUE);
|
||||||
assertThat(map.get("consoleServer")).isEqualTo("http://localhost:8080");
|
assertThat(map.get("consoleServer").toString()).isEqualTo(
|
||||||
|
Arrays.asList(Tuple2.of("localhost", 8080), Tuple2.of("localhost", 8081))
|
||||||
|
.toString());
|
||||||
assertThat(map.get("clientPort")).isEqualTo("9999");
|
assertThat(map.get("clientPort")).isEqualTo("9999");
|
||||||
assertThat(map.get("heartbeatIntervalMs")).isEqualTo(20000L);
|
assertThat(map.get("heartbeatIntervalMs")).isEqualTo(20000L);
|
||||||
assertThat(map.get("clientIp")).isEqualTo("1.1.1.1");
|
assertThat(map.get("clientIp")).isEqualTo("1.1.1.1");
|
||||||
@ -174,7 +168,7 @@ public class SentinelAutoConfigurationTests {
|
|||||||
private void checkSentinelTransport() {
|
private void checkSentinelTransport() {
|
||||||
assertThat(sentinelProperties.getTransport().getPort()).isEqualTo("9999");
|
assertThat(sentinelProperties.getTransport().getPort()).isEqualTo("9999");
|
||||||
assertThat(sentinelProperties.getTransport().getDashboard())
|
assertThat(sentinelProperties.getTransport().getDashboard())
|
||||||
.isEqualTo("http://localhost:8080");
|
.isEqualTo("http://localhost:8080,http://localhost:8081");
|
||||||
assertThat(sentinelProperties.getTransport().getClientIp()).isEqualTo("1.1.1.1");
|
assertThat(sentinelProperties.getTransport().getClientIp()).isEqualTo("1.1.1.1");
|
||||||
assertThat(sentinelProperties.getTransport().getHeartbeatIntervalMs())
|
assertThat(sentinelProperties.getTransport().getHeartbeatIntervalMs())
|
||||||
.isEqualTo("20000");
|
.isEqualTo("20000");
|
||||||
@ -191,7 +185,9 @@ public class SentinelAutoConfigurationTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testSentinelSystemProperties() {
|
public void testSentinelSystemProperties() {
|
||||||
assertThat(LogBase.isLogNameUsePid()).isEqualTo(true);
|
assertThat(LogBase.isLogNameUsePid()).isEqualTo(true);
|
||||||
assertThat(TransportConfig.getConsoleServer()).isEqualTo("http://localhost:8080");
|
assertThat(TransportConfig.getConsoleServerList().toString()).isEqualTo(
|
||||||
|
Arrays.asList(Tuple2.of("localhost", 8080), Tuple2.of("localhost", 8081))
|
||||||
|
.toString());
|
||||||
assertThat(TransportConfig.getPort()).isEqualTo("9999");
|
assertThat(TransportConfig.getPort()).isEqualTo("9999");
|
||||||
assertThat(TransportConfig.getHeartbeatIntervalMs().longValue())
|
assertThat(TransportConfig.getHeartbeatIntervalMs().longValue())
|
||||||
.isEqualTo(20000L);
|
.isEqualTo(20000L);
|
||||||
@ -203,7 +199,7 @@ public class SentinelAutoConfigurationTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlowRestTemplate() {
|
public void testRestTemplateBlockHandler() {
|
||||||
|
|
||||||
assertThat(restTemplate.getInterceptors().size()).isEqualTo(2);
|
assertThat(restTemplate.getInterceptors().size()).isEqualTo(2);
|
||||||
assertThat(restTemplateWithBlockClass.getInterceptors().size()).isEqualTo(1);
|
assertThat(restTemplateWithBlockClass.getInterceptors().size()).isEqualTo(1);
|
||||||
@ -231,15 +227,6 @@ public class SentinelAutoConfigurationTests {
|
|||||||
}).isInstanceOf(RestClientException.class);
|
}).isInstanceOf(RestClientException.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFallbackRestTemplate() {
|
|
||||||
ResponseEntity responseEntity = restTemplateWithFallbackClass
|
|
||||||
.getForEntity(degradeUrl, String.class);
|
|
||||||
|
|
||||||
assertThat(responseEntity.getBody()).isEqualTo("Oops fallback");
|
|
||||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
static class SentinelTestConfiguration {
|
static class SentinelTestConfiguration {
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
* @author <a href="mailto:fangjian0423@gmail.com">Jim</a>
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = { SentinelBeanAutowiredTests.TestConfig.class },
|
@SpringBootTest(classes = { SentinelBeanAutowiredTests.TestConfig.class }, properties = {
|
||||||
properties = { "spring.cloud.sentinel.filter.order=111" })
|
"spring.cloud.sentinel.filter.order=111" })
|
||||||
public class SentinelBeanAutowiredTests {
|
public class SentinelBeanAutowiredTests {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -34,7 +34,7 @@ public class SidecarNacosDiscoveryProperties extends NacosDiscoveryProperties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws SocketException {
|
public void init() throws Exception {
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
String ip = sidecarProperties.getIp();
|
String ip = sidecarProperties.getIp();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user