mirror of
https://gitee.com/huoyo/ko-time.git
synced 2025-12-06 16:58:26 +08:00
optimize exception handler
This commit is contained in:
parent
f2b0dc0234
commit
5031745c10
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>cn.langpy</groupId>
|
<groupId>cn.langpy</groupId>
|
||||||
<artifactId>ko-time</artifactId>
|
<artifactId>ko-time</artifactId>
|
||||||
<version>2.2.3</version>
|
<version>2.2.4</version>
|
||||||
<name>KoTime</name>
|
<name>KoTime</name>
|
||||||
<description>A springboot tool for tracking the paths of the methods,which can help you to find methods's performances easily.</description>
|
<description>A springboot tool for tracking the paths of the methods,which can help you to find methods's performances easily.</description>
|
||||||
<licenses>
|
<licenses>
|
||||||
|
|||||||
@ -6,18 +6,17 @@ public class KoSqlConstant {
|
|||||||
public final static String queryMethodLikeName = "SELECT id, name, class_name, method_name, route_name, method_type FROM ko_method_node WHERE name like ?";
|
public final static String queryMethodLikeName = "SELECT id, name, class_name, method_name, route_name, method_type FROM ko_method_node WHERE name like ?";
|
||||||
public final static String queryController = "SELECT id, name, class_name, method_name, route_name, method_type FROM ko_method_node WHERE method_type=?";
|
public final static String queryController = "SELECT id, name, class_name, method_name, route_name, method_type FROM ko_method_node WHERE method_type=?";
|
||||||
public final static String updateMethod = "UPDATE ko_method_node SET name=?, class_name=?, method_name=?, route_name=?, method_type=? WHERE id=?";
|
public final static String updateMethod = "UPDATE ko_method_node SET name=?, class_name=?, method_name=?, route_name=?, method_type=? WHERE id=?";
|
||||||
public final static String addException = "INSERT INTO ko_exception_node(id, name, class_name, message) VALUES (?, ?, ?, ?)";
|
public final static String addException = "INSERT INTO ko_exception_node(id, name, class_name) VALUES (?, ?, ?)";
|
||||||
public final static String queryExceptions = "SELECT id, name, class_name, message FROM ko_exception_node";
|
public final static String queryExceptions = "SELECT id, name, class_name FROM ko_exception_node";
|
||||||
public final static String queryException = "SELECT id, name, class_name, message FROM ko_exception_node WHERE id=?";
|
public final static String queryException = "SELECT id, name, class_name FROM ko_exception_node WHERE id=?";
|
||||||
public final static String addMethodRe = "INSERT INTO ko_method_relation(id, source_id, target_id, avg_run_time, max_run_time, min_run_time) VALUES (?, ?, ?, ?, ?, ?)";
|
public final static String addMethodRe = "INSERT INTO ko_method_relation(id, source_id, target_id, avg_run_time, max_run_time, min_run_time) VALUES (?, ?, ?, ?, ?, ?)";
|
||||||
public final static String queryMethodRe = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE id=?";
|
public final static String queryMethodRe = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE id=?";
|
||||||
public final static String queryMethodReBySource = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE source_id=?";
|
public final static String queryMethodReBySource = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE source_id=?";
|
||||||
public final static String queryMethodReByTarget = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE target_id=?";
|
public final static String queryMethodReByTarget = "SELECT id, source_id, target_id, avg_run_time, max_run_time, min_run_time FROM ko_method_relation WHERE target_id=?";
|
||||||
public final static String updateMethodRe = "UPDATE ko_method_relation SET source_id=?, target_id=?, avg_run_time=?, max_run_time=?, min_run_time=? WHERE id=?";
|
public final static String updateMethodRe = "UPDATE ko_method_relation SET source_id=?, target_id=?, avg_run_time=?, max_run_time=?, min_run_time=? WHERE id=?";
|
||||||
public final static String addExceptionRe = "INSERT INTO ko_exception_relation(id, source_id, target_id, location) VALUES (?, ?, ?, ?)";
|
public final static String addExceptionRe = "INSERT INTO ko_exception_relation(id, source_id, target_id, location,message) VALUES (?, ?, ?, ?, ?)";
|
||||||
public final static String queryExceptionRe = "SELECT id, source_id, target_id, location FROM ko_exception_relation WHERE id=?";
|
public final static String queryExceptionRe = "SELECT id, source_id, target_id, location, message FROM ko_exception_relation WHERE id=?";
|
||||||
public final static String queryExceptionReByTarget = "SELECT id, source_id, target_id, location FROM ko_exception_relation WHERE target_id=?";
|
public final static String queryExceptionReByTarget = "SELECT id, source_id, target_id, location, message FROM ko_exception_relation WHERE target_id=?";
|
||||||
public final static String updateExceptionRe = "UPDATE ko_exception_relation SET source_id=?, target_id=?, location=? WHERE id=?";
|
|
||||||
public final static String addParamsAna = "INSERT INTO ko_param_ana (source_id, params, avg_run_time, max_run_time, min_run_time) VALUES (?, ?, ?, ?, ?)";
|
public final static String addParamsAna = "INSERT INTO ko_param_ana (source_id, params, avg_run_time, max_run_time, min_run_time) VALUES (?, ?, ?, ?, ?)";
|
||||||
public final static String queryParamsAna = "SELECT source_id, params, avg_run_time, max_run_time, min_run_time FROM ko_param_ana WHERE source_id=? and params=?";
|
public final static String queryParamsAna = "SELECT source_id, params, avg_run_time, max_run_time, min_run_time FROM ko_param_ana WHERE source_id=? and params=?";
|
||||||
public final static String queryParamsAnaBySource = "SELECT source_id, params, avg_run_time, max_run_time, min_run_time FROM ko_param_ana WHERE source_id=?";
|
public final static String queryParamsAnaBySource = "SELECT source_id, params, avg_run_time, max_run_time, min_run_time FROM ko_param_ana WHERE source_id=?";
|
||||||
|
|||||||
@ -130,8 +130,7 @@ public class DataBase implements GraphService {
|
|||||||
Object[] params = new Object[]{
|
Object[] params = new Object[]{
|
||||||
exceptionNode.getId(),
|
exceptionNode.getId(),
|
||||||
exceptionNode.getName(),
|
exceptionNode.getName(),
|
||||||
exceptionNode.getClassName(),
|
exceptionNode.getClassName()
|
||||||
exceptionNode.getMessage()
|
|
||||||
};
|
};
|
||||||
DataBaseUtil.insert(getWriteConnection(), KoSqlConstant.addException, params);
|
DataBaseUtil.insert(getWriteConnection(), KoSqlConstant.addException, params);
|
||||||
}
|
}
|
||||||
@ -192,7 +191,8 @@ public class DataBase implements GraphService {
|
|||||||
sourceMethodNode.getId() + exceptionNode.getId(),
|
sourceMethodNode.getId() + exceptionNode.getId(),
|
||||||
sourceMethodNode.getId(),
|
sourceMethodNode.getId(),
|
||||||
exceptionNode.getId(),
|
exceptionNode.getId(),
|
||||||
exceptionNode.getValue()
|
exceptionNode.getValue(),
|
||||||
|
exceptionNode.getMessage()
|
||||||
};
|
};
|
||||||
DataBaseUtil.insert(getWriteConnection(), KoSqlConstant.addExceptionRe, params);
|
DataBaseUtil.insert(getWriteConnection(), KoSqlConstant.addExceptionRe, params);
|
||||||
}
|
}
|
||||||
@ -454,8 +454,8 @@ public class DataBase implements GraphService {
|
|||||||
}
|
}
|
||||||
MethodNode methodNode = methodNodes.get(0);
|
MethodNode methodNode = methodNodes.get(0);
|
||||||
|
|
||||||
List<ExceptionNode> exceptions = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryMethod, new Object[]{exceptionId}, ExceptionNode.class);
|
List<ExceptionNode> exceptions = DataBaseUtil.query(getReadConnection(), KoSqlConstant.queryException, new Object[]{exceptionId}, ExceptionNode.class);
|
||||||
if (methodNodes.size() == 0) {
|
if (exceptions.size() == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ExceptionNode exceptionNode = exceptions.get(0);
|
ExceptionNode exceptionNode = exceptions.get(0);
|
||||||
@ -464,7 +464,7 @@ public class DataBase implements GraphService {
|
|||||||
exceptionInfo.setName(exceptionNode.getName());
|
exceptionInfo.setName(exceptionNode.getName());
|
||||||
exceptionInfo.setClassName(exceptionNode.getClassName());
|
exceptionInfo.setClassName(exceptionNode.getClassName());
|
||||||
exceptionInfo.setLocation(relation.getLocation());
|
exceptionInfo.setLocation(relation.getLocation());
|
||||||
exceptionInfo.setMessage(exceptionNode.getMessage());
|
exceptionInfo.setMessage(relation.getMessage());
|
||||||
exceptionInfo.setMethodName(methodNode.getMethodName());
|
exceptionInfo.setMethodName(methodNode.getMethodName());
|
||||||
exceptionInfo.setOccurClassName(methodNode.getClassName());
|
exceptionInfo.setOccurClassName(methodNode.getClassName());
|
||||||
if (!exceptionInfos.contains(exceptionInfo)) {
|
if (!exceptionInfos.contains(exceptionInfo)) {
|
||||||
@ -489,7 +489,7 @@ public class DataBase implements GraphService {
|
|||||||
exceptionInfo.setId(exceptionNode.getId());
|
exceptionInfo.setId(exceptionNode.getId());
|
||||||
exceptionInfo.setName(exceptionNode.getName());
|
exceptionInfo.setName(exceptionNode.getName());
|
||||||
exceptionInfo.setClassName(exceptionNode.getClassName());
|
exceptionInfo.setClassName(exceptionNode.getClassName());
|
||||||
exceptionInfo.setMessage(exceptionNode.getMessage());
|
exceptionInfo.setMessage(relation.getMessage());
|
||||||
exceptionInfo.setLocation(relation.getLocation());
|
exceptionInfo.setLocation(relation.getLocation());
|
||||||
if (!exceptionInfos.contains(exceptionInfo)) {
|
if (!exceptionInfos.contains(exceptionInfo)) {
|
||||||
exceptionInfos.add(exceptionInfo);
|
exceptionInfos.add(exceptionInfo);
|
||||||
|
|||||||
@ -133,6 +133,7 @@ public class MemoryBase implements GraphService {
|
|||||||
exceptionRelation.setSourceId(sourceMethodNode.getId());
|
exceptionRelation.setSourceId(sourceMethodNode.getId());
|
||||||
exceptionRelation.setTargetId(exceptionNode.getId());
|
exceptionRelation.setTargetId(exceptionNode.getId());
|
||||||
exceptionRelation.setLocation(exceptionNode.getValue());
|
exceptionRelation.setLocation(exceptionNode.getValue());
|
||||||
|
exceptionRelation.setMessage(exceptionNode.getMessage());
|
||||||
ExceptionRelation old = exceptionRelations.get(exceptionRelation.getId());
|
ExceptionRelation old = exceptionRelations.get(exceptionRelation.getId());
|
||||||
if (null == old) {
|
if (null == old) {
|
||||||
exceptionRelations.put(exceptionRelation.getId(), exceptionRelation);
|
exceptionRelations.put(exceptionRelation.getId(), exceptionRelation);
|
||||||
@ -160,7 +161,7 @@ public class MemoryBase implements GraphService {
|
|||||||
exceptionInfo.setId(exceptionNode.getId());
|
exceptionInfo.setId(exceptionNode.getId());
|
||||||
exceptionInfo.setName(exceptionNode.getName());
|
exceptionInfo.setName(exceptionNode.getName());
|
||||||
exceptionInfo.setClassName(exceptionNode.getClassName());
|
exceptionInfo.setClassName(exceptionNode.getClassName());
|
||||||
exceptionInfo.setMessage(exceptionNode.getMessage());
|
exceptionInfo.setMessage(relation.getMessage());
|
||||||
exceptionInfo.setLocation(relation.getLocation());
|
exceptionInfo.setLocation(relation.getLocation());
|
||||||
if (!exceptionInfos.contains(exceptionInfo)) {
|
if (!exceptionInfos.contains(exceptionInfo)) {
|
||||||
exceptionInfos.add(exceptionInfo);
|
exceptionInfos.add(exceptionInfo);
|
||||||
@ -274,7 +275,7 @@ public class MemoryBase implements GraphService {
|
|||||||
exceptionInfo.setName(exceptionNode.getName());
|
exceptionInfo.setName(exceptionNode.getName());
|
||||||
exceptionInfo.setClassName(exceptionNode.getClassName());
|
exceptionInfo.setClassName(exceptionNode.getClassName());
|
||||||
exceptionInfo.setLocation(relation.getLocation());
|
exceptionInfo.setLocation(relation.getLocation());
|
||||||
exceptionInfo.setMessage(exceptionNode.getMessage());
|
exceptionInfo.setMessage(relation.getMessage());
|
||||||
exceptionInfo.setMethodName(methodNode.getMethodName());
|
exceptionInfo.setMethodName(methodNode.getMethodName());
|
||||||
exceptionInfo.setOccurClassName(methodNode.getClassName());
|
exceptionInfo.setOccurClassName(methodNode.getClassName());
|
||||||
if (!exceptionInfos.contains(exceptionInfo)) {
|
if (!exceptionInfos.contains(exceptionInfo)) {
|
||||||
|
|||||||
@ -139,6 +139,7 @@ public class RedisBase implements GraphService {
|
|||||||
exceptionRelation.setSourceId(sourceMethodNode.getId());
|
exceptionRelation.setSourceId(sourceMethodNode.getId());
|
||||||
exceptionRelation.setTargetId(exceptionNode.getId());
|
exceptionRelation.setTargetId(exceptionNode.getId());
|
||||||
exceptionRelation.setLocation(exceptionNode.getValue());
|
exceptionRelation.setLocation(exceptionNode.getValue());
|
||||||
|
exceptionRelation.setMessage(exceptionNode.getMessage());
|
||||||
String key = exceptionRelationPre + exceptionRelation.getId();
|
String key = exceptionRelationPre + exceptionRelation.getId();
|
||||||
ExceptionRelation old = query(key, ExceptionRelation.class);
|
ExceptionRelation old = query(key, ExceptionRelation.class);
|
||||||
if (null == old) {
|
if (null == old) {
|
||||||
@ -169,7 +170,7 @@ public class RedisBase implements GraphService {
|
|||||||
exceptionInfo.setId(exceptionNode.getId());
|
exceptionInfo.setId(exceptionNode.getId());
|
||||||
exceptionInfo.setName(exceptionNode.getName());
|
exceptionInfo.setName(exceptionNode.getName());
|
||||||
exceptionInfo.setClassName(exceptionNode.getClassName());
|
exceptionInfo.setClassName(exceptionNode.getClassName());
|
||||||
exceptionInfo.setMessage(exceptionNode.getMessage());
|
exceptionInfo.setMessage(relation.getMessage());
|
||||||
exceptionInfo.setLocation(relation.getLocation());
|
exceptionInfo.setLocation(relation.getLocation());
|
||||||
if (!exceptionInfos.contains(exceptionInfo)) {
|
if (!exceptionInfos.contains(exceptionInfo)) {
|
||||||
exceptionInfos.add(exceptionInfo);
|
exceptionInfos.add(exceptionInfo);
|
||||||
@ -302,7 +303,7 @@ public class RedisBase implements GraphService {
|
|||||||
exceptionInfo.setName(exceptionNode.getName());
|
exceptionInfo.setName(exceptionNode.getName());
|
||||||
exceptionInfo.setClassName(exceptionNode.getClassName());
|
exceptionInfo.setClassName(exceptionNode.getClassName());
|
||||||
exceptionInfo.setLocation(relation.getLocation());
|
exceptionInfo.setLocation(relation.getLocation());
|
||||||
exceptionInfo.setMessage(exceptionNode.getMessage());
|
exceptionInfo.setMessage(relation.getMessage());
|
||||||
exceptionInfo.setMethodName(methodNode.getMethodName());
|
exceptionInfo.setMethodName(methodNode.getMethodName());
|
||||||
exceptionInfo.setOccurClassName(methodNode.getClassName());
|
exceptionInfo.setOccurClassName(methodNode.getClassName());
|
||||||
if (!exceptionInfos.contains(exceptionInfo)) {
|
if (!exceptionInfos.contains(exceptionInfo)) {
|
||||||
|
|||||||
@ -43,7 +43,7 @@ public class RunTimeHandler implements MethodInterceptor {
|
|||||||
exception.setName(e.getClass().getSimpleName());
|
exception.setName(e.getClass().getSimpleName());
|
||||||
exception.setClassName(e.getClass().getName());
|
exception.setClassName(e.getClass().getName());
|
||||||
exception.setMessage(e.getMessage());
|
exception.setMessage(e.getMessage());
|
||||||
exception.setId(exception.getClassName() + exception.getName() + exception.getMessage());
|
exception.setId(exception.getClassName() + exception.getName());
|
||||||
MethodNode current = MethodNodeService.getCurrentMethodNode(invocation, 0.0);
|
MethodNode current = MethodNodeService.getCurrentMethodNode(invocation, 0.0);
|
||||||
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
|
||||||
if (stackTraceElement.getClassName().equals(current.getClassName())) {
|
if (stackTraceElement.getClassName().equals(current.getClassName())) {
|
||||||
|
|||||||
@ -6,6 +6,7 @@ public class ExceptionRelation {
|
|||||||
private String id;
|
private String id;
|
||||||
private String sourceId;
|
private String sourceId;
|
||||||
private String targetId;
|
private String targetId;
|
||||||
|
private String message;
|
||||||
private Integer location = 0;
|
private Integer location = 0;
|
||||||
|
|
||||||
public Integer getLocation() {
|
public Integer getLocation() {
|
||||||
@ -40,6 +41,14 @@ public class ExceptionRelation {
|
|||||||
this.targetId = targetId;
|
this.targetId = targetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|||||||
47
src/main/resources/sql/mysql-v2.2.3-.sql
Normal file
47
src/main/resources/sql/mysql-v2.2.3-.sql
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
-- v2.2.3及以下版本
|
||||||
|
create table ko_method_node
|
||||||
|
(
|
||||||
|
id varchar(400) not null primary key comment '主键',
|
||||||
|
name varchar(400) null comment '类名+方法名',
|
||||||
|
class_name varchar(400) null comment '类名',
|
||||||
|
method_name varchar(400) null comment '方法名',
|
||||||
|
route_name varchar(400) null comment '路由,controller才有',
|
||||||
|
method_type varchar(64) null comment '方法类型'
|
||||||
|
) comment '方法信息表';
|
||||||
|
|
||||||
|
|
||||||
|
create table ko_method_relation
|
||||||
|
(
|
||||||
|
id varchar(400) not null primary key comment '',
|
||||||
|
source_id varchar(400) null comment '调用方id',
|
||||||
|
target_id varchar(400) null comment '被调用方id',
|
||||||
|
avg_run_time numeric(10, 2) null comment '平均耗时',
|
||||||
|
max_run_time numeric(10, 2) null comment '最大耗时',
|
||||||
|
min_run_time numeric(10, 2) null comment '最小耗时'
|
||||||
|
) comment '方法调用关系表';
|
||||||
|
;
|
||||||
|
create table ko_exception_node
|
||||||
|
(
|
||||||
|
id varchar(400) not null primary key comment '主键',
|
||||||
|
name varchar(400) null comment '异常名',
|
||||||
|
class_name varchar(400) null comment '类名',
|
||||||
|
message varchar(400) null comment '异常消息'
|
||||||
|
) comment '异常表';
|
||||||
|
|
||||||
|
|
||||||
|
create table ko_exception_relation
|
||||||
|
(
|
||||||
|
id varchar(400) not null primary key comment '',
|
||||||
|
source_id varchar(400) null comment '调用方法id',
|
||||||
|
target_id varchar(400) null comment '异常id',
|
||||||
|
location int null comment '异常位置'
|
||||||
|
) comment '异常关系表';
|
||||||
|
|
||||||
|
create table ko_param_ana
|
||||||
|
(
|
||||||
|
source_id varchar(400) null comment '调用方法id',
|
||||||
|
params varchar(400) null comment '参数组合,-分隔',
|
||||||
|
avg_run_time numeric(10, 2) null comment '平均耗时',
|
||||||
|
max_run_time numeric(10, 2) null comment '最大耗时',
|
||||||
|
min_run_time numeric(10, 2) null comment '最小耗时'
|
||||||
|
) comment '参数分析表';
|
||||||
47
src/main/resources/sql/mysql-v2.2.4+.sql
Normal file
47
src/main/resources/sql/mysql-v2.2.4+.sql
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
-- v2.2.4及以上版本
|
||||||
|
create table ko_method_node
|
||||||
|
(
|
||||||
|
id varchar(400) not null primary key comment '主键',
|
||||||
|
name varchar(400) null comment '类名+方法名',
|
||||||
|
class_name varchar(400) null comment '类名',
|
||||||
|
method_name varchar(400) null comment '方法名',
|
||||||
|
route_name varchar(400) null comment '路由,controller才有',
|
||||||
|
method_type varchar(64) null comment '方法类型'
|
||||||
|
) comment '方法信息表';
|
||||||
|
|
||||||
|
|
||||||
|
create table ko_method_relation
|
||||||
|
(
|
||||||
|
id varchar(400) not null primary key comment '',
|
||||||
|
source_id varchar(400) null comment '调用方id',
|
||||||
|
target_id varchar(400) null comment '被调用方id',
|
||||||
|
avg_run_time numeric(10, 2) null comment '平均耗时',
|
||||||
|
max_run_time numeric(10, 2) null comment '最大耗时',
|
||||||
|
min_run_time numeric(10, 2) null comment '最小耗时'
|
||||||
|
) comment '方法调用关系表';
|
||||||
|
;
|
||||||
|
create table ko_exception_node
|
||||||
|
(
|
||||||
|
id varchar(400) not null primary key comment '主键',
|
||||||
|
name varchar(400) null comment '异常名',
|
||||||
|
class_name varchar(400) null comment '类名'
|
||||||
|
) comment '异常表';
|
||||||
|
|
||||||
|
|
||||||
|
create table ko_exception_relation
|
||||||
|
(
|
||||||
|
id varchar(400) not null primary key comment '',
|
||||||
|
source_id varchar(400) null comment '调用方法id',
|
||||||
|
target_id varchar(400) null comment '异常id',
|
||||||
|
location int null comment '异常位置',
|
||||||
|
message varchar(400) null comment '异常消息'
|
||||||
|
) comment '异常关系表';
|
||||||
|
|
||||||
|
create table ko_param_ana
|
||||||
|
(
|
||||||
|
source_id varchar(400) null comment '调用方法id',
|
||||||
|
params varchar(400) null comment '参数组合,-分隔',
|
||||||
|
avg_run_time numeric(10, 2) null comment '平均耗时',
|
||||||
|
max_run_time numeric(10, 2) null comment '最大耗时',
|
||||||
|
min_run_time numeric(10, 2) null comment '最小耗时'
|
||||||
|
) comment '参数分析表';
|
||||||
Loading…
x
Reference in New Issue
Block a user