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