1
0
mirror of https://gitee.com/mirrors/Spring-Cloud-Alibaba.git synced 2021-06-26 13:25:11 +08:00

Add log configuration for Sentinel

This commit is contained in:
fangjian0423 2018-12-06 16:09:32 +08:00
parent cd6f79b16b
commit ac2eee154d
3 changed files with 90 additions and 23 deletions

View File

@ -26,6 +26,7 @@ import org.springframework.cloud.alibaba.sentinel.datasource.config.DataSourcePr
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.log.LogBase;
import com.alibaba.csp.sentinel.transport.config.TransportConfig; import com.alibaba.csp.sentinel.transport.config.TransportConfig;
/** /**
@ -48,11 +49,6 @@ public class SentinelProperties {
*/ */
private boolean enabled = true; private boolean enabled = true;
/**
* charset when sentinel write or search metric file {@link SentinelConfig#CHARSET}
*/
private String charset = "UTF-8";
/** /**
* configurations about datasource, like 'nacos', 'apollo', 'file', 'zookeeper' * configurations about datasource, like 'nacos', 'apollo', 'file', 'zookeeper'
*/ */
@ -91,6 +87,12 @@ public class SentinelProperties {
@NestedConfigurationProperty @NestedConfigurationProperty
private Flow flow = new Flow(); private Flow flow = new Flow();
/**
* sentinel log configuration {@link LogBase}
*/
@NestedConfigurationProperty
private Log log = new Log();
public boolean isEager() { public boolean isEager() {
return eager; return eager;
} }
@ -107,14 +109,6 @@ public class SentinelProperties {
this.flow = flow; this.flow = flow;
} }
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public Transport getTransport() { public Transport getTransport() {
return transport; return transport;
} }
@ -163,6 +157,14 @@ public class SentinelProperties {
this.datasource = datasource; this.datasource = datasource;
} }
public Log getLog() {
return log;
}
public void setLog(Log log) {
this.log = log;
}
public static class Flow { public static class Flow {
/** /**
@ -208,6 +210,12 @@ public class SentinelProperties {
*/ */
private String fileTotalCount; private String fileTotalCount;
/**
* charset when sentinel write or search metric file
* {@link SentinelConfig#CHARSET}
*/
private String charset = "UTF-8";
public String getFileSingleSize() { public String getFileSingleSize() {
return fileSingleSize; return fileSingleSize;
} }
@ -223,6 +231,14 @@ public class SentinelProperties {
public void setFileTotalCount(String fileTotalCount) { public void setFileTotalCount(String fileTotalCount) {
this.fileTotalCount = fileTotalCount; this.fileTotalCount = fileTotalCount;
} }
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
} }
public static class Transport { public static class Transport {
@ -299,4 +315,34 @@ public class SentinelProperties {
} }
} }
public static class Log {
/**
* sentinel log base dir
*/
private String dir;
/**
* distinguish the log file by pid number
*/
private boolean switchPid = false;
public String getDir() {
return dir;
}
public void setDir(String dir) {
this.dir = dir;
}
public boolean isSwitchPid() {
return switchPid;
}
public void setSwitchPid(boolean switchPid) {
this.switchPid = switchPid;
}
}
} }

View File

