diff --git a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/SentinelProperties.java b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/SentinelProperties.java index 3f91a3b0b..bd7120957 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/SentinelProperties.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/SentinelProperties.java @@ -22,6 +22,9 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.core.Ordered; +import com.alibaba.csp.sentinel.config.SentinelConfig; +import com.alibaba.csp.sentinel.transport.config.TransportConfig; + /** * @author xiaojing * @author hengyunabc @@ -31,44 +34,50 @@ import org.springframework.core.Ordered; public class SentinelProperties { /** - * 是否提前初始化心跳连接 + * earlier initialize heart-beat when the spring container starts when the + * transport dependency is on classpath ,the configuration is effective */ private boolean eager = false; /** - * Enable sentinel auto configure, the default value is true + * enable sentinel auto configure, the default value is true */ private boolean enabled = true; /** - * 字符编码集 + * charset when sentinel write or search metric file {@link SentinelConfig#CHARSET} */ private String charset = "UTF-8"; /** - * 通信相关配置 + * transport configuration about dashboard and client */ @NestedConfigurationProperty private Transport transport = new Transport(); /** - * 监控数据相关配置 + * metric configuration about resource */ @NestedConfigurationProperty private Metric metric = new Metric(); /** - * web 相关配置 + * web servlet configuration when the application is web ,the configuration is + * effective */ @NestedConfigurationProperty private Servlet servlet = new Servlet(); /** - * 限流相关 + * sentinel filter when the application is web ,the configuration is effective + * */ @NestedConfigurationProperty private Filter filter = new Filter(); + /** + * flow configuration + */ @NestedConfigurationProperty private Flow flow = new Flow(); @@ -139,7 +148,7 @@ public class SentinelProperties { public static class Flow { /** - * 限流冷启动因子 + * the cold factor {@link SentinelConfig#COLD_FACTOR} */ private String coldFactor = "3"; @@ -156,7 +165,7 @@ public class SentinelProperties { public static class Servlet { /** - * url 限流后的处理页面 + * The process page when the flow control is triggered */ private String blockPage; @@ -172,12 +181,12 @@ public class SentinelProperties { public static class Metric { /** - * 监控数据写磁盘时单个文件的大小 + * the metric file size {@link SentinelConfig#SINGLE_METRIC_FILE_SIZE} */ private String fileSingleSize; /** - * 监控数据在磁盘上的总数量 + * the total metric file count {@link SentinelConfig#TOTAL_METRIC_FILE_COUNT} */ private String fileTotalCount; @@ -201,18 +210,19 @@ public class SentinelProperties { public static class Transport { /** - * sentinel api port,default value is 8721 + * sentinel api port,default value is 8721 {@link TransportConfig#SERVER_PORT} */ private String port = "8721"; /** - * Sentinel dashboard address, won't try to connect dashboard when address is - * empty + * sentinel dashboard address, won't try to connect dashboard when address is + * empty {@link TransportConfig#CONSOLE_SERVER} */ private String dashboard = ""; /** - * 客户端和DashBord心跳发送时间 + * send heartbeat interval millisecond + * {@link TransportConfig#HEARTBEAT_INTERVAL_MS} */ private String heartbeatIntervalMs; @@ -245,7 +255,7 @@ public class SentinelProperties { public static class Filter { /** - * Sentinel filter chain order. + * sentinel filter chain order. */ private int order = Ordered.HIGHEST_PRECEDENCE; diff --git a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelAutoConfiguration.java b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelAutoConfiguration.java index ce0e7a910..2f0ef6084 100644 --- a/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelAutoConfiguration.java +++ b/spring-cloud-alibaba-sentinel/src/main/java/org/springframework/cloud/alibaba/sentinel/custom/SentinelAutoConfiguration.java @@ -32,7 +32,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; -import com.alibaba.csp.sentinel.Env; import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlBlockHandler; import com.alibaba.csp.sentinel.adapter.servlet.callback.UrlCleaner; import com.alibaba.csp.sentinel.adapter.servlet.callback.WebCallbackManager; @@ -40,7 +39,6 @@ import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig; import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect; import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.init.InitExecutor; -import com.alibaba.csp.sentinel.node.NodeBuilder; import com.alibaba.csp.sentinel.transport.config.TransportConfig; import com.alibaba.csp.sentinel.util.AppNameUtil; @@ -68,7 +66,8 @@ public class SentinelAutoConfiguration { @PostConstruct private void init() { - if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))) { + if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME)) + && StringUtils.hasText(projectName)) { System.setProperty(AppNameUtil.APP_NAME, projectName); } if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT)) @@ -115,11 +114,9 @@ public class SentinelAutoConfiguration { urlBlockHandlerOptional.ifPresent(WebCallbackManager::setUrlBlockHandler); urlCleanerOptional.ifPresent(WebCallbackManager::setUrlCleaner); - InitExecutor.doInit(); - // earlier initialize if (properties.isEager()) { - NodeBuilder nodeBuilder = Env.nodeBuilder; + InitExecutor.doInit(); } } diff --git a/spring-cloud-alibaba-sentinel/src/test/java/org/springframework/cloud/alibaba/sentinel/SentinelAutoConfigurationTests.java b/spring-cloud-alibaba-sentinel/src/test/java/org/springframework/cloud/alibaba/sentinel/SentinelAutoConfigurationTests.java index 521e7d7c9..647fde936 100644 --- a/spring-cloud-alibaba-sentinel/src/test/java/org/springframework/cloud/alibaba/sentinel/SentinelAutoConfigurationTests.java +++ b/spring-cloud-alibaba-sentinel/src/test/java/org/springframework/cloud/alibaba/sentinel/SentinelAutoConfigurationTests.java @@ -34,13 +34,14 @@ import com.alibaba.csp.sentinel.slots.block.BlockException; /** * @author fangjian + * @author jiashuai.xie */ public class SentinelAutoConfigurationTests { private WebApplicationContextRunner contextRunner = new WebApplicationContextRunner() .withConfiguration(AutoConfigurations.of(SentinelAutoConfiguration.class, SentinelWebAutoConfiguration.class, SentinelTestConfiguration.class)) - .withPropertyValues("spring.cloud.sentinel.port=8888") + .withPropertyValues("spring.cloud.sentinel.transport.port=8888") .withPropertyValues("spring.cloud.sentinel.filter.order=123") .withPropertyValues("spring.cloud.sentinel.filter.urlPatterns=/*,/test");