Переглянути джерело

Fixes #453: Support tracing exception count for specific entry or context in Tracer

Signed-off-by: Eric Zhao <sczyh16@gmail.com>
master
Eric Zhao 5 роки тому
джерело
коміт
ba4fdcc638
1 змінених файлів з 68 додано та 3 видалено
  1. +68
    -3
      sentinel-core/src/main/java/com/alibaba/csp/sentinel/Tracer.java

+ 68
- 3
sentinel-core/src/main/java/com/alibaba/csp/sentinel/Tracer.java Переглянути файл

@@ -22,18 +22,30 @@ import com.alibaba.csp.sentinel.node.DefaultNode;
import com.alibaba.csp.sentinel.slots.block.BlockException;

/**
* This class is used to record other exception except block exception.
* This class is used to record other exceptions except block exception.
*
* @author jialiang.linjl
* @author Eric Zhao
*/
public final class Tracer {

/**
* Trace provided {@link Throwable} and increment exception count to entry in current context.
*
* @param e exception to record
*/
public static void trace(Throwable e) {
trace(e, 1);
}

/**
* Trace provided {@link Throwable} and add exception count to entry in current context.
*
* @param e exception to record
* @param count exception count to add
*/
public static void trace(Throwable e, int count) {
if (e instanceof BlockException) {
if (e == null || e instanceof BlockException) {
return;
}

@@ -43,6 +55,58 @@ public final class Tracer {
}

DefaultNode curNode = (DefaultNode)context.getCurNode();
traceExceptionToNode(e, count, curNode);
}

/**
* Trace provided {@link Throwable} and add exception count to current entry in provided context.
*
* @param e exception to record
* @param count exception count to add
* @since 1.4.2
*/
public static void traceContext(Throwable e, int count, Context context) {
if (e == null || e instanceof BlockException) {
return;
}
if (context == null) {
return;
}

DefaultNode curNode = (DefaultNode)context.getCurNode();
traceExceptionToNode(e, count, curNode);
}

/**
* Trace provided {@link Throwable} and increment exception count to provided entry.
*
* @param e exception to record
* @since 1.4.2
*/
public static void traceEntry(Throwable e, Entry entry) {
traceEntry(e, 1, entry);
}

/**
* Trace provided {@link Throwable} and add exception count to provided entry.
*
* @param e exception to record
* @param count exception count to add
* @since 1.4.2
*/
public static void traceEntry(Throwable e, int count, Entry entry) {
if (e == null || e instanceof BlockException) {
return;
}
if (entry == null || entry.getCurNode() == null) {
return;
}

DefaultNode curNode = (DefaultNode)entry.getCurNode();
traceExceptionToNode(e, count, curNode);
}

private static void traceExceptionToNode(Throwable t, int count, DefaultNode curNode) {
if (curNode == null) {
return;
}
@@ -52,7 +116,8 @@ public final class Tracer {
if (clusterNode == null) {
return;
}
clusterNode.trace(e, count);
clusterNode.trace(t, count);
}

private Tracer() {}
}

Завантаження…
Відмінити
Зберегти