Skip to content

Commit

Permalink
Remove incorrect API of Dubbo (#13076)
Browse files Browse the repository at this point in the history
  • Loading branch information
steverao authored Jan 21, 2025
1 parent ab09fce commit d0795ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,13 @@ public static DubboTelemetryBuilder builder(OpenTelemetry openTelemetry) {
this.clientInstrumenter = clientInstrumenter;
}

/**
* Returns a new Dubbo {@link Filter} that traces Dubbo RPC invocations.
*
* @deprecated Use {@link #newClientFilter} and {@link #newServerFilter} instead.
*/
@Deprecated
public Filter newFilter() {
return TracingFilter.newFilter(serverInstrumenter, clientInstrumenter);
}

/** Returns a new Dubbo client {@link Filter} that traces Dubbo RPC invocations. */
public Filter newClientFilter() {
return TracingFilter.newClientFilter(clientInstrumenter);
return new TracingFilter(clientInstrumenter, true);
}

/** Returns a new Dubbo server {@link Filter} that traces Dubbo RPC invocations. */
public Filter newServerFilter() {
return TracingFilter.newServerFilter(serverInstrumenter);
return new TracingFilter(serverInstrumenter, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,52 +18,13 @@

final class TracingFilter implements Filter {

private final InstrumenterSupplier instrumenterSupplier;
private final Instrumenter<DubboRequest, Result> instrumenter;

private TracingFilter(InstrumenterSupplier instrumenterSupplier) {
this.instrumenterSupplier = instrumenterSupplier;
}

static TracingFilter newClientFilter(Instrumenter<DubboRequest, Result> clientInstrumenter) {
return newFilter(clientInstrumenter, true);
}

static TracingFilter newServerFilter(Instrumenter<DubboRequest, Result> serverInstrumenter) {
return newFilter(serverInstrumenter, false);
}

private static TracingFilter newFilter(
Instrumenter<DubboRequest, Result> instrumenter, boolean isClientSide) {
return new TracingFilter(
new InstrumenterSupplier() {

@Override
public Instrumenter<DubboRequest, Result> get(RpcContext rpcContext) {
return instrumenter;
}
private final boolean isClientSide;

@Override
public boolean isClientSide(RpcContext rpcContext) {
return isClientSide;
}
});
}

static TracingFilter newFilter(
Instrumenter<DubboRequest, Result> serverInstrumenter,
Instrumenter<DubboRequest, Result> clientInstrumenter) {
return new TracingFilter(
new InstrumenterSupplier() {
@Override
public Instrumenter<DubboRequest, Result> get(RpcContext rpcContext) {
return rpcContext.isConsumerSide() ? clientInstrumenter : serverInstrumenter;
}

@Override
public boolean isClientSide(RpcContext rpcContext) {
return rpcContext.isConsumerSide();
}
});
TracingFilter(Instrumenter<DubboRequest, Result> instrumenter, boolean isClientSide) {
this.instrumenter = instrumenter;
this.isClientSide = isClientSide;
}

@Override
Expand All @@ -78,7 +39,6 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) {
return invoker.invoke(invocation);
}

Instrumenter<DubboRequest, Result> instrumenter = instrumenterSupplier.get(rpcContext);
Context parentContext = Context.current();
DubboRequest request = DubboRequest.create((RpcInvocation) invocation, rpcContext);

Expand All @@ -91,7 +51,7 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) {
boolean isSynchronous = true;
try (Scope ignored = context.makeCurrent()) {
result = invoker.invoke(invocation);
if (instrumenterSupplier.isClientSide(rpcContext)) {
if (isClientSide) {
CompletableFuture<Object> future = rpcContext.getCompletableFuture();
if (future != null) {
isSynchronous = false;
Expand All @@ -108,10 +68,4 @@ public Result invoke(Invoker<?> invoker, Invocation invocation) {
}
return result;
}

private interface InstrumenterSupplier {
Instrumenter<DubboRequest, Result> get(RpcContext rpcContext);

boolean isClientSide(RpcContext rpcContext);
}
}

0 comments on commit d0795ec

Please sign in to comment.