@ -41,6 +41,7 @@ import com.alibaba.csp.sentinel.adapter.servlet.config.WebServletConfig;
import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect; import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.alibaba.csp.sentinel.config.SentinelConfig; import com.alibaba.csp.sentinel.config.SentinelConfig;
import com.alibaba.csp.sentinel.init.InitExecutor; import com.alibaba.csp.sentinel.init.InitExecutor;
import com.alibaba.csp.sentinel.log.LogBase;
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.alibaba.csp.sentinel.util.AppNameUtil;
@ -71,7 +72,6 @@ public class SentinelAutoConfiguration {
@PostConstruct @PostConstruct
private void init() { private void init() {
if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME)) if (StringUtils.isEmpty(System.getProperty(AppNameUtil.APP_NAME))
&& StringUtils.hasText(projectName)) { && StringUtils.hasText(projectName)) {
System.setProperty(AppNameUtil.APP_NAME, projectName); System.setProperty(AppNameUtil.APP_NAME, projectName);
@ -93,8 +93,9 @@ public class SentinelAutoConfiguration {
properties.getTransport().getHeartbeatIntervalMs()); properties.getTransport().getHeartbeatIntervalMs());
} }
if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET)) if (StringUtils.isEmpty(System.getProperty(SentinelConfig.CHARSET))
&& StringUtils.hasText(properties.getCharset())) { && StringUtils.hasText(properties.getMetric().getCharset())) {
System.setProperty(SentinelConfig.CHARSET, properties.getCharset()); System.setProperty(SentinelConfig.CHARSET,
properties.getMetric().getCharset());
} }
if (StringUtils if (StringUtils
.isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE)) .isEmpty(System.getProperty(SentinelConfig.SINGLE_METRIC_FILE_SIZE))
@ -113,10 +114,19 @@ public class SentinelAutoConfiguration {
System.setProperty(SentinelConfig.COLD_FACTOR, System.setProperty(SentinelConfig.COLD_FACTOR,
properties.getFlow().getColdFactor()); properties.getFlow().getColdFactor());
} }
if (StringUtils.hasText(properties.getServlet().getBlockPage())) { if (StringUtils.hasText(properties.getServlet().getBlockPage())) {
WebServletConfig.setBlockPage(properties.getServlet().getBlockPage()); WebServletConfig.setBlockPage(properties.getServlet().getBlockPage());
} }
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_DIR))
&& StringUtils.hasText(properties.getLog().getDir())) {
System.setProperty(LogBase.LOG_DIR, properties.getLog().getDir());
}
if (StringUtils.isEmpty(System.getProperty(LogBase.LOG_NAME_USE_PID))
&& properties.getLog().isSwitchPid()) {
System.setProperty(LogBase.LOG_NAME_USE_PID,
String.valueOf(properties.getLog().isSwitchPid()));
}
urlBlockHandlerOptional.ifPresent(WebCallbackManager::setUrlBlockHandler); urlBlockHandlerOptional.ifPresent(WebCallbackManager::setUrlBlockHandler);
urlCleanerOptional.ifPresent(WebCallbackManager::setUrlCleaner); urlCleanerOptional.ifPresent(WebCallbackManager::setUrlCleaner);

View File

@ -12,12 +12,6 @@
"defaultValue": false, "defaultValue": false,
"description": "earlier initialize heart-beat when the spring container starts when the transport dependency is on classpath, the configuration is effective." "description": "earlier initialize heart-beat when the spring container starts when the transport dependency is on classpath, the configuration is effective."
}, },
{
"name": "spring.cloud.sentinel.charset",
"type": "java.lang.String",
"defaultValue": "UTF-8",
"description": "charset when sentinel write or search metric file."
},
{ {
"name": "spring.cloud.sentinel.transport.port", "name": "spring.cloud.sentinel.transport.port",
"type": "java.lang.String", "type": "java.lang.String",
@ -40,6 +34,12 @@
"defaultValue": "Integer.MIN_VALUE", "defaultValue": "Integer.MIN_VALUE",
"description": "sentinel filter chain order, will be set to FilterRegistrationBean." "description": "sentinel filter chain order, will be set to FilterRegistrationBean."
}, },
{
"name": "spring.cloud.sentinel.metric.charset",
"type": "java.lang.String",
"defaultValue": "UTF-8",
"description": "charset when sentinel write or search metric file."
},
{ {
"name": "spring.cloud.sentinel.metric.fileSingleSize", "name": "spring.cloud.sentinel.metric.fileSingleSize",
"type": "java.lang.String", "type": "java.lang.String",
@ -50,6 +50,17 @@
"type": "java.lang.String", "type": "java.lang.String",
"description": "the total metric file count." "description": "the total metric file count."
}, },
{
"name": "spring.cloud.sentinel.log.dir",
"type": "java.lang.String",
"description": "log base directory."
},
{
"name": "spring.cloud.sentinel.log.switch-pid",
"type": "java.lang.Boolean",
"defaultValue": false,
"description": "log file should with pid."
},
{ {
"name": "spring.cloud.sentinel.servlet.blockPage", "name": "spring.cloud.sentinel.servlet.blockPage",
"type": "java.lang.String", "type": "java.lang.String",