首届云原生编程挑战赛1: 实现一个分布式统计和过滤的链路追踪 跑demo
比赛链接:https://tianchi.aliyun.com/competition/entrance/231790/information
这篇博客的目的是将官方提供的demo程序跑起来。demo程序写的很好,值得多多借鉴。
第一步:下载demo程序
下载地址:https://code.aliyun.com/middleware-contest-2020/tail-based-sampling
下载得到zip包,解压,使用IDEA打开,是一个标准的springboot程序。
第二步:下载测试数据
第三步:修改源码
运行方式采用程序方式,获取链路数据文件采用本地获取。
只修改 com.alibaba.tailbase.clientprocess 包下的 ClientProcessData类。
修改 getPath()函数如下:
private String getPath(){
String port = System.getProperty("server.port", "8080");
if ("8000".equals(port)) {
// 文件放在本地
return "file:///home/tianchi/data/trace1.data";
// return "http://localhost:" + CommonController.getDataSourcePort() + "/trace1.data";
} else if ("8001".equals(port)){
return "file:///home/tianchi/data/trace2.data";
// return "http://localhost:" + CommonController.getDataSourcePort() + "/trace2.data";
} else {
return null;
}
}在 run()函数的开头修改获取文件方式:
URL url = new URL(path);
LOGGER.info("data path:" + path);
// HttpURLConnection httpConnection = (HttpURLConnection) url.openConnection(Proxy.NO_PROXY);
// InputStream input = httpConnection.getInputStream();
InputStream input = url.openStream();
BufferedReader bf = new BufferedReader(new InputStreamReader(input));编译打包成jar吧。
第四步:跑起来
打开四个shell界面,
shell1执行如下命令:
// jar文件路径改为自己的 java -Dserver.port=8000 -jar /home/tianchi/tailbaseSampling-1.0-SNAPSHOT.jar &
shell2执行如下命令:
// jar文件路径改为自己的 java -Dserver.port=8001 -jar /home/tianchi/tailbaseSampling-1.0-SNAPSHOT.jar &
shell3执行如下命令:
// jar文件路径改为自己的 java -Dserver.port=8002 -jar /home/tianchi/tailbaseSampling-1.0-SNAPSHOT.jar &
shell4执行如下命令:
// jar文件路径改为自己的 java -Dserver.port=9000 -DcheckSumPath=/home/tianchi/data/checkSum.data -jar /home/tianchi/data/scoring-1.0-SNAPSHOT.jar
稍等片刻,在shell4界面看到如下结果。
官方demo给出了比赛的一个基本思路,代码写的真好,感觉自己什么时候才能写出这么漂亮的代码。
最后有一起比赛的可以联系我。

查看5道真题和解析