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;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
if (methodEntry != null) {
|
if (methodEntry != null) {
|
||||||
methodEntry.exit();
|
methodEntry.exit(1, invocation.getArguments());
|
||||||
}
|
}
|
||||||
if (interfaceEntry != null) {
|
if (interfaceEntry != null) {
|
||||||
interfaceEntry.exit();
|
interfaceEntry.exit();
|
||||||
|
|
@ -108,32 +108,49 @@ public class SentinelDubboConsumerFilter extends BaseSentinelDubboFilter {
|
||||||
|
|
||||||
|
|
||||||
private Result asyncInvoke(Invoker<?> invoker, Invocation invocation) {
|
private Result asyncInvoke(Invoker<?> invoker, Invocation invocation) {
|
||||||
LinkedList<Entry> queue = new LinkedList<>();
|
LinkedList<EntryHolder> queue = new LinkedList<>();
|
||||||
String methodResourceName = getMethodName(invoker, invocation);
|
String methodResourceName = getMethodName(invoker, invocation);
|
||||||
String interfaceResourceName = getInterfaceName(invoker);
|
String interfaceResourceName = getInterfaceName(invoker);
|
||||||
try {
|
try {
|
||||||
queue.push(SphU.asyncEntry(interfaceResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT));
|
queue.push(new EntryHolder(SphU.asyncEntry(interfaceResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT), null));
|
||||||
queue.push(SphU.asyncEntry(methodResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT, 1, invocation.getArguments()));
|
queue.push(new EntryHolder(SphU.asyncEntry(methodResourceName, ResourceTypeConstants.COMMON_RPC, EntryType.OUT, 1, invocation.getArguments()), invocation.getArguments()));
|
||||||
Result result = invoker.invoke(invocation);
|
Result result = invoker.invoke(invocation);
|
||||||
result.whenCompleteWithContext(new BiConsumer<Result, Throwable>() {
|
result.whenCompleteWithContext(new BiConsumer<Result, Throwable>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(Result result, Throwable throwable) {
|
public void accept(Result result, Throwable throwable) {
|
||||||
while (!queue.isEmpty()) {
|
while (!queue.isEmpty()) {
|
||||||
Entry entry = queue.pop();
|
EntryHolder holder = queue.pop();
|
||||||
Tracer.traceEntry(result.getException(), entry);
|
Tracer.traceEntry(result.getException(), holder.entry);
|
||||||
entry.exit();
|
exitEntry(holder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
} catch (BlockException e) {
|
} catch (BlockException e) {
|
||||||
while (!queue.isEmpty()) {
|
while (!queue.isEmpty()) {
|
||||||
queue.pop().exit();
|
exitEntry(queue.pop());
|
||||||
}
|
}
|
||||||
return DubboFallbackRegistry.getConsumerFallback().handle(invoker, invocation, e);
|
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());
|
String resourceName = getResourceName(invoker, invocation, DubboConfig.getDubboConsumerPrefix());
|
||||||
interfaceEntry = SphU.entry(invoker.getInterface().getName(), ResourceTypeConstants.COMMON_RPC,
|
interfaceEntry = SphU.entry(invoker.getInterface().getName(), ResourceTypeConstants.COMMON_RPC,
|
||||||
EntryType.OUT);
|
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);
|
Result result = invoker.invoke(invocation);
|
||||||
if (result.hasException()) {
|
if (result.hasException()) {
|
||||||
|
|
@ -77,7 +77,7 @@ public class SentinelDubboConsumerFilter extends AbstractDubboFilter implements
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
if (methodEntry != null) {
|
if (methodEntry != null) {
|
||||||
methodEntry.exit();
|
methodEntry.exit(1, invocation.getArguments());
|
||||||
}
|
}
|
||||||
if (interfaceEntry != null) {
|
if (interfaceEntry != null) {
|
||||||
interfaceEntry.exit();
|
interfaceEntry.exit();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue