|
|
@ -18,6 +18,7 @@ package com.alibaba.cloud.sentinel.custom;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.cloud.commons.lang.StringUtils;
|
|
|
|
import com.alibaba.cloud.sentinel.SentinelProperties;
|
|
|
|
import com.alibaba.cloud.sentinel.SentinelProperties;
|
|
|
|
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
|
|
|
|
import com.alibaba.cloud.sentinel.datasource.converter.JsonConverter;
|
|
|
|
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
|
|
|
|
import com.alibaba.cloud.sentinel.datasource.converter.XmlConverter;
|
|
|
@ -46,7 +47,6 @@ import org.springframework.context.ApplicationContext;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.core.env.Environment;
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static com.alibaba.cloud.sentinel.SentinelConstants.BLOCK_PAGE_URL_CONF_KEY;
|
|
|
|
import static com.alibaba.cloud.sentinel.SentinelConstants.BLOCK_PAGE_URL_CONF_KEY;
|
|
|
|
import static com.alibaba.csp.sentinel.config.SentinelConfig.setConfig;
|
|
|
|
import static com.alibaba.csp.sentinel.config.SentinelConfig.setConfig;
|
|
|
@ -70,7 +70,7 @@ public class SentinelAutoConfiguration {
|
|
|
|
@PostConstruct
|
|
|
|
@PostConstruct
|
|
|
|
private void init() {
|
|
|
|
private void init() {
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_DIR))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_DIR))
|
|
|
|
&& StringUtils.hasText(properties.getLog().getDir())) {
|
|
|
|
&& StringUtils.isNotBlank(properties.getLog().getDir())) {
|
|
|
|
System.setProperty(LogBase.LOG_DIR, properties.getLog().getDir());
|
|
|
|
System.setProperty(LogBase.LOG_DIR, properties.getLog().getDir());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_NAME_USE_PID))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_NAME_USE_PID))
|
|
|
@ -79,53 +79,53 @@ public class SentinelAutoConfiguration {
|
|
|
|
String.valueOf(properties.getLog().isSwitchPid()));
|
|
|
|
String.valueOf(properties.getLog().isSwitchPid()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.APP_NAME_PROP_KEY))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.APP_NAME_PROP_KEY))
|
|
|
|
&& StringUtils.hasText(projectName)) {
|
|
|
|
&& StringUtils.isNotBlank(projectName)) {
|
|
|
|
System.setProperty(SentinelConfig.APP_NAME_PROP_KEY, projectName);
|
|
|
|
System.setProperty(SentinelConfig.APP_NAME_PROP_KEY, projectName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.SERVER_PORT))
|
|
|
|
&& StringUtils.hasText(properties.getTransport().getPort())) {
|
|
|
|
&& StringUtils.isNotBlank(properties.getTransport().getPort())) {
|
|
|
|
System.setProperty(TransportConfig.SERVER_PORT,
|
|
|
|
System.setProperty(TransportConfig.SERVER_PORT,
|
|
|
|
properties.getTransport().getPort());
|
|
|
|
properties.getTransport().getPort());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.CONSOLE_SERVER))
|
|
|
|
&& StringUtils.hasText(properties.getTransport().getDashboard())) {
|
|
|
|
&& StringUtils.isNotBlank(properties.getTransport().getDashboard())) {
|
|
|
|
System.setProperty(TransportConfig.CONSOLE_SERVER,
|
|
|
|
System.setProperty(TransportConfig.CONSOLE_SERVER,
|
|
|
|
properties.getTransport().getDashboard());
|
|
|
|
properties.getTransport().getDashboard());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_INTERVAL_MS))
|
|
|
|
&& StringUtils
|
|
|
|
&& StringUtils
|
|
|
|
.hasText(properties.getTransport().getHeartbeatIntervalMs())) {
|
|
|
|
.isNotBlank(properties.getTransport().getHeartbeatIntervalMs())) {
|
|
|
|
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS,
|
|
|
|
System.setProperty(TransportConfig.HEARTBEAT_INTERVAL_MS,
|
|
|
|
properties.getTransport().getHeartbeatIntervalMs());
|
|
|
|
properties.getTransport().getHeartbeatIntervalMs());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_CLIENT_IP))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(TransportConfig.HEARTBEAT_CLIENT_IP))
|
|
|
|
&& StringUtils.hasText(properties.getTransport().getClientIp())) {
|
|
|
|
&& StringUtils.isNotBlank(properties.getTransport().getClientIp())) {
|
|
|
|
System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP,
|
|
|
|
System.setProperty(TransportConfig.HEARTBEAT_CLIENT_IP,
|
|
|
|
properties.getTransport().getClientIp());
|
|
|
|
properties.getTransport().getClientIp());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
|
|
|
|
&& StringUtils.hasText(properties.getMetric().getCharset())) {
|
|
|
|
&& StringUtils.isNotBlank(properties.getMetric().getCharset())) {
|
|
|
|
System.setProperty(SentinelConfig.CHARSET,
|
|
|
|
System.setProperty(SentinelConfig.CHARSET,
|
|
|
|
properties.getMetric().getCharset());
|
|
|
|
properties.getMetric().getCharset());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils
|
|
|
|
if (StringUtils
|
|
|
|
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
|
|
|
|
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
|
|
|
|
&& StringUtils.hasText(properties.getMetric().getFileSingleSize())) {
|
|
|
|
&& StringUtils.isNotBlank(properties.getMetric().getFileSingleSize())) {
|
|
|
|
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE,
|
|
|
|
System.setProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE,
|
|
|
|
properties.getMetric().getFileSingleSize());
|
|
|
|
properties.getMetric().getFileSingleSize());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils
|
|
|
|
if (StringUtils
|
|
|
|
.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT))
|
|
|
|
.isEmpty(System.getProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT))
|
|
|
|
&& StringUtils.hasText(properties.getMetric().getFileTotalCount())) {
|
|
|
|
&& StringUtils.isNotBlank(properties.getMetric().getFileTotalCount())) {
|
|
|
|
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT,
|
|
|
|
System.setProperty(SentinelConfig.TOTAL_METRIC_FILE_COUNT,
|
|
|
|
properties.getMetric().getFileTotalCount());
|
|
|
|
properties.getMetric().getFileTotalCount());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR))
|
|
|
|
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.COLD_FACTOR))
|
|
|
|
&& StringUtils.hasText(properties.getFlow().getColdFactor())) {
|
|
|
|
&& StringUtils.isNotBlank(properties.getFlow().getColdFactor())) {
|
|
|
|
System.setProperty(SentinelConfig.COLD_FACTOR,
|
|
|
|
System.setProperty(SentinelConfig.COLD_FACTOR,
|
|
|
|
properties.getFlow().getColdFactor());
|
|
|
|
properties.getFlow().getColdFactor());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (StringUtils.hasText(properties.getBlockPage())) {
|
|
|
|
if (StringUtils.isNotBlank(properties.getBlockPage())) {
|
|
|
|
setConfig(BLOCK_PAGE_URL_CONF_KEY, properties.getBlockPage());
|
|
|
|
setConfig(BLOCK_PAGE_URL_CONF_KEY, properties.getBlockPage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|