Improve consumer filter of Dubbo 2.6.x and 2.7.x adapter (#1532)
* entry and exit with params in consumer filter
This commit is contained in:
parent
a1e3715db1
commit
f1b63315c1
|
|
@ -98,7 +98,7 @@ public class SentinelDubboConsumerFilter extends BaseSentinelDubboFilter {
|
|||
throw e;
|
||||
} finally {
|
||||
if (methodEntry != null) {
|
||||
methodEntry.exit();
|
||||
methodEntry.exit(1, invocation.getArguments());
|
||||
}
|
||||
if (interfaceEntry != null) {
|
||||
interfaceEntry.exit();
|
||||
|
|
@ -108,32 +108,49 @@ public class SentinelDubboConsumerFilter extends BaseSentinelDubboFilter {
|
|||
|
||||
|
||||
private Result asyncInvoke(Invoker<?> invoker, Invocation invocation) {
|
||||
LinkedList<Entry> queue = new LinkedList<>();
|
||||
LinkedList<EntryHolder> queue = new LinkedList<>();
|
||||
String methodResourceName = getMethodName(invoker, invocation);
|
||||
String interfaceResourceName = getInterfaceName(invoker);
|
||||
try {
|
||||
queue.push(SphU.asyncEntry(interfaceResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT));
|
||||
queue.push(SphU.asyncEntry(methodResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT, 1, invocation.getArguments()));
|
||||
queue.push(new EntryHolder(SphU.asyncEntry(interfaceResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT), null));
|
||||
queue.push(new EntryHolder(SphU.asyncEntry(methodResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT, 1, invocation.getArguments()), invocation.getArguments()));
|
||||
Result result = invoker.invoke(invocation);
|
||||
result.whenCompleteWithContext(new BiConsumer<Result, Throwable>() {
|
||||
@Override
|
||||
public void accept(Result result, Throwable throwable) {
|
||||
while (!queue.isEmpty()) {
|
||||
Entry entry = queue.pop();
|
||||
Tracer.traceEntry(result.getException(), entry);
|
||||
entry.exit();
|
||||
EntryHolder holder = queue.pop();
|
||||
Tracer.traceEntry(result.getException(), holder.entry);
|
||||
exitEntry(holder);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
} catch (BlockException e) {
|
||||
while (!queue.isEmpty()) {
|
||||
queue.pop().exit();
|
||||
exitEntry(queue.pop());
|
||||
}
|
||||
return DubboFallbackRegistry.getConsumerFallback().handle(invoker, invocation, e);
|
||||
}
|
||||
}
|
||||
|
||||
class EntryHolder {
|
||||
|
||||
final private Entry entry;
|
||||
|
||||
final private Object[] params;
|
||||
|
||||
public EntryHolder(Entry entry, Object[] params) {
|
||||
this.entry = entry;
|
||||
this.params = params;
|
||||
}
|
||||
}
|
||||
|
||||
private void exitEntry(EntryHolder holder) {
|
||||
if (holder.params != null) {
|
||||
holder.entry.exit(1, holder.params);
|
||||
} else {
|
||||
holder.entry.exit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class SentinelDubboConsumerFilter extends AbstractDubboFilter implements
|
|||
String resourceName = getResourceName(invoker, invocation, DubboConfig.getDubboConsumerPrefix());
|
||||
interfaceEntry = SphU.entry(invoker.getInterface().getName(), ResourceTypeConstants.COMMON_RPC,
|
||||
EntryType.OUT);
|
||||
methodEntry = SphU.entry(resourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT);
|
||||
methodEntry = SphU.entry(resourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT, invocation.getArguments());
|
||||
|
||||
Result result = invoker.invoke(invocation);
|
||||
if (result.hasException()) {
|
||||
|
|
@ -77,7 +77,7 @@ public class SentinelDubboConsumerFilter extends AbstractDubboFilter implements
|
|||
throw e;
|
||||
} finally {
|
||||
if (methodEntry != null) {
|
||||
methodEntry.exit();
|
||||
methodEntry.exit(1, invocation.getArguments());
|
||||
}
|
||||
if (interfaceEntry != null) {
|
||||
interfaceEntry.exit();
|
||||
|
|
|
|||
Loading…
Reference in New Issue