[Fix][Trace ID]: 日志增加Trace ID同request_id,便于日志定位
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
<!--日志文件名称-->
|
||||
<property name="LOG_FILE_NAME">galaxy-qgw-service</property>
|
||||
<!--日志打印格式-->
|
||||
<property name="LOG_PATTERN">[%d{yyyy-MM-dd HH:mm:ssZ}] [%p] [Thread:%t] %l %x - %m%n</property>
|
||||
<property name="LOG_PATTERN">[%d{yyyy-MM-dd HH:mm:ssZ}] [%p] [Thread:%t] [%X{traceId}] %l %x - %m%n</property>
|
||||
</Properties>
|
||||
|
||||
<appenders>
|
||||
|
||||
@@ -27,6 +27,9 @@ management:
|
||||
health: /component_status
|
||||
#MySql configuration
|
||||
spring:
|
||||
sleuth:
|
||||
enabled: true
|
||||
traceId128: true
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://192.168.44.12:3306/tsg_olap?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=UTC&failOverReadOnly=false&connectTimeout=10000&socketTimeout=30000
|
||||
@@ -114,7 +117,7 @@ service:
|
||||
defaultSize: 100000
|
||||
## ArangoDB configuration
|
||||
arango:
|
||||
server: http://192.168.44.83:8529
|
||||
server: http://192.168.44.12:8529
|
||||
database: tsg_galaxy_v3
|
||||
username: ENC(UyZxsi4PT6kQXJAep5qvQQ==)
|
||||
pin: ENC(qUA355VopKSx6kwwwXZwqWWEYSu76Slz)
|
||||
|
||||
9
pom.xml
9
pom.xml
@@ -75,7 +75,7 @@
|
||||
<hazelcast-spring.version>5.3.6</hazelcast-spring.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mesalab.ua</groupId>
|
||||
@@ -110,6 +110,13 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-sleuth -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-sleuth</artifactId>
|
||||
<version>2.2.7.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
|
||||
17
src/main/java/com/mesalab/common/utils/MDCUtil.java
Normal file
17
src/main/java/com/mesalab/common/utils/MDCUtil.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.mesalab.common.utils;
|
||||
|
||||
import org.slf4j.MDC;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @Classname MDCUtil
|
||||
* @Date 2024/1/10 18:11
|
||||
* @Author wWei
|
||||
*/
|
||||
public class MDCUtil {
|
||||
|
||||
public static String getTraceId() {
|
||||
return MDC.get("traceId");
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
package com.mesalab.qgw.aspect;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.log.Log;
|
||||
import cn.hutool.log.LogFactory;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.mesalab.common.entity.BaseResult;
|
||||
import com.mesalab.common.utils.HttpHelper;
|
||||
import com.mesalab.common.utils.MDCUtil;
|
||||
import com.mesalab.qgw.model.basic.SQLQueryContext;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.qgw.model.basic.AuditServiceLog;
|
||||
import com.geedgenetworks.utils.IPUtil;
|
||||
import com.geedgenetworks.utils.StringUtil;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.*;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
@@ -22,7 +21,6 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@Aspect
|
||||
@@ -35,7 +33,8 @@ public class AuditLogAspect {
|
||||
|
||||
|
||||
@Pointcut("@annotation(com.mesalab.qgw.model.basic.AuditLog)")
|
||||
public void annotationPointCut(){}
|
||||
public void annotationPointCut() {
|
||||
}
|
||||
|
||||
@Before("annotationPointCut()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
@@ -47,30 +46,28 @@ public class AuditLogAspect {
|
||||
String remoteAddr = request.getRemoteAddr();
|
||||
String clientIp = IPUtil.getIpAddr(request);
|
||||
String classMethod = joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName();
|
||||
Object paramObject = joinPoint.getArgs()[0];
|
||||
|
||||
MethodSignature sign = (MethodSignature)joinPoint.getSignature();
|
||||
MethodSignature sign = (MethodSignature) joinPoint.getSignature();
|
||||
Method method2 = sign.getMethod();
|
||||
AuditLog annotation = method2.getAnnotation(AuditLog.class);
|
||||
AuditServiceLog auditServiceLog = new AuditServiceLog();
|
||||
AuditServiceLog auditServiceLog = new AuditServiceLog();
|
||||
auditServiceLog.setAnnotation(annotation.value());
|
||||
auditServiceLog.setRemoteAddr(remoteAddr);
|
||||
auditServiceLog.setClientIp(clientIp);
|
||||
auditServiceLog.setMethod(method);
|
||||
if (log.isDebugEnabled()) {
|
||||
auditServiceLog.setParam(Optional.ofNullable(paramObject).orElse("").toString());
|
||||
if (log.isInfoEnabled()) {
|
||||
auditServiceLog.setParam(Arrays.toString(joinPoint.getArgs()));
|
||||
auditServiceLog.setUrl(url);
|
||||
auditServiceLog.setClassMethod(classMethod);
|
||||
}
|
||||
auditServiceLog.setCacheKey(HttpHelper.generateCacheKey(request));
|
||||
auditServiceLog.setRequestId(DigestUtil.md5Hex(StringUtil.createUUID()));
|
||||
auditServiceLog.setRequestId(MDCUtil.getTraceId());
|
||||
auditLog.set(auditServiceLog);
|
||||
}
|
||||
|
||||
@AfterThrowing(value = "annotationPointCut()", throwing = "exception")
|
||||
public void doAfterThrowingAdvice(JoinPoint joinPoint, Throwable exception){
|
||||
AuditServiceLog logAfter = auditLog.get();
|
||||
logAfter.setRequestId(null);
|
||||
public void doAfterThrowingAdvice(JoinPoint joinPoint, Throwable exception) {
|
||||
AuditServiceLog logAfter = auditLog.get();
|
||||
logAfter.setParam(Arrays.toString(joinPoint.getArgs()));
|
||||
log.error("Audit Log [error]:{}", JSON.toJSONString(logAfter));
|
||||
}
|
||||
@@ -78,16 +75,20 @@ public class AuditLogAspect {
|
||||
|
||||
@After(value = "annotationPointCut()")
|
||||
public void after(JoinPoint joinPoint) {
|
||||
if (joinPoint.getArgs()[0] instanceof SQLQueryContext) {
|
||||
SQLQueryContext queryContext = (SQLQueryContext) joinPoint.getArgs()[0];
|
||||
auditLog.get().setDbEngine(queryContext.getDbEngine());
|
||||
}
|
||||
Object[] args = joinPoint.getArgs();
|
||||
if (args.length == 0) {
|
||||
return;
|
||||
}
|
||||
if (args[0] instanceof SQLQueryContext) {
|
||||
SQLQueryContext queryContext = (SQLQueryContext) joinPoint.getArgs()[0];
|
||||
auditLog.get().setDbEngine(queryContext.getDbEngine());
|
||||
}
|
||||
}
|
||||
|
||||
@AfterReturning(returning = "result", pointcut = "annotationPointCut()")
|
||||
public void doAfterReturning(Object result) {
|
||||
AuditServiceLog logAfter = auditLog.get();
|
||||
if(result instanceof BaseResult){
|
||||
AuditServiceLog logAfter = auditLog.get();
|
||||
if (result instanceof BaseResult) {
|
||||
BaseResult baseResult = (BaseResult) result;
|
||||
baseResult.setRequestId(logAfter.getRequestId());
|
||||
}
|
||||
@@ -97,5 +98,4 @@ public class AuditLogAspect {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mesalab.qgw.constant.QGWMessageConst;
|
||||
import com.mesalab.common.enums.HttpStatusCodeEnum;
|
||||
import com.mesalab.qgw.exception.QGWBusinessException;
|
||||
import com.mesalab.common.exception.CommonErrorCode;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.qgw.model.job.StorageDeletionInfo;
|
||||
import com.mesalab.qgw.service.DatabaseService;
|
||||
import com.geedgenetworks.utils.StringUtil;
|
||||
@@ -36,6 +37,7 @@ public class DatabaseController {
|
||||
|
||||
|
||||
@RequestMapping(value = "/table/{table_name}/schema", consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("DatabaseController.getSchemaByTable")
|
||||
public BaseResult getSchemaByTable(@PathVariable("table_name") String tableName) {
|
||||
log.debug("SCHEMA信息获取,参数为{} {}", tableName);
|
||||
|
||||
@@ -46,6 +48,7 @@ public class DatabaseController {
|
||||
}
|
||||
|
||||
@PutMapping(value = "/table/{table_name}/schema", consumes = "application/json")
|
||||
@AuditLog("DatabaseController.updateSchema")
|
||||
public BaseResult updateSchema(@PathVariable("table_name") String tableName, @RequestBody Map<String, Object> obj) {
|
||||
log.info("update Schema api, params is: {}-{}", tableName, obj);
|
||||
if (StringUtil.isBlank(tableName) || StringUtil.isEmpty(obj)) {
|
||||
@@ -57,6 +60,7 @@ public class DatabaseController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{dbName}/table", consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("DatabaseController.getTableByDB")
|
||||
public BaseResult getTableByDB(@PathVariable String dbName) {
|
||||
log.debug("SCHEMA信息获取,参数为{} {}", dbName);
|
||||
|
||||
@@ -68,11 +72,13 @@ public class DatabaseController {
|
||||
}
|
||||
|
||||
@GetMapping(value = "/storage/quota", consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("DatabaseController.storageQuota")
|
||||
public BaseResult storageQuota() {
|
||||
return databaseService.getStorageQuota();
|
||||
}
|
||||
|
||||
@PutMapping(value = "/storage/quota", consumes = "application/json")
|
||||
@AuditLog("DatabaseController.storageSetting")
|
||||
public BaseResult storageSetting(@RequestBody List<StorageDeletionInfo> list) {
|
||||
log.warn("数据配额设置, 参数: params is {}", list);
|
||||
if (StringUtil.isEmpty(list)) {
|
||||
@@ -97,6 +103,7 @@ public class DatabaseController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/storage/quota", method = RequestMethod.DELETE, consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("DatabaseController.storageDeletion")
|
||||
public BaseResult storageDeletion(@RequestParam String type) {
|
||||
List<StorageDeletionInfo> deletionInfoList = Lists.newArrayList();
|
||||
StorageDeletionInfo deletionInfo = new StorageDeletionInfo();
|
||||
@@ -107,6 +114,7 @@ public class DatabaseController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/storage/quota/daily_usage", consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("DatabaseController.dailyTrendOfStorage")
|
||||
public BaseResult dailyTrendOfStorage(@RequestParam Map<String, Object> param) {
|
||||
String searchStartTime = StringUtil.stripToEmpty((String) param.get("start_time"));
|
||||
String searchEndTime = StringUtil.stripToEmpty((String) param.get("end_time"));
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.mesalab.common.enums.DBEngineType;
|
||||
import com.mesalab.qgw.constant.QGWMessageConst;
|
||||
import com.mesalab.qgw.exception.QGWBusinessException;
|
||||
import com.mesalab.common.exception.CommonErrorCode;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.qgw.service.DatasetService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -26,6 +27,7 @@ public class DatasetController {
|
||||
private DatasetService datasetService;
|
||||
|
||||
@GetMapping(value = "/{identifier_name}")
|
||||
@AuditLog("DatasetController.getDataset")
|
||||
public BaseResult getDataset(@PathVariable("identifier_name") String identifierName) {
|
||||
log.info("Get Dataset, ID is: {}", identifierName);
|
||||
Map<String, Object> dataset = datasetService.getDataset(identifierName);
|
||||
@@ -33,6 +35,7 @@ public class DatasetController {
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
@AuditLog("DatasetController.getDatasets")
|
||||
public BaseResult getDatasets(@RequestParam(value = "identifier_names", required = false) String datasetIds, @RequestParam(required = false) String category, @RequestParam(value = "backend_engine", required = false) String backendEngine) {
|
||||
if (StrUtil.isNotBlank(backendEngine)) {
|
||||
if (Arrays.stream(DBEngineType.values()).noneMatch(o -> o.getValue().equalsIgnoreCase(backendEngine))) {
|
||||
@@ -45,11 +48,13 @@ public class DatasetController {
|
||||
}
|
||||
|
||||
@GetMapping(value = "/{identifier_name}/result_preview")
|
||||
@AuditLog("DatasetController.getPreview")
|
||||
public BaseResult getPreview(@PathVariable("identifier_name") String identifierName) {
|
||||
return datasetService.getPreview(identifierName);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/dataset/global_variable")
|
||||
@AuditLog("DatasetController.getVariable")
|
||||
public BaseResult getVariable() {
|
||||
return BaseResultGenerator.success(datasetService.getVariable());
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.mesalab.common.enums.DBEngineType;
|
||||
import com.mesalab.qgw.constant.QGWMessageConst;
|
||||
import com.mesalab.qgw.exception.QGWBusinessException;
|
||||
import com.mesalab.common.exception.CommonErrorCode;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.qgw.service.DiagnosisService;
|
||||
import com.mesalab.services.common.enums.EntityQueryType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -27,17 +28,20 @@ public class DiagnosisController {
|
||||
private DiagnosisService diagnosisService;
|
||||
|
||||
@RequestMapping("/component_info")
|
||||
@AuditLog("DiagnosisController.versionInfo")
|
||||
public JSONObject versionInfo() {
|
||||
return diagnosisService.getVersionInfo();
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/schema_check")
|
||||
@AuditLog("DiagnosisController.validateSchema")
|
||||
public BaseResult validateSchema() {
|
||||
return diagnosisService.validateSchema();
|
||||
}
|
||||
|
||||
@RequestMapping({"/sql", "/sql/{dialect}/{queryNo}"})
|
||||
@AuditLog("DiagnosisController.getPocSql")
|
||||
public BaseResult getPocSql(@PathVariable String dialect, @PathVariable(required = false) Integer queryNo) {
|
||||
if (Arrays.stream(DBEngineType.values()).noneMatch(o -> o.getValue().equalsIgnoreCase(dialect))){
|
||||
throw new QGWBusinessException(HttpStatus.HTTP_BAD_REQUEST, CommonErrorCode.PARAMETER_ERROR.getCode(),
|
||||
@@ -47,6 +51,7 @@ public class DiagnosisController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/entity")
|
||||
@AuditLog("DiagnosisController.getMessageInfo")
|
||||
public BaseResult getMessageInfo(String option) {
|
||||
log.info("Entity recommendation proportion statistical information interface, param is: {}", option);
|
||||
if (!EntityQueryType.TOPSERVERIP.getType().equalsIgnoreCase(option) && !EntityQueryType.TOPSNI.getType().equalsIgnoreCase(option)) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.mesalab.common.enums.HttpStatusCodeEnum;
|
||||
import com.mesalab.common.exception.BusinessException;
|
||||
import com.mesalab.qgw.constant.QGWMessageConst;
|
||||
import com.mesalab.common.exception.CommonErrorCode;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.qgw.service.HosService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -27,6 +28,7 @@ public class HosController {
|
||||
private HosService hosService;
|
||||
|
||||
@GetMapping(value = "/{bucket_name}", consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("HosController.getFileList")
|
||||
public BaseResult getFileList(@PathVariable("bucket_name") String bucketName, @RequestParam(required = false) String prefix, HttpServletRequest request) {
|
||||
if (StrUtil.isNotBlank(bucketName)) {
|
||||
Map<String, String> udfMetaParam = new HashMap<>();
|
||||
|
||||
@@ -28,8 +28,6 @@ import java.util.List;
|
||||
@RequestMapping(value = "test")
|
||||
public class TestController {
|
||||
|
||||
@Autowired
|
||||
private DiagnosisService diagnosisService;
|
||||
@Autowired
|
||||
TroubleshootingController troubleshootingController;
|
||||
@Autowired
|
||||
@@ -58,6 +56,7 @@ public class TestController {
|
||||
* @return BaseResult
|
||||
*/
|
||||
@GetMapping(value = "projectProperties")
|
||||
@AuditLog("TestController.projectProperties")
|
||||
public BaseResult projectProperties() {
|
||||
log.info("Project Properties: {}", projectProperties);
|
||||
return BaseResultGenerator.success("ok", projectProperties);
|
||||
@@ -69,6 +68,7 @@ public class TestController {
|
||||
* @return 返回当前项目的环境值
|
||||
*/
|
||||
@GetMapping(value = "activeProfiles")
|
||||
@AuditLog("TestController.activeProfiles")
|
||||
public BaseResult activeProfiles() {
|
||||
List<String> activeProfiles = Lists.newArrayList(nacosConfig.getNamespace());
|
||||
log.info("Current Namespace: {}", activeProfiles);
|
||||
@@ -81,6 +81,7 @@ public class TestController {
|
||||
* @return 返回当前项目的运行环境
|
||||
*/
|
||||
@GetMapping(value = "env")
|
||||
@AuditLog("TestController.env")
|
||||
public BaseResult env() {
|
||||
return BaseResultGenerator.success(Lists.newArrayList(nacosConfig.getNamespace()));
|
||||
}
|
||||
@@ -91,41 +92,18 @@ public class TestController {
|
||||
* @return 检查授权
|
||||
*/
|
||||
@GetMapping(value = "checkAuthc")
|
||||
@AuditLog("TestController.checkAuthc")
|
||||
public BaseResult checkAuthc() {
|
||||
return BaseResultGenerator.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 运行测试用例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "runSql")
|
||||
@Deprecated
|
||||
public BaseResult runSql() {
|
||||
BaseResult result = troubleshootingController.benchmark("olap_sql_dataset", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验schema
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "runSchema")
|
||||
@Deprecated
|
||||
public BaseResult runSchema() {
|
||||
BaseResult result = diagnosisService.validateSchema();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查job动态连接配置
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "jobAdminHttpSource")
|
||||
@AuditLog("TestController.jobAdminHttpSource")
|
||||
public BaseResult jobAdminHttpSource() {
|
||||
return BaseResultGenerator.success("ok", jobAdminHttpSource);
|
||||
}
|
||||
@@ -136,6 +114,7 @@ public class TestController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "druidIoHttpSource")
|
||||
@AuditLog("TestController.druidIoHttpSource")
|
||||
public BaseResult druidIoHttpSource() {
|
||||
return BaseResultGenerator.success("ok", druidIoHttpSource);
|
||||
}
|
||||
@@ -146,6 +125,7 @@ public class TestController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "clickHouseHttpSource")
|
||||
@AuditLog("TestController.clickHouseHttpSource")
|
||||
public BaseResult clickHouseHttpSource() {
|
||||
return BaseResultGenerator.success("ok", clickHouseHttpSource);
|
||||
}
|
||||
@@ -156,6 +136,7 @@ public class TestController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "hBaseAPISource")
|
||||
@AuditLog("TestController.hBaseAPISource")
|
||||
public BaseResult hBaseAPISource() {
|
||||
return BaseResultGenerator.success("ok", hBaseAPISource);
|
||||
}
|
||||
@@ -166,6 +147,7 @@ public class TestController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "engineConfigSource")
|
||||
@AuditLog("TestController.engineConfigSource")
|
||||
public BaseResult engineConfigSource() {
|
||||
return BaseResultGenerator.success("ok", engineConfigSource);
|
||||
}
|
||||
@@ -176,6 +158,7 @@ public class TestController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "arangoConfig")
|
||||
@AuditLog("TestController.arangoConfig")
|
||||
public BaseResult arangoConfig() {
|
||||
return BaseResultGenerator.success("ok", arangoConfig);
|
||||
}
|
||||
@@ -186,6 +169,7 @@ public class TestController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "httpConfig")
|
||||
@AuditLog("TestController.httpConfig")
|
||||
public BaseResult httpConfig() {
|
||||
return BaseResultGenerator.success("ok", httpConfig);
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mesalab.qgw.constant.QGWMessageConst;
|
||||
import com.mesalab.common.exception.BusinessException;
|
||||
import com.mesalab.qgw.exception.QGWBusinessException;
|
||||
import com.mesalab.common.exception.CommonErrorCode;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.qgw.service.TroubleshootingService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -31,11 +32,13 @@ public class TroubleshootingController {
|
||||
private static final String TEST_PARAM = "olap_sql_dataset";
|
||||
|
||||
@RequestMapping("/component/status")
|
||||
public JSONObject ComponentStatus() {
|
||||
@AuditLog("TroubleshootingController.componentStatus")
|
||||
public JSONObject componentStatus() {
|
||||
return troubleshootingService.getComponentStatus();
|
||||
}
|
||||
|
||||
@RequestMapping(value = "sanity", method = RequestMethod.GET)
|
||||
@AuditLog("TroubleshootingController.sanity")
|
||||
public BaseResult sanity(String test) {
|
||||
if (Arrays.stream(ConsistencyOption.values()).noneMatch(o -> o.getValue().equalsIgnoreCase(test))) {
|
||||
throw new QGWBusinessException(HttpStatus.HTTP_BAD_REQUEST, CommonErrorCode.PARAMETER_ERROR.getCode(),
|
||||
@@ -54,6 +57,7 @@ public class TroubleshootingController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/benchmark", method = RequestMethod.GET)
|
||||
@AuditLog("TroubleshootingController.benchmark")
|
||||
public BaseResult benchmark(@RequestParam String test, @RequestParam(value = "is_saved", required = false, defaultValue = "0") @JsonProperty("isSaved") Integer isSaved) throws BusinessException {
|
||||
if (!TEST_PARAM.equals(test) || StrUtil.isBlankIfStr(test)) {
|
||||
throw new QGWBusinessException(HttpStatus.HTTP_BAD_REQUEST, CommonErrorCode.PARAMETER_ERROR.getCode(),
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.mesalab.common.enums.HttpStatusCodeEnum;
|
||||
import com.mesalab.common.exception.CommonErrorCode;
|
||||
import com.mesalab.qgw.constant.QGWMessageConst;
|
||||
import com.mesalab.qgw.exception.QGWBusinessException;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.qgw.model.job.EncryptionInfo;
|
||||
import com.mesalab.qgw.service.UtilService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -22,11 +23,13 @@ public class UtilController {
|
||||
private UtilService utilService;
|
||||
|
||||
@GetMapping(value = "/sql_parser", consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("UtilController.getSQLSyntaxTree")
|
||||
public BaseResult getSQLSyntaxTree(String sql){
|
||||
return utilService.getSQLSyntaxTree(sql);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/password_generator", consumes = "application/json")
|
||||
@AuditLog("UtilController.getCiphertext")
|
||||
public BaseResult getCiphertext(@RequestBody EncryptionInfo param) {
|
||||
log.info("Plaintext encrypted,The plaintext argument is : {}", param);
|
||||
if (StringUtil.isEmpty(param.getPassword()) || StringUtil.isEmpty(param.getSalt())) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.io.IOException;
|
||||
@WebFilter(urlPatterns = "/*")
|
||||
public class ControllerFilter implements Filter {
|
||||
private static final String NOT_FILTER_PATHS = "/v1/knowledge_base";
|
||||
private static final String NOT_FILTER_PATHS_DEPRECATED = "/knowledge_base/v1";
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
@@ -22,7 +21,7 @@ public class ControllerFilter implements Filter {
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest httpServletRequest = ((HttpServletRequest) servletRequest);
|
||||
String servletPath = httpServletRequest.getServletPath();
|
||||
if (String.valueOf(servletPath).contains(NOT_FILTER_PATHS) || String.valueOf(servletPath).contains(NOT_FILTER_PATHS_DEPRECATED)) {
|
||||
if (String.valueOf(servletPath).contains(NOT_FILTER_PATHS)) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
} else {
|
||||
filterChain.doFilter(new RequestParamWrapper(httpServletRequest), servletResponse);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mesalab.qgw.interceptor;
|
||||
|
||||
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.log.Log;
|
||||
import cn.hutool.log.LogFactory;
|
||||
@@ -8,6 +9,7 @@ import com.mesalab.common.entity.BaseResult;
|
||||
import com.mesalab.common.entity.BaseResultGenerator;
|
||||
import com.mesalab.common.enums.HttpStatusCodeEnum;
|
||||
import com.mesalab.common.exception.BusinessException;;
|
||||
import com.mesalab.common.utils.MDCUtil;
|
||||
import com.mesalab.qgw.exception.QGWBusinessException;
|
||||
import com.geedgenetworks.utils.StringUtil;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
@@ -37,7 +39,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler(Exception.class)
|
||||
public BaseResult handleException(Exception e, HttpServletRequest request, HttpServletResponse response) {
|
||||
response.setStatus(HttpStatusCodeEnum.BAD_REQUEST.getCode());
|
||||
String queryKey = DigestUtil.md5Hex(StringUtil.createUUID());
|
||||
String queryKey = StrUtil.isEmpty(MDCUtil.getTraceId()) ? DigestUtil.md5Hex(StringUtil.createUUID()) : MDCUtil.getTraceId();
|
||||
log.error("requestId:{}, message:{}, stackTrace:{}", queryKey, ExceptionUtil.getRootCauseMessage(e), getStackTrace(e));
|
||||
return BaseResultGenerator.failure(e.getMessage(), queryKey);
|
||||
}
|
||||
@@ -46,7 +48,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler({QGWBusinessException.class})
|
||||
public BaseResult handleBusinessException(QGWBusinessException e, HttpServletRequest request, HttpServletResponse response) {
|
||||
response.setStatus(e.getStatus());
|
||||
String queryKey = DigestUtil.md5Hex(StringUtil.createUUID());
|
||||
String queryKey = StrUtil.isEmpty(MDCUtil.getTraceId()) ? DigestUtil.md5Hex(StringUtil.createUUID()) : MDCUtil.getTraceId();
|
||||
String message = (null != e.getMessage()) ? e.getMessage() : ExceptionUtil.getRootCauseMessage(e);
|
||||
log.error("requestId:{}.message:{}.stackTrace:{}", queryKey, message, getStackTrace(e));
|
||||
return BaseResultGenerator.failure(e.getStatus(), e.getCode(), queryKey, message);
|
||||
@@ -55,7 +57,7 @@ public class GlobalExceptionHandler {
|
||||
@ExceptionHandler({BusinessException.class})
|
||||
public BaseResult handleBusinessException(BusinessException e, HttpServletRequest request, HttpServletResponse response) {
|
||||
response.setStatus(e.getStatus());
|
||||
String queryKey = DigestUtil.md5Hex(StringUtil.createUUID());
|
||||
String queryKey = StrUtil.isEmpty(MDCUtil.getTraceId()) ? DigestUtil.md5Hex(StringUtil.createUUID()) : MDCUtil.getTraceId();
|
||||
String message = (null != e.getMessage()) ? e.getMessage() : ExceptionUtil.getRootCauseMessage(e);
|
||||
log.error("requestId:{}.message:{}.stackTrace:{}", queryKey, message, getStackTrace(e));
|
||||
return BaseResultGenerator.failure(e.getStatus(), e.getCode(), queryKey, message);
|
||||
@@ -65,5 +67,4 @@ public class GlobalExceptionHandler {
|
||||
return StringUtil.isNotEmpty(e.getStackTrace()) ? e.getStackTrace()[0].toString() : "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class KnowledgeScheduler {
|
||||
private KBService kbService;
|
||||
private static final Map<String, String> updateMap = new HashMap<>();
|
||||
|
||||
@PostConstruct
|
||||
//@PostConstruct
|
||||
private void loadKnowledge() {
|
||||
try {
|
||||
BaseResult baseResult = kbService.getList(null);
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mesalab.common.enums.HttpStatusCodeEnum;
|
||||
import com.mesalab.common.exception.BusinessException;
|
||||
import com.mesalab.common.exception.CommonErrorCode;
|
||||
import com.mesalab.qgw.constant.QGWMessageConst;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.services.common.entity.KnowledgeBaseRequest;
|
||||
import com.mesalab.services.service.KBService;
|
||||
import com.geedgenetworks.utils.StringUtil;
|
||||
@@ -33,6 +34,7 @@ public class KBController {
|
||||
KBService kbService;
|
||||
|
||||
@PostMapping(produces = "application/json", consumes = "multipart/form-data")
|
||||
@AuditLog("KBController.publishKnowledgeBase")
|
||||
public BaseResult publishKnowledgeBase(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
|
||||
try {
|
||||
KnowledgeBaseRequest KBRequest = getKnowledgeBaseRequest(request);
|
||||
@@ -46,6 +48,7 @@ public class KBController {
|
||||
}
|
||||
|
||||
@PutMapping(value = {"/{kb_Id}"},consumes = "multipart/form-data")
|
||||
@AuditLog("KBController.updateKnowledgeBase")
|
||||
public BaseResult updateKnowledgeBase(@PathVariable(value = "kb_Id",required = false) String kbId,@RequestPart(value = "file") MultipartFile file,HttpServletRequest request) {
|
||||
try {
|
||||
KnowledgeBaseRequest KBRequest = getKnowledgeBaseRequest(request);
|
||||
@@ -67,6 +70,7 @@ public class KBController {
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/{kb_id}",consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("KBController.deleteKnowledgeBase")
|
||||
public BaseResult deleteKnowledgeBase(@PathVariable(value = "kb_id") String kbId, @RequestParam(required = false) String version) {
|
||||
try {
|
||||
KnowledgeBaseRequest request = new KnowledgeBaseRequest();
|
||||
@@ -87,6 +91,7 @@ public class KBController {
|
||||
}
|
||||
|
||||
@PutMapping(value = "/{kb_id}/status",consumes = "application/x-www-form-urlencoded")
|
||||
@AuditLog("KBController.updateStatusKnowledgeBase")
|
||||
public BaseResult updateStatusKnowledgeBase(@PathVariable(value = "kb_id") String kbId, HttpServletRequest request) {
|
||||
try {
|
||||
KnowledgeBaseRequest KBRequest = getKnowledgeBaseRequest(request);
|
||||
@@ -108,6 +113,7 @@ public class KBController {
|
||||
}
|
||||
|
||||
@GetMapping(produces = "application/json")
|
||||
@AuditLog("KBController.getList")
|
||||
public BaseResult getList(@RequestParam(required = false, value = "kb_id") String kbId) {
|
||||
try {
|
||||
log.info("Knowledge Base File get list interface,param is: kb_id= {}", kbId);
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.mesalab.common.enums.HttpStatusCodeEnum;
|
||||
import com.mesalab.qgw.constant.QGWMessageConst;
|
||||
import com.mesalab.qgw.exception.QGWBusinessException;
|
||||
import com.mesalab.common.exception.CommonErrorCode;
|
||||
import com.mesalab.qgw.model.basic.AuditLog;
|
||||
import com.mesalab.services.service.SQLDatasetService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -33,8 +34,9 @@ public class SQLDatasetController
|
||||
SQLDatasetService sqlDatasetService;
|
||||
|
||||
@DeleteMapping(value = "sql/query/{query_id}")
|
||||
@AuditLog("DatabaseController.killQuery")
|
||||
public BaseResult killQuery(@PathVariable("query_id") String queryId) {
|
||||
log.warn("停止查询, 参数: queryId is {}", queryId);
|
||||
log.warn("skill query, param: queryId is {}", queryId);
|
||||
if (StringUtil.isBlank(queryId)) {
|
||||
return BaseResultGenerator.success4Message("ok");
|
||||
}
|
||||
@@ -43,8 +45,9 @@ public class SQLDatasetController
|
||||
|
||||
|
||||
@RequestMapping(value = "sql/query/query_id", method = RequestMethod.POST)
|
||||
@AuditLog("DatabaseController.getQueryId")
|
||||
public BaseResult getQueryId(@RequestParam String query, @RequestParam(value = "result_id", required = false) Integer resultId) {
|
||||
log.info("获取当前SQL Query ID, 参数: query ={},result_id ={}", query, resultId);
|
||||
log.info("get current SQL Query ID, parma: query ={},result_id ={}", query, resultId);
|
||||
if (StringUtil.isEmpty(query)) {
|
||||
throw new QGWBusinessException(HttpStatusCodeEnum.BAD_REQUEST.getCode(), CommonErrorCode.PARAMETER_ERROR.getCode(),
|
||||
String.format(CommonErrorCode.PARAMETER_ERROR.getMessage(), QGWMessageConst.QUERY_CANNOT_BE_EMPTY));
|
||||
@@ -63,8 +66,9 @@ public class SQLDatasetController
|
||||
}
|
||||
|
||||
@GetMapping(value = "sql/query/{query_id}/progress")
|
||||
@AuditLog("DatabaseController.getProcessesByQueryId")
|
||||
public BaseResult getProcessesByQueryId(@PathVariable("query_id") String queryId) {
|
||||
log.info("查询SQL任务执行状态, 参数: queryId is {}", queryId);
|
||||
log.info("get query status, param: queryId is {}", queryId);
|
||||
return sqlDatasetService.getProcessesByQueryId(queryId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user