(improvement)(code) Replace e.printStackTrace() with logger.error. (#1156)

This commit is contained in:
lexluo09
2024-06-15 18:26:52 +08:00
committed by GitHub
parent b5cc450758
commit f2a12e56b7
9 changed files with 39 additions and 36 deletions

View File

@@ -5,6 +5,7 @@ import com.tencent.supersonic.auth.api.authentication.constant.UserConstants;
import com.tencent.supersonic.auth.authentication.service.UserServiceImpl; import com.tencent.supersonic.auth.authentication.service.UserServiceImpl;
import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils; import com.tencent.supersonic.auth.authentication.utils.UserTokenUtils;
import com.tencent.supersonic.common.util.S2ThreadContext; import com.tencent.supersonic.common.util.S2ThreadContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.connector.RequestFacade; import org.apache.catalina.connector.RequestFacade;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings; import org.apache.logging.log4j.util.Strings;
@@ -17,7 +18,7 @@ import java.lang.reflect.Field;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@Slf4j
public abstract class AuthenticationInterceptor implements HandlerInterceptor { public abstract class AuthenticationInterceptor implements HandlerInterceptor {
@@ -64,7 +65,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
return StringUtils.isNotBlank(appId); return StringUtils.isNotBlank(appId);
} }
protected void reflectSetparam(HttpServletRequest request, String key, String value) { protected void reflectSetParam(HttpServletRequest request, String key, String value) {
try { try {
if (request instanceof StandardMultipartHttpServletRequest) { if (request instanceof StandardMultipartHttpServletRequest) {
RequestFacade servletRequest = RequestFacade servletRequest =
@@ -98,7 +99,7 @@ public abstract class AuthenticationInterceptor implements HandlerInterceptor {
o2.addValue(key).setString(value); o2.addValue(key).setString(value);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("reflectSetParam error:", e);
} }
} }
} }

View File

@@ -67,7 +67,7 @@ public class DefaultAuthenticationInterceptor extends AuthenticationInterceptor
private void setFakerUser(HttpServletRequest request) { private void setFakerUser(HttpServletRequest request) {
String token = userTokenUtils.generateAdminToken(request); String token = userTokenUtils.generateAdminToken(request);
reflectSetparam(request, authenticationConfig.getTokenHttpHeaderKey(), token); reflectSetParam(request, authenticationConfig.getTokenHttpHeaderKey(), token);
setContext(User.getFakeUser().getName(), request); setContext(User.getFakeUser().getName(), request);
} }

View File

@@ -3,8 +3,9 @@ package com.tencent.supersonic.common.util;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.Base64; import java.util.Base64;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class MD5Util { public class MD5Util {
@@ -44,7 +45,7 @@ public class MD5Util {
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("", e);
} }
if (isUpper) { if (isUpper) {

View File

@@ -12,8 +12,9 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLMapper;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class YamlUtils { public class YamlUtils {
/** /**
@@ -30,7 +31,7 @@ public class YamlUtils {
try { try {
return mapper.readValue(yamlStr, clazz); return mapper.readValue(yamlStr, clazz);
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); log.error("", e);
} }
return null; return null;
} }
@@ -53,7 +54,7 @@ public class YamlUtils {
.replaceAll("\"false\"", "false") .replaceAll("\"false\"", "false")
.replaceAll("\"False\"", "false"); .replaceAll("\"False\"", "false");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); log.error("", e);
} }
return null; return null;
} }

View File

@@ -32,8 +32,7 @@ public class LocalFileConfig {
try { try {
return HanlpHelper.getHanlpPropertiesPath(); return HanlpHelper.getHanlpPropertiesPath();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
log.warn("getDictDirectoryPrefixDir error: " + e); log.error("getDictDirectoryPrefixDir error: ", e);
e.printStackTrace();
} }
return ""; return "";
} }

View File

@@ -59,16 +59,16 @@ public class SqlQueryApiController {
chatQueryService.correct(querySqlReq, user); chatQueryService.correct(querySqlReq, user);
return querySqlReq; return querySqlReq;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
List<CompletableFuture<SemanticQueryResp>> futures = semanticQueryReqs.stream() List<CompletableFuture<SemanticQueryResp>> futures = semanticQueryReqs.stream()
.map(querySqlReq -> CompletableFuture.supplyAsync(() -> { .map(querySqlReq -> CompletableFuture.supplyAsync(() -> {
try { try {
return queryService.queryByReq(querySqlReq, user); return queryService.queryByReq(querySqlReq, user);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("querySqlReq:{},queryByReq error:", querySqlReq, e);
return new SemanticQueryResp(); return new SemanticQueryResp();
} }
})) })).collect(Collectors.toList());
.collect(Collectors.toList());
return futures.stream().map(CompletableFuture::join).collect(Collectors.toList()); return futures.stream().map(CompletableFuture::join).collect(Collectors.toList());
} }

View File

@@ -1,5 +1,11 @@
package com.tencent.supersonic.headless.server.utils; package com.tencent.supersonic.headless.server.utils;
import static com.tencent.supersonic.common.pojo.Constants.AND_UPPER;
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE;
import static com.tencent.supersonic.common.pojo.Constants.COMMA;
import static com.tencent.supersonic.common.pojo.Constants.POUND;
import static com.tencent.supersonic.common.pojo.Constants.SPACE;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.tencent.supersonic.auth.api.authentication.pojo.User; import com.tencent.supersonic.auth.api.authentication.pojo.User;
import com.tencent.supersonic.common.pojo.Aggregator; import com.tencent.supersonic.common.pojo.Aggregator;
@@ -34,13 +40,6 @@ import com.tencent.supersonic.headless.server.service.MetricService;
import com.tencent.supersonic.headless.server.service.ModelService; import com.tencent.supersonic.headless.server.service.ModelService;
import com.tencent.supersonic.headless.server.service.QueryService; import com.tencent.supersonic.headless.server.service.QueryService;
import com.tencent.supersonic.headless.server.service.TagMetaService; import com.tencent.supersonic.headless.server.service.TagMetaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList; import java.util.ArrayList;
@@ -53,12 +52,12 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.StringJoiner; import java.util.StringJoiner;
import lombok.extern.slf4j.Slf4j;
import static com.tencent.supersonic.common.pojo.Constants.AND_UPPER; import org.springframework.beans.BeanUtils;
import static com.tencent.supersonic.common.pojo.Constants.APOSTROPHE; import org.springframework.beans.factory.annotation.Value;
import static com.tencent.supersonic.common.pojo.Constants.COMMA; import org.springframework.context.annotation.Lazy;
import static com.tencent.supersonic.common.pojo.Constants.POUND; import org.springframework.stereotype.Component;
import static com.tencent.supersonic.common.pojo.Constants.SPACE; import org.springframework.util.CollectionUtils;
@Slf4j @Slf4j
@Component @Component
@@ -87,10 +86,10 @@ public class DictUtils {
private final TagMetaService tagMetaService; private final TagMetaService tagMetaService;
public DictUtils(DimensionService dimensionService, public DictUtils(DimensionService dimensionService,
MetricService metricService, MetricService metricService,
QueryService queryService, QueryService queryService,
ModelService modelService, ModelService modelService,
@Lazy TagMetaService tagMetaService) { @Lazy TagMetaService tagMetaService) {
this.dimensionService = dimensionService; this.dimensionService = dimensionService;
this.metricService = metricService; this.metricService = metricService;
this.queryService = queryService; this.queryService = queryService;
@@ -190,7 +189,7 @@ public class DictUtils {
constructDictLines(valueAndFrequencyPair, lines, nature); constructDictLines(valueAndFrequencyPair, lines, nature);
addWhiteValueLines(dictItemResp, lines, nature); addWhiteValueLines(dictItemResp, lines, nature);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("dictItemResp:{},fetchItemValue error:", dictItemResp, e);
} }
return lines; return lines;
} }

View File

@@ -130,7 +130,7 @@ public class StatUtils {
queryStatInfo.setModelId(queryTagReq.getModelIds().get(0)); queryStatInfo.setModelId(queryTagReq.getModelIds().get(0));
} }
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); log.error("", e);
} }
StatUtils.set(queryStatInfo); StatUtils.set(queryStatInfo);
@@ -198,7 +198,7 @@ public class StatUtils {
queryStatInfo.setModelId(queryStructReq.getModelIds().get(0)); queryStatInfo.setModelId(queryStructReq.getModelIds().get(0));
} }
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); log.error("", e);
} }
StatUtils.set(queryStatInfo); StatUtils.set(queryStatInfo);

View File

@@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
import com.tencent.supersonic.auth.api.authentication.utils.UserHolder; import com.tencent.supersonic.auth.api.authentication.utils.UserHolder;
import com.tencent.supersonic.auth.authentication.strategy.FakeUserStrategy; import com.tencent.supersonic.auth.authentication.strategy.FakeUserStrategy;
import com.tencent.supersonic.headless.server.listener.FlightSqlListener; import com.tencent.supersonic.headless.server.listener.FlightSqlListener;
import lombok.extern.slf4j.Slf4j;
import org.apache.arrow.flight.CallHeaders; import org.apache.arrow.flight.CallHeaders;
import org.apache.arrow.flight.FlightCallHeaders; import org.apache.arrow.flight.FlightCallHeaders;
import org.apache.arrow.flight.FlightClient; import org.apache.arrow.flight.FlightClient;
@@ -18,6 +19,7 @@ import org.apache.arrow.memory.RootAllocator;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@Slf4j
public class FlightSqlTest extends BaseTest { public class FlightSqlTest extends BaseTest {
@@ -59,7 +61,7 @@ public class FlightSqlTest extends BaseTest {
assertEquals(2, colCnt); assertEquals(2, colCnt);
assertTrue(rowCnt > 0); assertTrue(rowCnt > 0);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("", e);
} }
} }
@@ -95,7 +97,7 @@ public class FlightSqlTest extends BaseTest {
assertEquals(2, colCnt); assertEquals(2, colCnt);
assertTrue(rowCnt > 0); assertTrue(rowCnt > 0);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); log.error("", e);
} }
} }
} }