|
@@ -35,10 +35,10 @@ import com.alibaba.csp.sentinel.slots.block.BlockException; |
|
|
* When entering this slot, we need to separately count the following |
|
|
* When entering this slot, we need to separately count the following |
|
|
* information: |
|
|
* information: |
|
|
* <ul> |
|
|
* <ul> |
|
|
* <li>{@link ClusterNode}: total statistics of a cluster node of the resource id </li> |
|
|
|
|
|
* <li> origin node: statistics of a cluster node from different callers/origins.</li> |
|
|
|
|
|
* <li> {@link DefaultNode}: statistics for specific resource name in the specific context. |
|
|
|
|
|
* <li> Finally, the sum statistics of all entrances.</li> |
|
|
|
|
|
|
|
|
* <li>{@link ClusterNode}: total statistics of a cluster node of the resource ID.</li> |
|
|
|
|
|
* <li>Origin node: statistics of a cluster node from different callers/origins.</li> |
|
|
|
|
|
* <li>{@link DefaultNode}: statistics for specific resource name in the specific context.</li> |
|
|
|
|
|
* <li>Finally, the sum statistics of all entrances.</li> |
|
|
* </ul> |
|
|
* </ul> |
|
|
* </p> |
|
|
* </p> |
|
|
* |
|
|
* |
|
@@ -51,24 +51,31 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> { |
|
|
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, Object... args) |
|
|
public void entry(Context context, ResourceWrapper resourceWrapper, DefaultNode node, int count, Object... args) |
|
|
throws Throwable { |
|
|
throws Throwable { |
|
|
try { |
|
|
try { |
|
|
|
|
|
// Do some checking. |
|
|
fireEntry(context, resourceWrapper, node, count, args); |
|
|
fireEntry(context, resourceWrapper, node, count, args); |
|
|
|
|
|
|
|
|
|
|
|
// Request passed, add thread count and pass count. |
|
|
node.increaseThreadNum(); |
|
|
node.increaseThreadNum(); |
|
|
node.addPassRequest(); |
|
|
node.addPassRequest(); |
|
|
|
|
|
|
|
|
if (context.getCurEntry().getOriginNode() != null) { |
|
|
if (context.getCurEntry().getOriginNode() != null) { |
|
|
|
|
|
// Add count for origin node. |
|
|
context.getCurEntry().getOriginNode().increaseThreadNum(); |
|
|
context.getCurEntry().getOriginNode().increaseThreadNum(); |
|
|
context.getCurEntry().getOriginNode().addPassRequest(); |
|
|
context.getCurEntry().getOriginNode().addPassRequest(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (resourceWrapper.getType() == EntryType.IN) { |
|
|
if (resourceWrapper.getType() == EntryType.IN) { |
|
|
|
|
|
// Add count for global inbound entry node for global statistics. |
|
|
Constants.ENTRY_NODE.increaseThreadNum(); |
|
|
Constants.ENTRY_NODE.increaseThreadNum(); |
|
|
Constants.ENTRY_NODE.addPassRequest(); |
|
|
Constants.ENTRY_NODE.addPassRequest(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Handle pass event with registered entry callback handlers. |
|
|
for (ProcessorSlotEntryCallback<DefaultNode> handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) { |
|
|
for (ProcessorSlotEntryCallback<DefaultNode> handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) { |
|
|
handler.onPass(context, resourceWrapper, node, count, args); |
|
|
handler.onPass(context, resourceWrapper, node, count, args); |
|
|
} |
|
|
} |
|
|
} catch (BlockException e) { |
|
|
} catch (BlockException e) { |
|
|
|
|
|
// Blocked, set block exception to current entry. |
|
|
context.getCurEntry().setError(e); |
|
|
context.getCurEntry().setError(e); |
|
|
|
|
|
|
|
|
// Add block count. |
|
|
// Add block count. |
|
@@ -78,18 +85,21 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (resourceWrapper.getType() == EntryType.IN) { |
|
|
if (resourceWrapper.getType() == EntryType.IN) { |
|
|
|
|
|
// Add count for global inbound entry node for global statistics. |
|
|
Constants.ENTRY_NODE.increaseBlockQps(); |
|
|
Constants.ENTRY_NODE.increaseBlockQps(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Handle block event with registered entry callback handlers. |
|
|
for (ProcessorSlotEntryCallback<DefaultNode> handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) { |
|
|
for (ProcessorSlotEntryCallback<DefaultNode> handler : StatisticSlotCallbackRegistry.getEntryCallbacks()) { |
|
|
handler.onBlocked(e, context, resourceWrapper, node, count, args); |
|
|
handler.onBlocked(e, context, resourceWrapper, node, count, args); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
throw e; |
|
|
throw e; |
|
|
} catch (Throwable e) { |
|
|
} catch (Throwable e) { |
|
|
|
|
|
// Unexpected error, set error to current entry. |
|
|
context.getCurEntry().setError(e); |
|
|
context.getCurEntry().setError(e); |
|
|
|
|
|
|
|
|
// Should not happen |
|
|
|
|
|
|
|
|
// This should not happen. |
|
|
node.increaseExceptionQps(); |
|
|
node.increaseExceptionQps(); |
|
|
if (context.getCurEntry().getOriginNode() != null) { |
|
|
if (context.getCurEntry().getOriginNode() != null) { |
|
|
context.getCurEntry().getOriginNode().increaseExceptionQps(); |
|
|
context.getCurEntry().getOriginNode().increaseExceptionQps(); |
|
@@ -107,11 +117,13 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> { |
|
|
DefaultNode node = (DefaultNode)context.getCurNode(); |
|
|
DefaultNode node = (DefaultNode)context.getCurNode(); |
|
|
|
|
|
|
|
|
if (context.getCurEntry().getError() == null) { |
|
|
if (context.getCurEntry().getError() == null) { |
|
|
|
|
|
// Calculate response time (max RT is TIME_DROP_VALVE). |
|
|
long rt = TimeUtil.currentTimeMillis() - context.getCurEntry().getCreateTime(); |
|
|
long rt = TimeUtil.currentTimeMillis() - context.getCurEntry().getCreateTime(); |
|
|
if (rt > Constants.TIME_DROP_VALVE) { |
|
|
if (rt > Constants.TIME_DROP_VALVE) { |
|
|
rt = Constants.TIME_DROP_VALVE; |
|
|
rt = Constants.TIME_DROP_VALVE; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Record response time and success count. |
|
|
node.rt(rt); |
|
|
node.rt(rt); |
|
|
if (context.getCurEntry().getOriginNode() != null) { |
|
|
if (context.getCurEntry().getOriginNode() != null) { |
|
|
context.getCurEntry().getOriginNode().rt(rt); |
|
|
context.getCurEntry().getOriginNode().rt(rt); |
|
@@ -131,6 +143,7 @@ public class StatisticSlot extends AbstractLinkedProcessorSlot<DefaultNode> { |
|
|
// Error may happen. |
|
|
// Error may happen. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Handle exit event with registered exit callback handlers. |
|
|
Collection<ProcessorSlotExitCallback> exitCallbacks = StatisticSlotCallbackRegistry.getExitCallbacks(); |
|
|
Collection<ProcessorSlotExitCallback> exitCallbacks = StatisticSlotCallbackRegistry.getExitCallbacks(); |
|
|
for (ProcessorSlotExitCallback handler : exitCallbacks) { |
|
|
for (ProcessorSlotExitCallback handler : exitCallbacks) { |
|
|
handler.onExit(context, resourceWrapper, count, args); |
|
|
handler.onExit(context, resourceWrapper, count, args); |
|
|