Authored by hugufei

超时统计添加开关

@@ -4,8 +4,11 @@ import javax.annotation.PostConstruct; @@ -4,8 +4,11 @@ import javax.annotation.PostConstruct;
4 import javax.servlet.http.HttpServletRequest; 4 import javax.servlet.http.HttpServletRequest;
5 import javax.servlet.http.HttpServletResponse; 5 import javax.servlet.http.HttpServletResponse;
6 6
  7 +import com.yoho.search.common.utils.HttpServletRequestUtils;
  8 +import com.yoho.search.service.base.SearchDynamicConfigService;
7 import org.slf4j.Logger; 9 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory; 10 import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.core.NamedThreadLocal; 12 import org.springframework.core.NamedThreadLocal;
10 import org.springframework.web.servlet.HandlerInterceptor; 13 import org.springframework.web.servlet.HandlerInterceptor;
11 import org.springframework.web.servlet.ModelAndView; 14 import org.springframework.web.servlet.ModelAndView;
@@ -30,6 +33,9 @@ public class ControllerCostInterceptor implements HandlerInterceptor { @@ -30,6 +33,9 @@ public class ControllerCostInterceptor implements HandlerInterceptor {
30 33
31 private PerformanceMonitor monitor; 34 private PerformanceMonitor monitor;
32 35
  36 + @Autowired
  37 + private SearchDynamicConfigService searchDynamicConfigService;
  38 +
33 @PostConstruct 39 @PostConstruct
34 void init() { 40 void init() {
35 monitor = new PerformanceMonitor("CONTROLLER_PERFORMANCE", CONTROLLER_PERFORMANCE, 10); 41 monitor = new PerformanceMonitor("CONTROLLER_PERFORMANCE", CONTROLLER_PERFORMANCE, 10);
@@ -66,8 +72,11 @@ public class ControllerCostInterceptor implements HandlerInterceptor { @@ -66,8 +72,11 @@ public class ControllerCostInterceptor implements HandlerInterceptor {
66 if (cost <= 500) { 72 if (cost <= 500) {
67 return; 73 return;
68 } 74 }
69 - // // 5、打印响应超过500ms的请求与参数  
70 - // CONTROLLER_COST.info("run more than 500ms ,cost [{}] ms, RequestURL: {}", cost, HttpServletRequestUtils.getRequestUrl(request)); 75 +
  76 + // 5、打印响应超过500ms的请求与参数
  77 + if(searchDynamicConfigService.isControllerCostLogOpen()){
  78 + CONTROLLER_COST.info("run more than 500ms ,cost [{}] ms, RequestURL: {}", cost, HttpServletRequestUtils.getRequestUrl(request));
  79 + }
71 } catch (Exception e) { 80 } catch (Exception e) {
72 // TODO: handle exception 81 // TODO: handle exception
73 } finally { 82 } finally {
@@ -215,5 +215,12 @@ public class SearchDynamicConfigService { @@ -215,5 +215,12 @@ public class SearchDynamicConfigService {
215 public boolean isSearchLikeSimilarSknOpen() { 215 public boolean isSearchLikeSimilarSknOpen() {
216 return configReader.getBoolean("search.searchlike.similarskn", true); 216 return configReader.getBoolean("search.searchlike.similarskn", true);
217 } 217 }
  218 +
  219 + /**
  220 + * 超时日志是否打开
  221 + */
  222 + public boolean isControllerCostLogOpen() {
  223 + return configReader.getBoolean("search.controller.cost.log.open", true);
  224 + }
218 225
219 } 226 }
@@ -51,6 +51,8 @@ search.persional.recommend.open=true @@ -51,6 +51,8 @@ search.persional.recommend.open=true
51 51
52 #searchlike 52 #searchlike
53 search.searchlike.similarskn=true 53 search.searchlike.similarskn=true
  54 +#log
  55 +search.controller.cost.log.open=true
54 56
55 search.persional.rateLimit.brand.productList=200:2 57 search.persional.rateLimit.brand.productList=200:2
56 search.persional.rateLimit.brand.aggregations=100:2 58 search.persional.rateLimit.brand.aggregations=100:2