请求资源列表的size大于maxListSize(默认10)时,请求日志中不保存request_content

This commit is contained in:
zhangdongxu
2018-11-20 16:19:11 +08:00
parent 374c439347
commit 0547f71248
6 changed files with 52 additions and 10 deletions

View File

@@ -213,4 +213,10 @@ public final class Constants {
public static final Boolean IS_USE_MINIO = Configurations.getBooleanProperty("isUseMinio", true); public static final Boolean IS_USE_MINIO = Configurations.getBooleanProperty("isUseMinio", true);
public static final int MAXTHREADNUM = Configurations.getIntProperty("maxThreadNum", 10); public static final int MAXTHREADNUM = Configurations.getIntProperty("maxThreadNum", 10);
public static final int EVERTHREADNUM = Configurations.getIntProperty("everThreadNum", 10000); public static final int EVERTHREADNUM = Configurations.getIntProperty("everThreadNum", 10000);
/**
* 保存请求内容时最大的资源列表size
*/
public static final int MAX_LIST_SIZE = Configurations.getIntProperty("maxListSize", 10);
} }

View File

@@ -50,6 +50,7 @@ public class AuditLogThread implements Runnable {
private int businessCode; private int businessCode;
private String exceptionInfo; private String exceptionInfo;
private String traceCode; private String traceCode;
private Boolean saveContentFlag=true;//是否保存请求内容
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
@@ -62,7 +63,7 @@ public class AuditLogThread implements Runnable {
CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_A);// 开启数据源B CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_A);// 开启数据源B
if (service != null) { if (service != null) {
service.saveRequestLog(remoteAddr, requestURI, queryString, contextPath, operator, version, opAction, service.saveRequestLog(remoteAddr, requestURI, queryString, contextPath, operator, version, opAction,
opTime, content, requestTime, consumerTime, businessCode, exceptionInfo, traceCode); opTime, content, requestTime, consumerTime, businessCode, exceptionInfo, traceCode,saveContentFlag);
} else { } else {
logger.error("service 为空!"); logger.error("service 为空!");
} }
@@ -430,4 +431,11 @@ public class AuditLogThread implements Runnable {
this.traceCode = traceCode; this.traceCode = traceCode;
} }
public Boolean getSaveContentFlag() {
return saveContentFlag;
}
public void setSaveContentFlag(Boolean saveContentFlag) {
this.saveContentFlag = saveContentFlag;
}
} }

View File

