Authored by wangning

update

... ... @@ -264,6 +264,9 @@ public class TraceAnalyzeHandler implements TraceHandler, Serializable {
//3处理异常调用链信息
handlerExceptionTrace(apiResultTraceDStream);
//4处理所有traceid
handlerAllTrace(apiResultTraceDStream);
}
... ... @@ -449,4 +452,51 @@ public class TraceAnalyzeHandler implements TraceHandler, Serializable {
}
});
}
private void handlerAllTrace(JavaPairDStream<String, ApiTraceResult> apiResultTraceDStream){
apiResultTraceDStream.foreachRDD(new VoidFunction<JavaPairRDD<String, ApiTraceResult>>() {
@Override
public void call(JavaPairRDD<String, ApiTraceResult> stringSortedTraceJavaPairRDD) throws Exception {
stringSortedTraceJavaPairRDD.foreachPartition(new VoidFunction<Iterator<Tuple2<String, ApiTraceResult>>>() {
@Override
public void call(Iterator<Tuple2<String, ApiTraceResult>> tuple2Iterator) throws Exception {
HTable resultTable = null;
try {
if(tuple2Iterator == null){
return;
}
if (resultTable == null) {
resultTable = (HTable) HBasePool.getConnection().getTable(TableName.valueOf("all_trace"));
}
List<Put> putList = new ArrayList<>();
while(tuple2Iterator.hasNext()){
Tuple2<String, ApiTraceResult> next = tuple2Iterator.next();
ApiTraceResult apiTraceResult = next._2;
String[] md5Tags = StringUtils.split(apiTraceResult.getTraceMd5(), '.');
Put put = new Put(Bytes.toBytes( md5Tags[1] + ":" + apiTraceResult.getTraceStartTime()/1000 + ":" + apiTraceResult.getTraceId()));
put.addColumn(Bytes.toBytes("data"), Bytes.toBytes("spans"), Bytes.toBytes(JSONObject.toJSONString(apiTraceResult.getSpans())));
put.addColumn(Bytes.toBytes("data"), Bytes.toBytes("traceid"), Bytes.toBytes(apiTraceResult.getTraceId()));
put.addColumn(Bytes.toBytes("data"), Bytes.toBytes("starttime"), Bytes.toBytes(apiTraceResult.getTraceStartTime()/1000));
put.addColumn(Bytes.toBytes("data"), Bytes.toBytes("traceMd5"), Bytes.toBytes(apiTraceResult.getTraceMd5()));
putList.add(put);
}
resultTable.put(putList);
} catch (Exception e) {
logger.error(e.getMessage(),e);
} finally {
if (resultTable != null)
resultTable.close();
}
}
});
}
});
}
}
... ...