Authored by wangning

update

@@ -31,42 +31,42 @@ public class ApiStatisticsResultStore { @@ -31,42 +31,42 @@ public class ApiStatisticsResultStore {
31 logger.info("store api statistics result to hbase "); 31 logger.info("store api statistics result to hbase ");
32 32
33 //调试打印 33 //调试打印
34 - if (logger.isDebugEnabled()) {  
35 - apiResultRdd.foreach(  
36 - new VoidFunction<Tuple2<String, ApiTraceResult>>() {  
37 - @Override  
38 - public void call(Tuple2<String, ApiTraceResult> tuple2) throws Exception {  
39 -  
40 - ApiTraceResult result = tuple2._2();  
41 -  
42 - logger.debug("++++++++++++++++++++++++++++++++++++++++++++");  
43 - logger.debug(" ");  
44 - logger.debug("API:" + result.getApiName());  
45 - logger.debug(" Avg Response(ms): " + result.getDuration() + " ms");  
46 - logger.debug(" Times: " + result.getCallTimes());  
47 - logger.debug(" max latency: " + result.getMaxLatencyTrace() + " " + result.getMaxLatency() + " ms");  
48 - logger.debug(" min latency: " + result.getMinLatencyTrace() + " " + result.getMinLatency() + " ms");  
49 - logger.debug(" Sample Trace: ");  
50 -  
51 - List<SpanResult> list = result.getSpans();  
52 - for (int i = 0; i < list.size(); i++) {  
53 -  
54 - StringBuffer sb = new StringBuffer();  
55 - for (int n = 0; n < list.get(i).getLevel(); n++) {  
56 - sb.append(" ");  
57 - }  
58 - logger.debug(" " + i + ":" + sb.toString() + list.get(i).getSpanName()  
59 - + " (" + String.valueOf(list.get(i).getDuration()) + "ms) "  
60 - + " id:" + list.get(i).getSpanId()  
61 - + " parent:" + list.get(i).getParent());  
62 - }  
63 -  
64 - Thread.sleep(200);  
65 -  
66 - }  
67 - }  
68 - );  
69 - } 34 +// if (logger.isDebugEnabled()) {
  35 +// apiResultRdd.foreach(
  36 +// new VoidFunction<Tuple2<String, ApiTraceResult>>() {
  37 +// @Override
  38 +// public void call(Tuple2<String, ApiTraceResult> tuple2) throws Exception {
  39 +//
  40 +// ApiTraceResult result = tuple2._2();
  41 +//
  42 +// logger.debug("++++++++++++++++++++++++++++++++++++++++++++");
  43 +// logger.debug(" ");
  44 +// logger.debug("API:" + result.getApiName());
  45 +// logger.debug(" Avg Response(ms): " + result.getDuration() + " ms");
  46 +// logger.debug(" Times: " + result.getCallTimes());
  47 +// logger.debug(" max latency: " + result.getMaxLatencyTrace() + " " + result.getMaxLatency() + " ms");
  48 +// logger.debug(" min latency: " + result.getMinLatencyTrace() + " " + result.getMinLatency() + " ms");
  49 +// logger.debug(" Sample Trace: ");
  50 +//
  51 +// List<SpanResult> list = result.getSpans();
  52 +// for (int i = 0; i < list.size(); i++) {
  53 +//
  54 +// StringBuffer sb = new StringBuffer();
  55 +// for (int n = 0; n < list.get(i).getLevel(); n++) {
  56 +// sb.append(" ");
  57 +// }
  58 +// logger.debug(" " + i + ":" + sb.toString() + list.get(i).getSpanName()
  59 +// + " (" + String.valueOf(list.get(i).getDuration()) + "ms) "
  60 +// + " id:" + list.get(i).getSpanId()
  61 +// + " parent:" + list.get(i).getParent());
  62 +// }
  63 +//
  64 +// Thread.sleep(200);
  65 +//
  66 +// }
  67 +// }
  68 +// );
  69 +// }
70 70
71 71
72 72
@@ -84,18 +84,21 @@ public class ApiStatisticsResultStore { @@ -84,18 +84,21 @@ public class ApiStatisticsResultStore {
84 } 84 }
85 85
86 List<Put> putList = new ArrayList<>(); 86 List<Put> putList = new ArrayList<>();
  87 + long now = System.currentTimeMillis()/1000;
87 while(tuple2Iterator.hasNext()){ 88 while(tuple2Iterator.hasNext()){
88 Tuple2<String, ApiTraceResult> next = tuple2Iterator.next(); 89 Tuple2<String, ApiTraceResult> next = tuple2Iterator.next();
89 ApiTraceResult apiTraceResult = next._2; 90 ApiTraceResult apiTraceResult = next._2;
90 - String rowkey = apiTraceResult.getApiName() + ":" + apiTraceResult.getTraceMd5();  
91 - Put put = new Put(Bytes.toBytes(rowkey));  
92 - put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("api"), Bytes.toBytes(apiTraceResult.getApiName()));  
93 String[] md5Tags = StringUtils.split(apiTraceResult.getTraceMd5(), '.'); 91 String[] md5Tags = StringUtils.split(apiTraceResult.getTraceMd5(), '.');
94 if (null == md5Tags || 2 != md5Tags.length) { 92 if (null == md5Tags || 2 != md5Tags.length) {
95 - put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("traceMd5"), Bytes.toBytes(StringUtils.EMPTY));  
96 - } else {  
97 - put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("traceMd5"), Bytes.toBytes(md5Tags[1])); 93 + continue;
98 } 94 }
  95 +
  96 + String md5 = md5Tags[1];
  97 +
  98 + String rowkey = apiTraceResult.getApiName() + ":" + now + ":" + md5;
  99 + Put put = new Put(Bytes.toBytes(rowkey));
  100 + put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("api"), Bytes.toBytes(apiTraceResult.getApiName()));
  101 +
99 put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("duration"), Bytes.toBytes(apiTraceResult.getDuration())); 102 put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("duration"), Bytes.toBytes(apiTraceResult.getDuration()));
100 put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("times"), Bytes.toBytes(apiTraceResult.getCallTimes())); 103 put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("times"), Bytes.toBytes(apiTraceResult.getCallTimes()));
101 put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("maxLatency"), Bytes.toBytes(apiTraceResult.getMaxLatency())); 104 put.addColumn(Bytes.toBytes("trace"), Bytes.toBytes("maxLatency"), Bytes.toBytes(apiTraceResult.getMaxLatency()));