@@ -92,7 +92,7 @@ public class ServicesRequestLogService {
*/ */
public void saveRequestLog(String requestAddr, String requestURI, String queryString, String contextPath, public void saveRequestLog(String requestAddr, String requestURI, String queryString, String contextPath,
String operator, String version, int opAction, Date opTime, Object content, Date requestTime, String operator, String version, int opAction, Date opTime, Object content, Date requestTime,
long consumerTime, int businessCode, String exceptionInfo, String traceCode) { long consumerTime, int businessCode, String exceptionInfo, String traceCode,Boolean saveContentFlag) {
logger.info("开始记录日志---"); logger.info("开始记录日志---");
logger.info("请求IP---" + requestAddr); logger.info("请求IP---" + requestAddr);
logger.info("请求路径---" + requestURI); logger.info("请求路径---" + requestURI);
@@ -171,6 +171,9 @@ public class ServicesRequestLogService {
if ("file".equals(type)) {// 文件上传 if ("file".equals(type)) {// 文件上传
log.setRequestContent(content.toString()); log.setRequestContent(content.toString());
} else { } else {
if(!saveContentFlag){
log.setRequestContent("批量提交数量超过"+Constants.MAX_LIST_SIZE+",不记录请求内容");
}
if (content != null) { if (content != null) {
log.setRequestContent(content.toString()); log.setRequestContent(content.toString());
} }

View File

@@ -126,7 +126,10 @@ public class ConfigSourcesService extends BaseService {
StringBuffer sb) throws Exception { StringBuffer sb) throws Exception {
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>(); Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>(); Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
if (configCompileList!=null&&configCompileList.size()>Constants.MAX_LIST_SIZE) {
thread.setSaveContentFlag(false);
}
for (ConfigCompile configCompile : configCompileList) { for (ConfigCompile configCompile : configCompileList) {
Integer service = Integer.valueOf(configCompile.getService().toString()); Integer service = Integer.valueOf(configCompile.getService().toString());
MaatConfig maatConfig = new MaatConfig(); MaatConfig maatConfig = new MaatConfig();
@@ -323,6 +326,9 @@ public class ConfigSourcesService extends BaseService {
public void updateConfigSources(AuditLogThread thread, long start, List<ConfigCompile> compileList, Date opTime, public void updateConfigSources(AuditLogThread thread, long start, List<ConfigCompile> compileList, Date opTime,
StringBuffer sb) throws Exception { StringBuffer sb) throws Exception {
Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>(); Map<Integer, List<Long>> compileMap = new HashMap<Integer, List<Long>>();
if (compileList!=null&&compileList.size()>Constants.MAX_LIST_SIZE) {
thread.setSaveContentFlag(false);
}
if (null != compileList && compileList.size() > 0) { if (null != compileList && compileList.size() > 0) {
for (ConfigCompile config : compileList) { for (ConfigCompile config : compileList) {
checkCompileOptForUpdate(config); checkCompileOptForUpdate(config);
@@ -416,7 +422,9 @@ public class ConfigSourcesService extends BaseService {
throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason() + "," + e.getMessage(), throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason() + "," + e.getMessage(),
RestBusinessCode.CBParamFormateError.getValue()); RestBusinessCode.CBParamFormateError.getValue());
} }
if (jsonObjectList!=null&&jsonObjectList.size()>Constants.MAX_LIST_SIZE) {
thread.setSaveContentFlag(false);
}
Map<Integer, List<Map<String, String>>> dstMaps = new HashMap<Integer, List<Map<String, String>>>(); Map<Integer, List<Map<String, String>>> dstMaps = new HashMap<Integer, List<Map<String, String>>>();
for (int i = 0; i < jsonObjectList.size(); i++) { for (int i = 0; i < jsonObjectList.size(); i++) {
JsonObject jsonObj = (JsonObject) jsonObjectList.get(i); JsonObject jsonObj = (JsonObject) jsonObjectList.get(i);
@@ -636,6 +644,9 @@ public class ConfigSourcesService extends BaseService {
throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason() + "," + e.getMessage(), throw new RestServiceException(RestBusinessCode.CBParamFormateError.getErrorReason() + "," + e.getMessage(),
RestBusinessCode.CBParamFormateError.getValue()); RestBusinessCode.CBParamFormateError.getValue());
} }
if (jsonObjectList!=null&&jsonObjectList.size()>Constants.MAX_LIST_SIZE) {
thread.setSaveContentFlag(false);
}
// <service,cfgIdList> // <service,cfgIdList>
Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>(); Map<Integer, List<Long>> cfgMap = new HashMap<Integer, List<Long>>();
// 所有状态更新的配置isValid的值必须相同 // 所有状态更新的配置isValid的值必须相同
@@ -867,9 +878,17 @@ public class ConfigSourcesService extends BaseService {
} else { } else {
maatConfig.getIpRegionMapList().addAll(dstMapList); maatConfig.getIpRegionMapList().addAll(dstMapList);
} }
if ((maatConfig.getStrRegionMapList()!=null&&maatConfig.getStrRegionMapList().size()>Constants.MAX_LIST_SIZE)
||(maatConfig.getStrStrRegionMapList()!=null&&maatConfig.getStrStrRegionMapList().size()>Constants.MAX_LIST_SIZE)
||(maatConfig.getIpRegionMapList()!=null&&maatConfig.getIpRegionMapList().size()>Constants.MAX_LIST_SIZE)
||(maatConfig.getNumRegionMapList()!=null&&maatConfig.getNumRegionMapList().size()>Constants.MAX_LIST_SIZE)) {
thread.setSaveContentFlag(false);
}
//maatConfig.setService(groupReuse.getService()); //maatConfig.setService(groupReuse.getService());
list.add(maatConfig); list.add(maatConfig);
} }
// 调用接口入redis // 调用接口入redis
logger.info("---------------调用Redis 分组复用配置新增接口---------------------"); logger.info("---------------调用Redis 分组复用配置新增接口---------------------");
@@ -938,6 +957,9 @@ public class ConfigSourcesService extends BaseService {
} }
} }
logger.info("调用接口删除Redis中分组复用的域配置接口"); logger.info("调用接口删除Redis中分组复用的域配置接口");
if (reuseMap!=null&&reuseMap.size()>Constants.MAX_LIST_SIZE) {
thread.setSaveContentFlag(false);
}
// 所有的都删除成功返回true // 所有的都删除成功返回true
if (!configRedisService.delGroupReuseConfig(reuseMap)) { if (!configRedisService.delGroupReuseConfig(reuseMap)) {
// if (!configRedisService.delGroupReuseConfigByPipeline(reuseMap)) { // if (!configRedisService.delGroupReuseConfigByPipeline(reuseMap)) {

View File

@@ -55,11 +55,13 @@ public class MaatTestServiceimpl {
Map<String, String[]> tapFieldMap = ServiceAndRDBIndexReal.getMaatToValveMap().get(service); Map<String, String[]> tapFieldMap = ServiceAndRDBIndexReal.getMaatToValveMap().get(service);
//用于判断是否是入阀门时添加的额外字段 //用于判断是否是入阀门时添加的额外字段
Map<String, String> keyMap = new HashMap<String, String>(); Map<String, String> keyMap = new HashMap<String, String>();
Iterator iterator = tapFieldMap.keySet().iterator(); if(null!=tapFieldMap){
while (iterator.hasNext()) { Iterator iterator = tapFieldMap.keySet().iterator();
String [] tapFields = tapFieldMap.get(iterator.next().toString()); while (iterator.hasNext()) {
for (String obj : tapFields) { String [] tapFields = tapFieldMap.get(iterator.next().toString());
keyMap.put(CamelUnderlineUtil.underlineToCamel(obj).toLowerCase(), obj.toLowerCase()); for (String obj : tapFields) {
keyMap.put(CamelUnderlineUtil.underlineToCamel(obj).toLowerCase(), obj.toLowerCase());
}
} }
} }
List<Integer> redisDBList = ServiceAndRDBIndexReal.getRedisDBByService(service); List<Integer> redisDBList = ServiceAndRDBIndexReal.getRedisDBByService(service);

View File

@@ -174,7 +174,8 @@ maxPageSize=100000
#是否开启Debug模式 #是否开启Debug模式
isDebug=false isDebug=false
#保存请求内容时最大的资源列表size
maxListSize=10
#实时报表统计时间,单位:分钟 #实时报表统计时间,单位:分钟
pzReportTime=5 pzReportTime=5