1.增加打印日志
2.修复Mapper传出的key不是CallEntrance而是EntranceNodeToken 3.增加log4j的依赖,便于输出日志
This commit is contained in:
parent
ec6501b0ae
commit
dac6ec24fe
|
|
@ -54,6 +54,11 @@
|
|||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.38</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -16,15 +16,16 @@ import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
|
|||
import org.apache.hadoop.hbase.mapreduce.TableMapper;
|
||||
import org.apache.hadoop.hbase.util.Bytes;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class ChainBuildMapper extends TableMapper<Text, Text> {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ChainBuildMapper.class);
|
||||
private Logger logger = LogManager.getLogger(ChainBuildMapper.class);
|
||||
|
||||
@Override
|
||||
protected void setup(Context context) throws IOException,
|
||||
|
|
@ -56,9 +57,8 @@ public class ChainBuildMapper extends TableMapper<Text, Text> {
|
|||
logger.debug("convert tid[" + Bytes.toString(key.get())
|
||||
+ "] to chain with cid[" + chainInfo.getCID() + "].");
|
||||
context.write(
|
||||
new Text(chainInfo.getEntranceNodeToken()), new Text(new Gson().toJson(chainInfo)));
|
||||
new Text(chainInfo.getCallEntrance()), new Text(new Gson().toJson(chainInfo)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error("Failed to mapper call chain[" + key.toString() + "]",
|
||||
e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ import org.apache.hadoop.hbase.util.Bytes;
|
|||
import org.apache.hadoop.io.IntWritable;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.hadoop.mapreduce.Reducer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class ChainBuildReducer extends Reducer<Text, Text, Text, IntWritable> {
|
||||
private Logger logger = LoggerFactory.getLogger(ChainBuildReducer.class);
|
||||
private Logger logger = LogManager.getLogger(ChainBuildReducer.class);
|
||||
|
||||
@Override
|
||||
protected void setup(Context context) throws IOException,
|
||||
|
|
@ -33,7 +33,8 @@ public class ChainBuildReducer extends Reducer<Text, Text, Text, IntWritable> {
|
|||
public void doReduceAction(String key, Iterator<Text> chainInfoIterator)
|
||||
throws IOException, InterruptedException {
|
||||
CallChainTree chainTree = CallChainTree.load(key);
|
||||
SpecificTimeCallTreeMergedChainIdContainer container = new SpecificTimeCallTreeMergedChainIdContainer(chainTree.getTreeToken());
|
||||
SpecificTimeCallTreeMergedChainIdContainer container
|
||||
= new SpecificTimeCallTreeMergedChainIdContainer(chainTree.getTreeToken());
|
||||
while (chainInfoIterator.hasNext()) {
|
||||
String callChainData = chainInfoIterator.next().toString();
|
||||
ChainInfo chainInfo = null;
|
||||
|
|
@ -42,7 +43,6 @@ public class ChainBuildReducer extends Reducer<Text, Text, Text, IntWritable> {
|
|||
container.addMergedChainIfNotContain(chainInfo);
|
||||
chainTree.summary(chainInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.error(
|
||||
"Failed to summary call chain, maybe illegal data:"
|
||||
+ callChainData, e);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,12 @@ import java.util.Map;
|
|||
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainInfo;
|
||||
import com.ai.cloud.skywalking.analysis.chainbuild.po.ChainNode;
|
||||
import com.ai.cloud.skywalking.analysis.chainbuild.util.TokenGenerator;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class CallChainTree {
|
||||
private Logger logger = LogManager.getLogger(CallChainTree.class);
|
||||
|
||||
private String callEntrance;
|
||||
|
||||
private String treeToken;
|
||||
|
|
@ -23,6 +27,7 @@ public class CallChainTree {
|
|||
nodes = new HashMap<String, CallChainTreeNode>();
|
||||
this.callEntrance = callEntrance;
|
||||
this.treeToken = TokenGenerator.generateTreeToken(callEntrance);
|
||||
logger.info("CallEntrance:[{}] == TreeToken[{}]",callEntrance, treeToken);
|
||||
}
|
||||
|
||||
public static CallChainTree load(String callEntrance) throws IOException {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import com.ai.cloud.skywalking.analysis.config.HBaseTableMetaData;
|
|||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import org.apache.hadoop.hbase.client.Put;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
|
@ -17,6 +19,8 @@ import java.util.*;
|
|||
* @author wusheng
|
||||
*/
|
||||
public class CallChainTreeNode {
|
||||
private Logger logger = LogManager.getLogger(CallChainTreeNode.class);
|
||||
|
||||
@Expose
|
||||
private String traceLevelId;
|
||||
@Expose
|
||||
|
|
|
|||
|
|
@ -62,46 +62,11 @@ public class CallChainMapperTest {
|
|||
return entries;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDataIsCorrect() throws IOException, ParseException {
|
||||
List<ChainInfo> chainInfos = selectSpans();
|
||||
Iterator<ChainInfo> chainInfoIterator = chainInfos.iterator();
|
||||
while (chainInfoIterator.hasNext()) {
|
||||
ChainInfo chainInfo = chainInfoIterator.next();
|
||||
if (!"http://m.aisse.asiainfo.com/aisseWorkPage/workPay".equals(chainInfo.getCallEntrance())) {
|
||||
chainInfoIterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, List<ChainNode>> result = new HashMap<>();
|
||||
for (int i = 0; i < chainInfos.size(); i++) {
|
||||
for (ChainNode chainNode :chainInfos.get(i).getNodes()){
|
||||
if ("0".equals(chainNode.getTraceLevelId())){
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(new Date(chainNode.getStartDate()));
|
||||
List<ChainNode> chainNodes = result.get(getKey(calendar));
|
||||
if (chainNodes == null){
|
||||
chainNodes = new ArrayList<>();
|
||||
}
|
||||
chainNodes.add(chainNode);
|
||||
result.put(getKey(calendar), chainNodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(result.size());
|
||||
}
|
||||
|
||||
private String getKey(Calendar calendar) {
|
||||
return calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH)) + "-"
|
||||
+ calendar.get(Calendar.DAY_OF_MONTH) + " " + calendar.get(Calendar.HOUR) + ":00:00";
|
||||
}
|
||||
|
||||
public static List<ChainInfo> selectSpans() throws IOException, ParseException {
|
||||
List<ChainInfo> chainInfos = new ArrayList<ChainInfo>();
|
||||
Table table = connection.getTable(TableName.valueOf(HBaseTableMetaData.TABLE_CALL_CHAIN.TABLE_NAME));
|
||||
Scan scan = new Scan();
|
||||
scan.setTimeRange(new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss").parse("2015-12-09/18:44:48").getTime(), new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss").parse("2016-03-09/18:44:48").getTime());
|
||||
scan.setTimeRange(new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss").parse("2016-01-10/11:55:48").getTime(), new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss").parse("2016-02-10/11:55:48").getTime());
|
||||
ResultScanner resultScanner = table.getScanner(scan);
|
||||
Iterator<Result> resultIterator = resultScanner.iterator();
|
||||
while (resultIterator.hasNext()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue