mirror of
https://gitee.com/jd-platform-opensource/jlog.git
synced 2024-11-29 18:38:06 +08:00
!17 feat:记录接口异常信息;refactor:重构传输对象(map->obj)
Merge pull request !17 from imalasong/self
This commit is contained in:
commit
d7aa8833f7
2
.gitignore
vendored
2
.gitignore
vendored
@ -27,3 +27,5 @@ HELP.md
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
/log/
|
29
Dashboard/.gitignore
vendored
Normal file
29
Dashboard/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -193,7 +193,10 @@
|
||||
},
|
||||
{
|
||||
field: 'errmsg',
|
||||
title: '错误信息'
|
||||
title: '错误信息',
|
||||
formatter: function(value, row, index) {
|
||||
return $.table.tooltip(value, 100, "open");
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'createTime',
|
||||
|
29
client/.gitignore
vendored
Normal file
29
client/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -2,13 +2,13 @@ package com.jd.platform.jlog.client.filter;
|
||||
|
||||
import com.jd.platform.jlog.client.Context;
|
||||
import com.jd.platform.jlog.client.cache.ExtParamFactory;
|
||||
import com.jd.platform.jlog.client.log.LogExceptionStackTrace;
|
||||
import com.jd.platform.jlog.client.percent.DefaultTracerPercentImpl;
|
||||
import com.jd.platform.jlog.client.percent.ITracerPercent;
|
||||
import com.jd.platform.jlog.client.tracerholder.TracerHolder;
|
||||
import com.jd.platform.jlog.client.udp.UdpSender;
|
||||
import com.jd.platform.jlog.common.handler.CompressHandler.Outcome;
|
||||
import com.jd.platform.jlog.common.model.TracerBean;
|
||||
import com.jd.platform.jlog.common.utils.CollectionUtil;
|
||||
import com.jd.platform.jlog.common.handler.CompressHandler.Outcome;
|
||||
import com.jd.platform.jlog.common.utils.IdWorker;
|
||||
import com.jd.platform.jlog.common.utils.IpUtils;
|
||||
import com.jd.platform.jlog.core.ClientHandler;
|
||||
@ -18,13 +18,11 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
import static com.jd.platform.jlog.common.constant.Constant.REQ;
|
||||
import static com.jd.platform.jlog.common.constant.Constant.RESP;
|
||||
|
||||
|
||||
/**
|
||||
* HttpFilter
|
||||
@ -64,74 +62,64 @@ public class HttpFilter implements Filter {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletResponse resp = (HttpServletResponse) servletResponse;
|
||||
RequestWrapper requestWrapper = new RequestWrapper((HttpServletRequest) servletRequest);
|
||||
long currentTImeMills = System.currentTimeMillis();
|
||||
String uri = requestWrapper.getRequestURI().replace("/", "");
|
||||
//设置随机数
|
||||
Random random = new Random(currentTImeMills);
|
||||
//1-100之间
|
||||
int number = random.nextInt(100) + 1;
|
||||
//此处要有个开关,控制百分比
|
||||
if (iTracerPercent.percent() < number) {
|
||||
filterChain.doFilter(requestWrapper, servletResponse);
|
||||
return;
|
||||
}
|
||||
//如果是要忽略的接口,就继续执行,不搜集信息
|
||||
if (iTracerPercent.ignoreUriSet() != null && iTracerPercent.ignoreUriSet().contains(uri)) {
|
||||
filterChain.doFilter(requestWrapper, servletResponse);
|
||||
return;
|
||||
}
|
||||
//链路唯一Id
|
||||
long tracerId = IdWorker.nextId();
|
||||
TracerHolder.setTracerId(tracerId);
|
||||
TracerBean tracerBean = new TracerBean();
|
||||
tracerBean.setTracerId(tracerId);
|
||||
tracerBean.setCreateTimeLong(System.currentTimeMillis());
|
||||
tracerBean.setUri(uri);
|
||||
tracerBean.setApp(Context.APP_NAME);
|
||||
|
||||
//处理request的各个入参
|
||||
parseRequestMap(requestWrapper, tracerBean);
|
||||
try {
|
||||
HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
|
||||
HttpServletResponse resp = (HttpServletResponse) servletResponse;
|
||||
String uri = httpRequest.getRequestURI().replace("/", "");
|
||||
long currentTImeMills = System.currentTimeMillis();
|
||||
|
||||
//设置随机数
|
||||
Random random = new Random(currentTImeMills);
|
||||
//1-100之间
|
||||
int number = random.nextInt(100) + 1;
|
||||
//此处要有个开关,控制百分比
|
||||
if (iTracerPercent.percent() < number) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
//如果是要忽略的接口,就继续执行,不搜集信息
|
||||
if (iTracerPercent.ignoreUriSet() != null && iTracerPercent.ignoreUriSet().contains(uri)) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
return;
|
||||
}
|
||||
|
||||
//链路唯一Id
|
||||
long tracerId = IdWorker.nextId();
|
||||
TracerHolder.setTracerId(tracerId);
|
||||
|
||||
//传输对象基础属性设置
|
||||
TracerBean tracerBean = new TracerBean();
|
||||
tracerBean.setCreateTime(System.currentTimeMillis());
|
||||
List<Map<String, Object>> tracerObject = new ArrayList<>();
|
||||
tracerBean.setTracerObject(tracerObject);
|
||||
tracerBean.setTracerId(tracerId + "");
|
||||
|
||||
//处理request的各个入参
|
||||
dealRequestMap(servletRequest, tracerObject, tracerId, uri);
|
||||
|
||||
//处理response
|
||||
dealResponseMap(servletRequest, servletResponse, resp, tracerObject, filterChain);
|
||||
|
||||
tracerBean.setResponseContent(dealResponseMap(requestWrapper, servletResponse,
|
||||
resp, filterChain));
|
||||
} catch (Exception e) {
|
||||
//异常信息
|
||||
tracerBean.setErrmsg(LogExceptionStackTrace.erroStackTrace(e).toString());
|
||||
filterChain.doFilter(requestWrapper, servletResponse);
|
||||
}finally {
|
||||
//设置耗时
|
||||
tracerBean.setCostTime((int) (System.currentTimeMillis() - tracerBean.getCreateTime()));
|
||||
|
||||
tracerBean.setCostTime((System.currentTimeMillis() - tracerBean.getCreateTimeLong()));
|
||||
//udp发送
|
||||
UdpSender.offerBean(tracerBean);
|
||||
} catch (Exception e) {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理出参相关信息
|
||||
*/
|
||||
private void dealResponseMap(ServletRequest servletRequest, ServletResponse servletResponse, HttpServletResponse resp,
|
||||
List<Map<String, Object>> tracerObject, FilterChain filterChain) throws IOException, ServletException {
|
||||
private byte[] dealResponseMap(ServletRequest servletRequest, ServletResponse servletResponse, HttpServletResponse resp,
|
||||
FilterChain filterChain) throws IOException, ServletException {
|
||||
// 包装响应对象 resp 并缓存响应数据
|
||||
ResponseWrapper mResp = new ResponseWrapper(resp);
|
||||
filterChain.doFilter(servletRequest, mResp);
|
||||
byte[] contentBytes = mResp.getContent();
|
||||
String content = new String(contentBytes);
|
||||
Map<String, Object> responseMap = new HashMap<>(8);
|
||||
|
||||
Map<String, Object> map = ExtParamFactory.getRespMap(content);
|
||||
Outcome outcome = ClientHandler.processResp(contentBytes, map);
|
||||
responseMap.put(RESP, outcome.getContent());
|
||||
if(CollectionUtil.isNotEmpty(outcome.getTagMap())){
|
||||
responseMap.putAll(outcome.getTagMap());
|
||||
}
|
||||
tracerObject.add(responseMap);
|
||||
|
||||
//此处可以对content做处理,然后再把content写回到输出流中
|
||||
servletResponse.setContentLength(-1);
|
||||
@ -139,29 +127,25 @@ public class HttpFilter implements Filter {
|
||||
out.write(content);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
return (byte[]) outcome.getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理入参相关信息
|
||||
*/
|
||||
private void dealRequestMap(ServletRequest servletRequest, List<Map<String, Object>> tracerObject,
|
||||
long tracerId, String uri) throws IllegalAccessException, InstantiationException {
|
||||
private void parseRequestMap(RequestWrapper requestWrapper, TracerBean tracerBean) {
|
||||
//request的各个入参
|
||||
Map<String, String[]> params = servletRequest.getParameterMap();
|
||||
Map<String, String[]> params = requestWrapper.getParameterMap();
|
||||
Map<String, Object> requestMap = new HashMap<>(params.size());
|
||||
for (String key : params.keySet()) {
|
||||
requestMap.put(key, params.get(key)[0]);
|
||||
}
|
||||
requestMap.put("appName", Context.APP_NAME);
|
||||
requestMap.put("serverIp", IpUtils.getIp());
|
||||
requestMap.put("tracerId", tracerId);
|
||||
requestMap.put("uri", uri);
|
||||
tracerBean.setUid((String) requestMap.get("uid"));
|
||||
// 自定义的其他的参数对
|
||||
requestMap.putAll(ExtParamFactory.getReqMap(servletRequest));
|
||||
|
||||
requestMap.putAll(ExtParamFactory.getReqMap(requestWrapper));
|
||||
Outcome out = ClientHandler.processReq(requestMap);
|
||||
requestMap.put(REQ, out.getContent());
|
||||
tracerObject.add(out.getTagMap());
|
||||
tracerBean.setRequestContent((byte[]) out.getContent());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4,13 +4,13 @@ import com.jd.platform.jlog.client.Context;
|
||||
import com.jd.platform.jlog.client.modeholder.ModeHolder;
|
||||
import com.jd.platform.jlog.client.worker.WorkerInfoHolder;
|
||||
import com.jd.platform.jlog.common.constant.Constant;
|
||||
import com.jd.platform.jlog.common.model.RunLogMessage;
|
||||
import com.jd.platform.jlog.common.constant.LogTypeEnum;
|
||||
import com.jd.platform.jlog.common.model.TracerBean;
|
||||
import com.jd.platform.jlog.common.model.RunLogMessage;
|
||||
import com.jd.platform.jlog.common.model.TracerData;
|
||||
import com.jd.platform.jlog.common.utils.AsyncPool;
|
||||
import com.jd.platform.jlog.common.utils.AsyncWorker;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.socket.DatagramPacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -57,9 +57,9 @@ public class UdpSender {
|
||||
/**
|
||||
* 写入队列
|
||||
*/
|
||||
public static void offerBean(TracerBean tracerBean) {
|
||||
public static void offerBean(TracerBean tracerModel) {
|
||||
//容量是否已满
|
||||
boolean success = tracerBeanQueue.offer(tracerBean);
|
||||
boolean success = tracerBeanQueue.offer(tracerModel);
|
||||
if (!success) {
|
||||
long failCount = FAIL_OFFER_COUNT.incrementAndGet();
|
||||
if (failCount % 10 == 0) {
|
||||
@ -105,7 +105,10 @@ public class UdpSender {
|
||||
TracerBean tracerBean = tracerBeanQueue.take();
|
||||
tempTracers.add(tracerBean);
|
||||
|
||||
send(tempTracers);
|
||||
TracerData tracerData = new TracerData();
|
||||
tracerData.setTracerBeanList(tempTracers);
|
||||
tracerData.setType(LogTypeEnum.SPAN);
|
||||
send(tracerData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -121,21 +124,10 @@ public class UdpSender {
|
||||
if (tempLogs.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
List<TracerBean> tempTracers = new ArrayList<>();
|
||||
TracerBean tracerBean = new TracerBean();
|
||||
tracerBean.setTracerId("-1");
|
||||
List<Map<String, Object>> tracerObject = new ArrayList<>();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
for (RunLogMessage runLogMessage : tempLogs) {
|
||||
map.put(UUID.randomUUID().toString(), runLogMessage);
|
||||
}
|
||||
tracerObject.add(map);
|
||||
tracerBean.setTracerObject(tracerObject);
|
||||
tempTracers.add(tracerBean);
|
||||
|
||||
send(tempTracers);
|
||||
TracerData tracerData = new TracerData();
|
||||
tracerData.setTempLogs(tempLogs);
|
||||
tracerData.setType(LogTypeEnum.TRADE);
|
||||
send(tracerData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -146,9 +138,7 @@ public class UdpSender {
|
||||
/**
|
||||
* 往worker发traceBean
|
||||
*/
|
||||
private static void send(List<TracerBean> tracerBeans) throws InterruptedException {
|
||||
TracerData tracerData = new TracerData();
|
||||
tracerData.setTracerBeanList(tracerBeans);
|
||||
private static void send(TracerData tracerData) throws InterruptedException {
|
||||
if(!ModeHolder.getSendMode().getUnicast()){
|
||||
List<String>ips= WorkerInfoHolder.selectWorkers();
|
||||
for(String ip:ips){
|
||||
|
29
clientlog4j/.gitignore
vendored
Normal file
29
clientlog4j/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
clientlog4j2/.gitignore
vendored
Normal file
29
clientlog4j2/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
clientlogback/.gitignore
vendored
Normal file
29
clientlogback/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
common/.gitignore
vendored
Normal file
29
common/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -0,0 +1,15 @@
|
||||
package com.jd.platform.jlog.common.constant;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author xiaochangbai
|
||||
* @date 2023-07-15 11:56
|
||||
*/
|
||||
public enum LogTypeEnum implements Serializable {
|
||||
|
||||
TRADE,
|
||||
|
||||
SPAN;
|
||||
|
||||
}
|
@ -107,4 +107,19 @@ public class RunLogMessage {
|
||||
public void setTagMap(Map<String, Object> tagMap) {
|
||||
this.tagMap = tagMap;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RunLogMessage{" +
|
||||
"tracerId=" + tracerId +
|
||||
", createTime=" + createTime +
|
||||
", content=" + content +
|
||||
", logLevel='" + logLevel + '\'' +
|
||||
", className='" + className + '\'' +
|
||||
", methodName='" + methodName + '\'' +
|
||||
", threadName='" + threadName + '\'' +
|
||||
", tagMap=" + tagMap +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,75 +1,130 @@
|
||||
package com.jd.platform.jlog.common.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 承载传输信息的对象
|
||||
* @author wuweifeng
|
||||
* @version 1.0
|
||||
* @date 2021-08-12
|
||||
* @author xiaochangbai
|
||||
* @date 2023-07-15 11:25
|
||||
*/
|
||||
public class TracerBean implements Serializable {
|
||||
/**
|
||||
* 时间戳
|
||||
*/
|
||||
private long createTime;
|
||||
/**
|
||||
* 耗时(毫秒)
|
||||
*/
|
||||
private int costTime;
|
||||
/**
|
||||
* 唯一id,代表一条链路
|
||||
*/
|
||||
private String tracerId;
|
||||
/**
|
||||
* tracer对象,里面放的是List<Map<String, Object>>
|
||||
* 第一个元素是request对象,key为request,value为完整request入参,从中可找到uuid
|
||||
* 最后一个元素是response响应,key为response,value为响应值byte[],可转为String入库
|
||||
*/
|
||||
private List<Map<String, Object>> tracerObject;
|
||||
|
||||
private Long tracerId;
|
||||
private byte[] requestContent;
|
||||
private byte[] responseContent;
|
||||
private Long costTime;
|
||||
private String uid;
|
||||
private String errno;
|
||||
private String errmsg;
|
||||
private String app;
|
||||
private String uri;
|
||||
private String createTime;
|
||||
|
||||
private Long createTimeLong;
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TracerBean{" +
|
||||
"createTime=" + createTime +
|
||||
", costTime=" + costTime +
|
||||
", tracerId='" + tracerId + '\'' +
|
||||
", tracerObject=" + tracerObject +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String getTracerId() {
|
||||
public Long getTracerId() {
|
||||
return tracerId;
|
||||
}
|
||||
|
||||
public void setTracerId(String tracerId) {
|
||||
public void setTracerId(Long tracerId) {
|
||||
this.tracerId = tracerId;
|
||||
}
|
||||
|
||||
public int getCostTime() {
|
||||
public byte[] getRequestContent() {
|
||||
return requestContent;
|
||||
}
|
||||
|
||||
public void setRequestContent(byte[] requestContent) {
|
||||
this.requestContent = requestContent;
|
||||
}
|
||||
|
||||
public byte[] getResponseContent() {
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
public void setResponseContent(byte[] responseContent) {
|
||||
this.responseContent = responseContent;
|
||||
}
|
||||
|
||||
public Long getCostTime() {
|
||||
return costTime;
|
||||
}
|
||||
|
||||
public void setCostTime(int costTime) {
|
||||
public void setCostTime(Long costTime) {
|
||||
this.costTime = costTime;
|
||||
}
|
||||
|
||||
public long getCreateTime() {
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getErrno() {
|
||||
return errno;
|
||||
}
|
||||
|
||||
public void setErrno(String errno) {
|
||||
this.errno = errno;
|
||||
}
|
||||
|
||||
public String getErrmsg() {
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
public void setErrmsg(String errmsg) {
|
||||
this.errmsg = errmsg;
|
||||
}
|
||||
|
||||
public String getApp() {
|
||||
return app;
|
||||
}
|
||||
|
||||
public void setApp(String app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(long createTime) {
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getTracerObject() {
|
||||
return tracerObject;
|
||||
public Long getCreateTimeLong() {
|
||||
return createTimeLong;
|
||||
}
|
||||
|
||||
public void setTracerObject(List<Map<String, Object>> tracerObject) {
|
||||
this.tracerObject = tracerObject;
|
||||
public void setCreateTimeLong(Long createTimeLong) {
|
||||
this.createTimeLong = createTimeLong;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TracerModel{" +
|
||||
"tracerId=" + tracerId +
|
||||
", requestContent=" + Arrays.toString(requestContent) +
|
||||
", responseContent=" + Arrays.toString(responseContent) +
|
||||
", costTime=" + costTime +
|
||||
", uid='" + uid + '\'' +
|
||||
", errno='" + errno + '\'' +
|
||||
", errmsg='" + errmsg + '\'' +
|
||||
", app='" + app + '\'' +
|
||||
", uri='" + uri + '\'' +
|
||||
", createTime=" + createTime +
|
||||
", createTimeLong=" + createTimeLong +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.jd.platform.jlog.common.model;
|
||||
|
||||
import com.jd.platform.jlog.common.constant.LogTypeEnum;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.List;
|
||||
@ -11,11 +13,22 @@ import java.util.List;
|
||||
* @date 2021-08-17
|
||||
*/
|
||||
public class TracerData implements Serializable {
|
||||
|
||||
/**
|
||||
* type
|
||||
*/
|
||||
private LogTypeEnum type;
|
||||
|
||||
/**
|
||||
* 多个tracer批量打包后
|
||||
*/
|
||||
private List<TracerBean> tracerBeanList;
|
||||
|
||||
/**
|
||||
* span日志
|
||||
*/
|
||||
List<RunLogMessage> tempLogs;
|
||||
|
||||
//发送地址(仅多播时候使用)
|
||||
private transient InetSocketAddress address;
|
||||
|
||||
@ -31,10 +44,28 @@ public class TracerData implements Serializable {
|
||||
this.tracerBeanList = tracerBeanList;
|
||||
}
|
||||
|
||||
public LogTypeEnum getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(LogTypeEnum type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<RunLogMessage> getTempLogs() {
|
||||
return tempLogs;
|
||||
}
|
||||
|
||||
public void setTempLogs(List<RunLogMessage> tempLogs) {
|
||||
this.tempLogs = tempLogs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TracerData{" +
|
||||
"tracerBeanList=" + tracerBeanList +
|
||||
"type=" + type +
|
||||
", tracerBeanList=" + tracerBeanList +
|
||||
", tempLogs=" + tempLogs +
|
||||
", address=" + address +
|
||||
'}';
|
||||
}
|
||||
|
29
config/.gitignore
vendored
Normal file
29
config/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
config/config-apollo/.gitignore
vendored
Normal file
29
config/config-apollo/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
config/config-core/.gitignore
vendored
Normal file
29
config/config-core/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
config/config-etcd/.gitignore
vendored
Normal file
29
config/config-etcd/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
config/config-nacos/.gitignore
vendored
Normal file
29
config/config-nacos/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
config/config-zk/.gitignore
vendored
Normal file
29
config/config-zk/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
29
example/.gitignore
vendored
Normal file
29
example/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -41,7 +41,7 @@ public class TestController {
|
||||
@RequestMapping("/index")
|
||||
public Object index() {
|
||||
TracerBean tracerBean = new TracerBean();
|
||||
tracerBean.setTracerId("11111");
|
||||
tracerBean.setTracerId(11111L);
|
||||
|
||||
Configurator configurator = ConfiguratorFactory.getInstance();
|
||||
try{
|
||||
@ -70,6 +70,9 @@ public class TestController {
|
||||
if(newKey == 1){
|
||||
return 1;
|
||||
}
|
||||
if(uid!=null && 3==uid){
|
||||
throw new RuntimeException("发生异常了");
|
||||
}
|
||||
return new Response("滴滴员工tangbohu的终身代号是什么???是9527");
|
||||
}
|
||||
|
||||
|
29
worker/.gitignore
vendored
Normal file
29
worker/.gitignore
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
HELP.md
|
||||
/target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
@ -1,18 +1,17 @@
|
||||
package com.jd.platform.jlog.worker.disruptor;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.jd.platform.jlog.common.model.RunLogMessage;
|
||||
import com.jd.platform.jlog.common.constant.LogTypeEnum;
|
||||
import com.jd.platform.jlog.common.model.TracerBean;
|
||||
import com.jd.platform.jlog.common.model.RunLogMessage;
|
||||
import com.jd.platform.jlog.common.model.TracerData;
|
||||
import com.jd.platform.jlog.common.utils.FastJsonUtils;
|
||||
import com.jd.platform.jlog.common.utils.ProtostuffUtils;
|
||||
import com.jd.platform.jlog.common.utils.ZstdUtils;
|
||||
import com.jd.platform.jlog.worker.store.TracerLogToDbStore;
|
||||
import com.jd.platform.jlog.worker.store.TracerModelToDbStore;
|
||||
import com.lmax.disruptor.WorkHandler;
|
||||
import io.netty.util.internal.StringUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cglib.beans.BeanMap;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
@ -22,8 +21,6 @@ import java.util.*;
|
||||
import java.util.concurrent.atomic.LongAdder;
|
||||
|
||||
import static com.jd.platform.jlog.common.constant.Constant.DEFAULT_BYTE;
|
||||
import static com.jd.platform.jlog.common.constant.Constant.REQ;
|
||||
import static com.jd.platform.jlog.common.constant.Constant.RESP;
|
||||
|
||||
/**
|
||||
* TracerConsumer
|
||||
@ -69,9 +66,8 @@ public class TracerConsumer implements WorkHandler<OneTracer> {
|
||||
|
||||
TracerData tracerData = ProtostuffUtils.deserialize(decompressBytes, TracerData.class);
|
||||
|
||||
//包含了多个tracer对象
|
||||
List<TracerBean> tracerBeanList = tracerData.getTracerBeanList();
|
||||
buildTracerModel(tracerBeanList);
|
||||
//消费处理
|
||||
buildTracerModel(tracerData);
|
||||
|
||||
//处理完毕,将数量加1
|
||||
totalDealCount.increment();
|
||||
@ -84,30 +80,24 @@ public class TracerConsumer implements WorkHandler<OneTracer> {
|
||||
/**
|
||||
* 构建要入库的对象
|
||||
*/
|
||||
private void buildTracerModel(List<TracerBean> tracerBeanList) {
|
||||
//遍历传过来的
|
||||
for (TracerBean tracerBean : tracerBeanList) {
|
||||
//普通日志
|
||||
if ("-1".equals(tracerBean.getTracerId())) {
|
||||
dealTracerLog(tracerBean);
|
||||
} else {
|
||||
dealFilterModel(tracerBean);
|
||||
}
|
||||
|
||||
private void buildTracerModel(TracerData tracerData) {
|
||||
//普通日志
|
||||
if (LogTypeEnum.TRADE.equals(tracerData.getType())) {
|
||||
dealTracerLog(tracerData.getTempLogs());
|
||||
} else {
|
||||
dealFilterModel(tracerData.getTracerBeanList());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理中途日志
|
||||
*/
|
||||
private void dealTracerLog(TracerBean tracerBean) {
|
||||
List<Map<String, Object>> mapList = tracerBean.getTracerObject();
|
||||
Map<String, Object> objectMap = mapList.get(0);
|
||||
//遍历value集合,里面每个都是一个RunLogMessage对象
|
||||
for (Object object :objectMap.values()) {
|
||||
private void dealTracerLog(List<RunLogMessage> tempLogs) {
|
||||
if(tempLogs==null){
|
||||
return;
|
||||
}
|
||||
for (RunLogMessage runLogMessage :tempLogs) {
|
||||
Map<String, Object> map = new HashMap<>(12);
|
||||
|
||||
RunLogMessage runLogMessage = (RunLogMessage) object;
|
||||
map.put("tracerId", runLogMessage.getTracerId());
|
||||
map.put("className", runLogMessage.getClassName());
|
||||
map.put("threadName", runLogMessage.getThreadName());
|
||||
@ -118,41 +108,25 @@ public class TracerConsumer implements WorkHandler<OneTracer> {
|
||||
map.putAll(runLogMessage.getTagMap());
|
||||
tracerLogToDbStore.offer(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理filter里处理的出入参
|
||||
*/
|
||||
private void dealFilterModel(TracerBean tracerBean) {
|
||||
|
||||
List<Map<String, Object>> mapList = tracerBean.getTracerObject();
|
||||
Map<String, Object> requestMap = mapList.get(0);
|
||||
|
||||
Object req = requestMap.get(REQ);
|
||||
if(req == null){
|
||||
req = DEFAULT_BYTE;
|
||||
private void dealFilterModel(List<TracerBean> tracerList) {
|
||||
if(tracerList==null){
|
||||
return;
|
||||
}
|
||||
requestMap.remove(REQ);
|
||||
|
||||
Map<String, Object> map = new HashMap<>(requestMap);
|
||||
long tracerId = Long.parseLong(tracerBean.getTracerId());
|
||||
//filter的出入参
|
||||
Map<String, Object> responseMap = mapList.get(mapList.size() - 1);
|
||||
|
||||
Object resp = responseMap.get(RESP);
|
||||
if(resp == null){
|
||||
resp = DEFAULT_BYTE;
|
||||
for(TracerBean tracerModel:tracerList){
|
||||
if(tracerModel.getResponseContent()==null){
|
||||
tracerModel.setResponseContent(DEFAULT_BYTE);
|
||||
}
|
||||
tracerModel.setCreateTime(formatLongTime(tracerModel.getCreateTimeLong()));
|
||||
Map map = new HashMap(BeanMap.create(tracerModel));
|
||||
map.remove("createTimeLong");
|
||||
tracerModelToDbStore.offer(map);
|
||||
}
|
||||
|
||||
map.put("requestContent", req);
|
||||
map.put("responseContent", resp);
|
||||
map.put("costTime", tracerBean.getCostTime());
|
||||
map.put("tracerId", tracerId);
|
||||
map.put("createTime", formatLongTime(tracerBean.getCreateTime()));
|
||||
responseMap.remove("response");
|
||||
map.putAll(responseMap);
|
||||
tracerModelToDbStore.offer(map);
|
||||
}
|
||||
|
||||
private static String formatLongTime(long time) {
|
||||
|
Loading…
Reference in New Issue
Block a user