convert module apache-dubbo-2.7 test case from groovy to java (#12008)
Co-authored-by: Jay DeLuca <jaydeluca4@gmail.com>
This commit is contained in:
parent
814c3ea9fa
commit
d9f7030107
|
@ -1,11 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.apachedubbo.v2_7
|
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
|
||||||
|
|
||||||
class DubboTest extends AbstractDubboTest implements AgentTestTrait {
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.apachedubbo.v2_7
|
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.AgentTestTrait
|
|
||||||
|
|
||||||
class DubboTraceChainTest extends AbstractDubboTraceChainTest implements AgentTestTrait {
|
|
||||||
}
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.apachedubbo.v2_7;
|
||||||
|
|
||||||
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.AbstractDubboTest;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
class DubboAgentTest extends AbstractDubboTest {
|
||||||
|
|
||||||
|
@RegisterExtension
|
||||||
|
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected InstrumentationExtension testing() {
|
||||||
|
return testing;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.javaagent.instrumentation.apachedubbo.v2_7;
|
||||||
|
|
||||||
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.AbstractDubboTraceChainTest;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
class DubboAgentTraceChainTest extends AbstractDubboTraceChainTest {
|
||||||
|
|
||||||
|
@RegisterExtension
|
||||||
|
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected InstrumentationExtension testing() {
|
||||||
|
return testing;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,11 +11,13 @@ enum DubboHeadersGetter implements TextMapGetter<DubboRequest> {
|
||||||
INSTANCE;
|
INSTANCE;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation") // deprecation for dubbo 3.2.15
|
||||||
public Iterable<String> keys(DubboRequest request) {
|
public Iterable<String> keys(DubboRequest request) {
|
||||||
return request.invocation().getAttachments().keySet();
|
return request.invocation().getAttachments().keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation") // deprecation for dubbo 3.2.15
|
||||||
public String get(DubboRequest request, String key) {
|
public String get(DubboRequest request, String key) {
|
||||||
return request.invocation().getAttachment(key);
|
return request.invocation().getAttachment(key);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ final class TracingFilter implements Filter {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@SuppressWarnings("deprecation") // deprecation for RpcContext.getContext()
|
||||||
public Result invoke(Invoker<?> invoker, Invocation invocation) {
|
public Result invoke(Invoker<?> invoker, Invocation invocation) {
|
||||||
if (!(invocation instanceof RpcInvocation)) {
|
if (!(invocation instanceof RpcInvocation)) {
|
||||||
return invoker.invoke(invocation);
|
return invoker.invoke(invocation);
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.apachedubbo.v2_7
|
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.LibraryTestTrait
|
|
||||||
|
|
||||||
class DubboTest extends AbstractDubboTest implements LibraryTestTrait {
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.apachedubbo.v2_7
|
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.test.LibraryTestTrait
|
|
||||||
|
|
||||||
class DubboTraceChainTest extends AbstractDubboTraceChainTest implements LibraryTestTrait {
|
|
||||||
}
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.apachedubbo.v2_7;
|
||||||
|
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
class DubboTest extends AbstractDubboTest {
|
||||||
|
|
||||||
|
@RegisterExtension
|
||||||
|
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected InstrumentationExtension testing() {
|
||||||
|
return testing;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.apachedubbo.v2_7;
|
||||||
|
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
class DubboTraceChainTest extends AbstractDubboTraceChainTest {
|
||||||
|
|
||||||
|
@RegisterExtension
|
||||||
|
static final InstrumentationExtension testing = LibraryInstrumentationExtension.create();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected InstrumentationExtension testing() {
|
||||||
|
return testing;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,211 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.apachedubbo.v2_7
|
|
||||||
|
|
||||||
import io.opentelemetry.api.trace.SpanKind
|
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService
|
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.HelloServiceImpl
|
|
||||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
|
||||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
|
||||||
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes
|
|
||||||
import io.opentelemetry.semconv.ServerAttributes
|
|
||||||
import io.opentelemetry.semconv.NetworkAttributes
|
|
||||||
import org.apache.dubbo.common.utils.NetUtils
|
|
||||||
import org.apache.dubbo.config.ApplicationConfig
|
|
||||||
import org.apache.dubbo.config.ProtocolConfig
|
|
||||||
import org.apache.dubbo.config.ReferenceConfig
|
|
||||||
import org.apache.dubbo.config.RegistryConfig
|
|
||||||
import org.apache.dubbo.config.ServiceConfig
|
|
||||||
import org.apache.dubbo.config.bootstrap.DubboBootstrap
|
|
||||||
import org.apache.dubbo.rpc.service.GenericService
|
|
||||||
import spock.lang.Shared
|
|
||||||
import spock.lang.Unroll
|
|
||||||
|
|
||||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT
|
|
||||||
import static io.opentelemetry.api.trace.SpanKind.SERVER
|
|
||||||
import static io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboTestUtil.newDubboBootstrap
|
|
||||||
import static io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboTestUtil.newFrameworkModel
|
|
||||||
|
|
||||||
@Unroll
|
|
||||||
abstract class AbstractDubboTest extends InstrumentationSpecification {
|
|
||||||
|
|
||||||
@Shared
|
|
||||||
def protocolConfig = new ProtocolConfig()
|
|
||||||
|
|
||||||
def setupSpec() {
|
|
||||||
NetUtils.LOCAL_ADDRESS = InetAddress.getLoopbackAddress()
|
|
||||||
}
|
|
||||||
|
|
||||||
ReferenceConfig<HelloService> configureClient(int port) {
|
|
||||||
ReferenceConfig<HelloService> reference = new ReferenceConfig<>()
|
|
||||||
reference.setInterface(HelloService)
|
|
||||||
reference.setGeneric("true")
|
|
||||||
reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000")
|
|
||||||
return reference
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceConfig configureServer() {
|
|
||||||
def registerConfig = new RegistryConfig()
|
|
||||||
registerConfig.setAddress("N/A")
|
|
||||||
ServiceConfig<HelloServiceImpl> service = new ServiceConfig<>()
|
|
||||||
service.setInterface(HelloService)
|
|
||||||
service.setRef(new HelloServiceImpl())
|
|
||||||
service.setRegistry(registerConfig)
|
|
||||||
return service
|
|
||||||
}
|
|
||||||
|
|
||||||
def "test apache dubbo base #dubbo"() {
|
|
||||||
setup:
|
|
||||||
def port = PortUtils.findOpenPort()
|
|
||||||
protocolConfig.setPort(port)
|
|
||||||
|
|
||||||
def frameworkModel = newFrameworkModel()
|
|
||||||
DubboBootstrap bootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
bootstrap.application(new ApplicationConfig("dubbo-test-provider"))
|
|
||||||
.service(configureServer())
|
|
||||||
.protocol(protocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
def consumerProtocolConfig = new ProtocolConfig()
|
|
||||||
consumerProtocolConfig.setRegister(false)
|
|
||||||
|
|
||||||
def reference = configureClient(port)
|
|
||||||
DubboBootstrap consumerBootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
consumerBootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer"))
|
|
||||||
.reference(reference)
|
|
||||||
.protocol(consumerProtocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
when:
|
|
||||||
GenericService genericService = reference.get()
|
|
||||||
def o = new Object[1]
|
|
||||||
o[0] = "hello"
|
|
||||||
def response = runWithSpan("parent") {
|
|
||||||
genericService.$invoke("hello", [String.getName()] as String[], o)
|
|
||||||
}
|
|
||||||
|
|
||||||
then:
|
|
||||||
response == "hello"
|
|
||||||
assertTraces(1) {
|
|
||||||
trace(0, 3) {
|
|
||||||
span(0) {
|
|
||||||
name "parent"
|
|
||||||
kind SpanKind.INTERNAL
|
|
||||||
hasNoParent()
|
|
||||||
}
|
|
||||||
span(1) {
|
|
||||||
name "org.apache.dubbo.rpc.service.GenericService/\$invoke"
|
|
||||||
kind CLIENT
|
|
||||||
childOf span(0)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "\$invoke"
|
|
||||||
"$ServerAttributes.SERVER_ADDRESS" "localhost"
|
|
||||||
"$ServerAttributes.SERVER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String}
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long}
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
span(2) {
|
|
||||||
name "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello"
|
|
||||||
kind SERVER
|
|
||||||
childOf span(1)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "hello"
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
bootstrap.destroy()
|
|
||||||
consumerBootstrap.destroy()
|
|
||||||
frameworkModel?.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
def "test apache dubbo test #dubbo"() {
|
|
||||||
setup:
|
|
||||||
def port = PortUtils.findOpenPort()
|
|
||||||
protocolConfig.setPort(port)
|
|
||||||
|
|
||||||
def frameworkModel = newFrameworkModel()
|
|
||||||
DubboBootstrap bootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
bootstrap.application(new ApplicationConfig("dubbo-test-async-provider"))
|
|
||||||
.service(configureServer())
|
|
||||||
.protocol(protocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
def consumerProtocolConfig = new ProtocolConfig()
|
|
||||||
consumerProtocolConfig.setRegister(false)
|
|
||||||
|
|
||||||
def reference = configureClient(port)
|
|
||||||
DubboBootstrap consumerBootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
consumerBootstrap.application(new ApplicationConfig("dubbo-demo-async-api-consumer"))
|
|
||||||
.reference(reference)
|
|
||||||
.protocol(consumerProtocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
when:
|
|
||||||
GenericService genericService = reference.get()
|
|
||||||
def o = new Object[1]
|
|
||||||
o[0] = "hello"
|
|
||||||
def responseAsync = runWithSpan("parent") {
|
|
||||||
genericService.$invokeAsync("hello", [String.getName()] as String[], o)
|
|
||||||
}
|
|
||||||
|
|
||||||
then:
|
|
||||||
responseAsync.get() == "hello"
|
|
||||||
assertTraces(1) {
|
|
||||||
trace(0, 3) {
|
|
||||||
span(0) {
|
|
||||||
name "parent"
|
|
||||||
kind SpanKind.INTERNAL
|
|
||||||
hasNoParent()
|
|
||||||
}
|
|
||||||
span(1) {
|
|
||||||
name "org.apache.dubbo.rpc.service.GenericService/\$invokeAsync"
|
|
||||||
kind CLIENT
|
|
||||||
childOf span(0)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "\$invokeAsync"
|
|
||||||
"$ServerAttributes.SERVER_ADDRESS" "localhost"
|
|
||||||
"$ServerAttributes.SERVER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String}
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long}
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
span(2) {
|
|
||||||
name "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello"
|
|
||||||
kind SERVER
|
|
||||||
childOf span(1)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "hello"
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
bootstrap.destroy()
|
|
||||||
consumerBootstrap.destroy()
|
|
||||||
frameworkModel?.destroy()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,287 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.apachedubbo.v2_7
|
|
||||||
|
|
||||||
import io.opentelemetry.api.trace.SpanKind
|
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService
|
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService
|
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.HelloServiceImpl
|
|
||||||
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.MiddleServiceImpl
|
|
||||||
import io.opentelemetry.instrumentation.test.InstrumentationSpecification
|
|
||||||
import io.opentelemetry.instrumentation.test.utils.PortUtils
|
|
||||||
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes
|
|
||||||
import io.opentelemetry.semconv.ServerAttributes
|
|
||||||
import io.opentelemetry.semconv.NetworkAttributes
|
|
||||||
import org.apache.dubbo.common.utils.NetUtils
|
|
||||||
import org.apache.dubbo.config.ApplicationConfig
|
|
||||||
import org.apache.dubbo.config.ProtocolConfig
|
|
||||||
import org.apache.dubbo.config.ReferenceConfig
|
|
||||||
import org.apache.dubbo.config.RegistryConfig
|
|
||||||
import org.apache.dubbo.config.ServiceConfig
|
|
||||||
import org.apache.dubbo.config.bootstrap.DubboBootstrap
|
|
||||||
import org.apache.dubbo.rpc.service.GenericService
|
|
||||||
import spock.lang.Unroll
|
|
||||||
|
|
||||||
import static io.opentelemetry.api.trace.SpanKind.CLIENT
|
|
||||||
import static io.opentelemetry.api.trace.SpanKind.SERVER
|
|
||||||
import static io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboTestUtil.newDubboBootstrap
|
|
||||||
import static io.opentelemetry.instrumentation.apachedubbo.v2_7.DubboTestUtil.newFrameworkModel
|
|
||||||
|
|
||||||
@Unroll
|
|
||||||
abstract class AbstractDubboTraceChainTest extends InstrumentationSpecification {
|
|
||||||
|
|
||||||
def setupSpec() {
|
|
||||||
NetUtils.LOCAL_ADDRESS = InetAddress.getLoopbackAddress()
|
|
||||||
}
|
|
||||||
|
|
||||||
ReferenceConfig<HelloService> configureClient(int port) {
|
|
||||||
ReferenceConfig<HelloService> reference = new ReferenceConfig<>()
|
|
||||||
reference.setInterface(HelloService)
|
|
||||||
reference.setGeneric("true")
|
|
||||||
reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000")
|
|
||||||
return reference
|
|
||||||
}
|
|
||||||
|
|
||||||
ReferenceConfig<HelloService> configureLocalClient(int port) {
|
|
||||||
ReferenceConfig<HelloService> reference = new ReferenceConfig<>()
|
|
||||||
reference.setInterface(HelloService)
|
|
||||||
reference.setGeneric("true")
|
|
||||||
reference.setUrl("injvm://localhost:" + port + "/?timeout=30000")
|
|
||||||
return reference
|
|
||||||
}
|
|
||||||
|
|
||||||
ReferenceConfig<HelloService> configureMiddleClient(int port) {
|
|
||||||
ReferenceConfig<MiddleService> reference = new ReferenceConfig<>()
|
|
||||||
reference.setInterface(MiddleService)
|
|
||||||
reference.setGeneric("true")
|
|
||||||
reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000")
|
|
||||||
return reference
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceConfig configureServer() {
|
|
||||||
def registerConfig = new RegistryConfig()
|
|
||||||
registerConfig.setAddress("N/A")
|
|
||||||
ServiceConfig<HelloServiceImpl> service = new ServiceConfig<>()
|
|
||||||
service.setInterface(HelloService)
|
|
||||||
service.setRef(new HelloServiceImpl())
|
|
||||||
service.setRegistry(registerConfig)
|
|
||||||
return service
|
|
||||||
}
|
|
||||||
|
|
||||||
ServiceConfig configureMiddleServer(ReferenceConfig<HelloService> referenceConfig) {
|
|
||||||
def registerConfig = new RegistryConfig()
|
|
||||||
registerConfig.setAddress("N/A")
|
|
||||||
ServiceConfig<MiddleServiceImpl> service = new ServiceConfig<>()
|
|
||||||
service.setInterface(MiddleService)
|
|
||||||
service.setRef(new MiddleServiceImpl(referenceConfig))
|
|
||||||
service.setRegistry(registerConfig)
|
|
||||||
return service
|
|
||||||
}
|
|
||||||
|
|
||||||
def "test that context is propagated correctly in chained dubbo calls"() {
|
|
||||||
setup:
|
|
||||||
def port = PortUtils.findOpenPorts(2)
|
|
||||||
def middlePort = port + 1
|
|
||||||
def protocolConfig = new ProtocolConfig()
|
|
||||||
protocolConfig.setPort(port)
|
|
||||||
|
|
||||||
def frameworkModel = newFrameworkModel()
|
|
||||||
DubboBootstrap bootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
bootstrap.application(new ApplicationConfig("dubbo-test-provider"))
|
|
||||||
.service(configureServer())
|
|
||||||
.protocol(protocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
def middleProtocolConfig = new ProtocolConfig()
|
|
||||||
middleProtocolConfig.setPort(middlePort)
|
|
||||||
|
|
||||||
def reference = configureClient(port)
|
|
||||||
DubboBootstrap middleBootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
middleBootstrap.application(new ApplicationConfig("dubbo-demo-middle"))
|
|
||||||
.reference(reference)
|
|
||||||
.service(configureMiddleServer(reference))
|
|
||||||
.protocol(middleProtocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
|
|
||||||
def consumerProtocolConfig = new ProtocolConfig()
|
|
||||||
consumerProtocolConfig.setRegister(false)
|
|
||||||
|
|
||||||
def middleReference = configureMiddleClient(middlePort)
|
|
||||||
DubboBootstrap consumerBootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
consumerBootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer"))
|
|
||||||
.reference(middleReference)
|
|
||||||
.protocol(consumerProtocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
when:
|
|
||||||
GenericService genericService = middleReference.get()
|
|
||||||
def response = runWithSpan("parent") {
|
|
||||||
genericService.$invoke("hello", [String.getName()] as String[], ["hello"] as Object[])
|
|
||||||
}
|
|
||||||
|
|
||||||
then:
|
|
||||||
response == "hello"
|
|
||||||
assertTraces(1) {
|
|
||||||
trace(0, 5) {
|
|
||||||
span(0) {
|
|
||||||
name "parent"
|
|
||||||
kind SpanKind.INTERNAL
|
|
||||||
hasNoParent()
|
|
||||||
}
|
|
||||||
span(1) {
|
|
||||||
name "org.apache.dubbo.rpc.service.GenericService/\$invoke"
|
|
||||||
kind CLIENT
|
|
||||||
childOf span(0)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "\$invoke"
|
|
||||||
"$ServerAttributes.SERVER_ADDRESS" "localhost"
|
|
||||||
"$ServerAttributes.SERVER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String}
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long}
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
span(2) {
|
|
||||||
name "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService/hello"
|
|
||||||
kind SERVER
|
|
||||||
childOf span(1)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "hello"
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
span(3) {
|
|
||||||
name "org.apache.dubbo.rpc.service.GenericService/\$invoke"
|
|
||||||
kind CLIENT
|
|
||||||
childOf span(2)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "\$invoke"
|
|
||||||
"$ServerAttributes.SERVER_ADDRESS" "localhost"
|
|
||||||
"$ServerAttributes.SERVER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String }
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long }
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
span(4) {
|
|
||||||
name "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello"
|
|
||||||
kind SERVER
|
|
||||||
childOf span(3)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "hello"
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
bootstrap.destroy()
|
|
||||||
middleBootstrap.destroy()
|
|
||||||
consumerBootstrap.destroy()
|
|
||||||
}
|
|
||||||
|
|
||||||
def "test ignore injvm calls"() {
|
|
||||||
setup:
|
|
||||||
def port = PortUtils.findOpenPorts(2)
|
|
||||||
def middlePort = port + 1
|
|
||||||
def protocolConfig = new ProtocolConfig()
|
|
||||||
protocolConfig.setPort(port)
|
|
||||||
|
|
||||||
def frameworkModel = newFrameworkModel()
|
|
||||||
DubboBootstrap bootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
bootstrap.application(new ApplicationConfig("dubbo-test-provider"))
|
|
||||||
.service(configureServer())
|
|
||||||
.protocol(protocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
def middleProtocolConfig = new ProtocolConfig()
|
|
||||||
middleProtocolConfig.setPort(middlePort)
|
|
||||||
|
|
||||||
def reference = configureLocalClient(port)
|
|
||||||
DubboBootstrap middleBootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
middleBootstrap.application(new ApplicationConfig("dubbo-demo-middle"))
|
|
||||||
.reference(reference)
|
|
||||||
.service(configureMiddleServer(reference))
|
|
||||||
.protocol(middleProtocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
|
|
||||||
def consumerProtocolConfig = new ProtocolConfig()
|
|
||||||
consumerProtocolConfig.setRegister(false)
|
|
||||||
|
|
||||||
def middleReference = configureMiddleClient(middlePort)
|
|
||||||
DubboBootstrap consumerBootstrap = newDubboBootstrap(frameworkModel)
|
|
||||||
consumerBootstrap.application(new ApplicationConfig("dubbo-demo-api-consumer"))
|
|
||||||
.reference(middleReference)
|
|
||||||
.protocol(consumerProtocolConfig)
|
|
||||||
.start()
|
|
||||||
|
|
||||||
when:
|
|
||||||
GenericService genericService = middleReference.get()
|
|
||||||
def response = runWithSpan("parent") {
|
|
||||||
genericService.$invoke("hello", [String.getName()] as String[], ["hello"] as Object[])
|
|
||||||
}
|
|
||||||
|
|
||||||
then:
|
|
||||||
response == "hello"
|
|
||||||
assertTraces(1) {
|
|
||||||
trace(0, 3) {
|
|
||||||
span(0) {
|
|
||||||
name "parent"
|
|
||||||
kind SpanKind.INTERNAL
|
|
||||||
hasNoParent()
|
|
||||||
}
|
|
||||||
span(1) {
|
|
||||||
name "org.apache.dubbo.rpc.service.GenericService/\$invoke"
|
|
||||||
kind CLIENT
|
|
||||||
childOf span(0)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "org.apache.dubbo.rpc.service.GenericService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "\$invoke"
|
|
||||||
"$ServerAttributes.SERVER_ADDRESS" "localhost"
|
|
||||||
"$ServerAttributes.SERVER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" { it == null || it instanceof String}
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" { it == null || it instanceof Long}
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
span(2) {
|
|
||||||
name "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService/hello"
|
|
||||||
kind SERVER
|
|
||||||
childOf span(1)
|
|
||||||
attributes {
|
|
||||||
"$RpcIncubatingAttributes.RPC_SYSTEM" "apache_dubbo"
|
|
||||||
"$RpcIncubatingAttributes.RPC_SERVICE" "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"
|
|
||||||
"$RpcIncubatingAttributes.RPC_METHOD" "hello"
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_ADDRESS" String
|
|
||||||
"$NetworkAttributes.NETWORK_PEER_PORT" Long
|
|
||||||
"$NetworkAttributes.NETWORK_TYPE" { it == "ipv4" || it == "ipv6" || it == null }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
bootstrap.destroy()
|
|
||||||
middleBootstrap.destroy()
|
|
||||||
consumerBootstrap.destroy()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright The OpenTelemetry Authors
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
package io.opentelemetry.instrumentation.apachedubbo.v2_7
|
|
||||||
|
|
||||||
import org.apache.dubbo.config.bootstrap.DubboBootstrap
|
|
||||||
|
|
||||||
class DubboTestUtil {
|
|
||||||
static newFrameworkModel() {
|
|
||||||
try {
|
|
||||||
// only present in latest dep
|
|
||||||
return Class.forName("org.apache.dubbo.rpc.model.FrameworkModel").newInstance()
|
|
||||||
} catch (ClassNotFoundException exception) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static DubboBootstrap newDubboBootstrap(Object frameworkModel) {
|
|
||||||
if (frameworkModel == null) {
|
|
||||||
return DubboBootstrap.newInstance()
|
|
||||||
}
|
|
||||||
return DubboBootstrap.newInstance(frameworkModel)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,287 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.apachedubbo.v2_7;
|
||||||
|
|
||||||
|
import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan;
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService;
|
||||||
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.HelloServiceImpl;
|
||||||
|
import io.opentelemetry.instrumentation.test.utils.PortUtils;
|
||||||
|
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import io.opentelemetry.semconv.NetworkAttributes;
|
||||||
|
import io.opentelemetry.semconv.ServerAttributes;
|
||||||
|
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import org.apache.dubbo.common.utils.NetUtils;
|
||||||
|
import org.apache.dubbo.config.ApplicationConfig;
|
||||||
|
import org.apache.dubbo.config.ProtocolConfig;
|
||||||
|
import org.apache.dubbo.config.ReferenceConfig;
|
||||||
|
import org.apache.dubbo.config.RegistryConfig;
|
||||||
|
import org.apache.dubbo.config.ServiceConfig;
|
||||||
|
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
||||||
|
import org.apache.dubbo.rpc.service.GenericService;
|
||||||
|
import org.assertj.core.api.AbstractAssert;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
public abstract class AbstractDubboTest {
|
||||||
|
|
||||||
|
private final ProtocolConfig protocolConfig = new ProtocolConfig();
|
||||||
|
|
||||||
|
protected abstract InstrumentationExtension testing();
|
||||||
|
|
||||||
|
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void setUp() throws Exception {
|
||||||
|
System.setProperty("dubbo.application.qos-enable", "false");
|
||||||
|
Field field = NetUtils.class.getDeclaredField("LOCAL_ADDRESS");
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(null, InetAddress.getLoopbackAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void tearDown() {
|
||||||
|
System.clearProperty("dubbo.application.qos-enable");
|
||||||
|
}
|
||||||
|
|
||||||
|
ReferenceConfig<HelloService> configureClient(int port) {
|
||||||
|
ReferenceConfig<HelloService> reference = new ReferenceConfig<>();
|
||||||
|
reference.setInterface(HelloService.class);
|
||||||
|
reference.setGeneric("true");
|
||||||
|
reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000");
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceConfig<HelloServiceImpl> configureServer() {
|
||||||
|
RegistryConfig registerConfig = new RegistryConfig();
|
||||||
|
registerConfig.setAddress("N/A");
|
||||||
|
ServiceConfig<HelloServiceImpl> service = new ServiceConfig<>();
|
||||||
|
service.setInterface(HelloService.class);
|
||||||
|
service.setRef(new HelloServiceImpl());
|
||||||
|
service.setRegistry(registerConfig);
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
ReferenceConfig<GenericService> convertReference(ReferenceConfig<HelloService> config) {
|
||||||
|
return (ReferenceConfig) config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testApacheDubboBase() throws ReflectiveOperationException {
|
||||||
|
int port = PortUtils.findOpenPort();
|
||||||
|
protocolConfig.setPort(port);
|
||||||
|
// provider boostrap
|
||||||
|
DubboBootstrap bootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(bootstrap::destroy);
|
||||||
|
bootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-test-provider"))
|
||||||
|
.service(configureServer())
|
||||||
|
.protocol(protocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// consumer boostrap
|
||||||
|
DubboBootstrap consumerBootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(consumerBootstrap::destroy);
|
||||||
|
ReferenceConfig<HelloService> referenceConfig = configureClient(port);
|
||||||
|
ProtocolConfig consumerProtocolConfig = new ProtocolConfig();
|
||||||
|
consumerProtocolConfig.setRegister(false);
|
||||||
|
consumerBootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-demo-api-consumer"))
|
||||||
|
.reference(referenceConfig)
|
||||||
|
.protocol(consumerProtocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// generic call
|
||||||
|
ReferenceConfig<GenericService> reference = convertReference(referenceConfig);
|
||||||
|
GenericService genericService = reference.get();
|
||||||
|
|
||||||
|
Object response =
|
||||||
|
runWithSpan(
|
||||||
|
"parent",
|
||||||
|
() ->
|
||||||
|
genericService.$invoke(
|
||||||
|
"hello", new String[] {String.class.getName()}, new Object[] {"hello"}));
|
||||||
|
|
||||||
|
assertThat(response).isEqualTo("hello");
|
||||||
|
testing()
|
||||||
|
.waitAndAssertTraces(
|
||||||
|
trace ->
|
||||||
|
trace.hasSpansSatisfyingExactly(
|
||||||
|
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
|
||||||
|
span ->
|
||||||
|
span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke")
|
||||||
|
.hasKind(SpanKind.CLIENT)
|
||||||
|
.hasParent(trace.getSpan(0))
|
||||||
|
.hasAttributesSatisfyingExactly(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"org.apache.dubbo.rpc.service.GenericService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
|
||||||
|
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
|
||||||
|
satisfies(
|
||||||
|
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(String.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(Long.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6")))),
|
||||||
|
span ->
|
||||||
|
span.hasName(
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello")
|
||||||
|
.hasKind(SpanKind.SERVER)
|
||||||
|
.hasParent(trace.getSpan(1))
|
||||||
|
.hasAttributesSatisfying(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k -> k.isInstanceOf(String.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE, AbstractAssert::isNull))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testApacheDubboTest()
|
||||||
|
throws ExecutionException, InterruptedException, ReflectiveOperationException {
|
||||||
|
int port = PortUtils.findOpenPort();
|
||||||
|
protocolConfig.setPort(port);
|
||||||
|
|
||||||
|
DubboBootstrap bootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(bootstrap::destroy);
|
||||||
|
bootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-test-async-provider"))
|
||||||
|
.service(configureServer())
|
||||||
|
.protocol(protocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
ProtocolConfig consumerProtocolConfig = new ProtocolConfig();
|
||||||
|
consumerProtocolConfig.setRegister(false);
|
||||||
|
|
||||||
|
ReferenceConfig<HelloService> referenceConfig = configureClient(port);
|
||||||
|
DubboBootstrap consumerBootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(consumerBootstrap::destroy);
|
||||||
|
consumerBootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-demo-async-api-consumer"))
|
||||||
|
.reference(referenceConfig)
|
||||||
|
.protocol(consumerProtocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// generic call
|
||||||
|
ReferenceConfig<GenericService> reference = convertReference(referenceConfig);
|
||||||
|
GenericService genericService = reference.get();
|
||||||
|
CompletableFuture<Object> response =
|
||||||
|
runWithSpan(
|
||||||
|
"parent",
|
||||||
|
() ->
|
||||||
|
genericService.$invokeAsync(
|
||||||
|
"hello", new String[] {String.class.getName()}, new Object[] {"hello"}));
|
||||||
|
|
||||||
|
assertThat(response.get()).isEqualTo("hello");
|
||||||
|
|
||||||
|
testing()
|
||||||
|
.waitAndAssertTraces(
|
||||||
|
trace ->
|
||||||
|
trace.hasSpansSatisfyingExactly(
|
||||||
|
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
|
||||||
|
span ->
|
||||||
|
span.hasName("org.apache.dubbo.rpc.service.GenericService/$invokeAsync")
|
||||||
|
.hasKind(SpanKind.CLIENT)
|
||||||
|
.hasParent(trace.getSpan(0))
|
||||||
|
.hasAttributesSatisfyingExactly(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"org.apache.dubbo.rpc.service.GenericService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invokeAsync"),
|
||||||
|
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
|
||||||
|
satisfies(
|
||||||
|
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(String.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(Long.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6")))),
|
||||||
|
span ->
|
||||||
|
span.hasName(
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello")
|
||||||
|
.hasKind(SpanKind.SERVER)
|
||||||
|
.hasParent(trace.getSpan(1))
|
||||||
|
.hasAttributesSatisfying(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k -> k.isInstanceOf(String.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6"))))));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,411 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.apachedubbo.v2_7;
|
||||||
|
|
||||||
|
import static io.opentelemetry.instrumentation.testing.GlobalTraceUtil.runWithSpan;
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
||||||
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import io.opentelemetry.api.trace.SpanKind;
|
||||||
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService;
|
||||||
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService;
|
||||||
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.HelloServiceImpl;
|
||||||
|
import io.opentelemetry.instrumentation.apachedubbo.v2_7.impl.MiddleServiceImpl;
|
||||||
|
import io.opentelemetry.instrumentation.test.utils.PortUtils;
|
||||||
|
import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension;
|
||||||
|
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||||
|
import io.opentelemetry.semconv.NetworkAttributes;
|
||||||
|
import io.opentelemetry.semconv.ServerAttributes;
|
||||||
|
import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import org.apache.dubbo.common.utils.NetUtils;
|
||||||
|
import org.apache.dubbo.config.ApplicationConfig;
|
||||||
|
import org.apache.dubbo.config.ProtocolConfig;
|
||||||
|
import org.apache.dubbo.config.ReferenceConfig;
|
||||||
|
import org.apache.dubbo.config.RegistryConfig;
|
||||||
|
import org.apache.dubbo.config.ServiceConfig;
|
||||||
|
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
||||||
|
import org.apache.dubbo.rpc.service.GenericService;
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||||
|
|
||||||
|
public abstract class AbstractDubboTraceChainTest {
|
||||||
|
|
||||||
|
@RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create();
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void setUp() throws Exception {
|
||||||
|
System.setProperty("dubbo.application.qos-enable", "false");
|
||||||
|
Field field = NetUtils.class.getDeclaredField("LOCAL_ADDRESS");
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(null, InetAddress.getLoopbackAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void tearDown() {
|
||||||
|
System.clearProperty("dubbo.application.qos-enable");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract InstrumentationExtension testing();
|
||||||
|
|
||||||
|
ReferenceConfig<HelloService> configureClient(int port) {
|
||||||
|
ReferenceConfig<HelloService> reference = new ReferenceConfig<>();
|
||||||
|
reference.setInterface(HelloService.class);
|
||||||
|
reference.setGeneric("true");
|
||||||
|
reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000");
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReferenceConfig<HelloService> configureLocalClient(int port) {
|
||||||
|
ReferenceConfig<HelloService> reference = new ReferenceConfig<>();
|
||||||
|
reference.setInterface(HelloService.class);
|
||||||
|
reference.setGeneric("true");
|
||||||
|
reference.setUrl("injvm://localhost:" + port + "/?timeout=30000");
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReferenceConfig<MiddleService> configureMiddleClient(int port) {
|
||||||
|
ReferenceConfig<MiddleService> reference = new ReferenceConfig<>();
|
||||||
|
reference.setInterface(MiddleService.class);
|
||||||
|
reference.setGeneric("true");
|
||||||
|
reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000");
|
||||||
|
return reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceConfig<HelloService> configureServer() {
|
||||||
|
RegistryConfig registerConfig = new RegistryConfig();
|
||||||
|
registerConfig.setAddress("N/A");
|
||||||
|
ServiceConfig<HelloService> service = new ServiceConfig<>();
|
||||||
|
service.setInterface(HelloService.class);
|
||||||
|
service.setRef(new HelloServiceImpl());
|
||||||
|
service.setRegistry(registerConfig);
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceConfig<MiddleService> configureMiddleServer(
|
||||||
|
ReferenceConfig<HelloService> referenceConfig) {
|
||||||
|
RegistryConfig registerConfig = new RegistryConfig();
|
||||||
|
registerConfig.setAddress("N/A");
|
||||||
|
ServiceConfig<MiddleService> service = new ServiceConfig<>();
|
||||||
|
service.setInterface(MiddleService.class);
|
||||||
|
service.setRef(new MiddleServiceImpl(referenceConfig));
|
||||||
|
service.setRegistry(registerConfig);
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
|
ReferenceConfig<GenericService> convertReference(ReferenceConfig<MiddleService> config) {
|
||||||
|
return (ReferenceConfig) config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test that context is propagated correctly in chained dubbo calls")
|
||||||
|
void testDubboChain() throws ReflectiveOperationException {
|
||||||
|
int port = PortUtils.findOpenPorts(2);
|
||||||
|
int middlePort = port + 1;
|
||||||
|
|
||||||
|
// setup hello service provider
|
||||||
|
ProtocolConfig protocolConfig = new ProtocolConfig();
|
||||||
|
protocolConfig.setPort(port);
|
||||||
|
|
||||||
|
DubboBootstrap bootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(bootstrap::destroy);
|
||||||
|
bootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-test-provider"))
|
||||||
|
.service(configureServer())
|
||||||
|
.protocol(protocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// setup middle service provider, hello service consumer
|
||||||
|
ProtocolConfig middleProtocolConfig = new ProtocolConfig();
|
||||||
|
middleProtocolConfig.setPort(middlePort);
|
||||||
|
|
||||||
|
ReferenceConfig<HelloService> clientReference = configureClient(port);
|
||||||
|
DubboBootstrap middleBootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(middleBootstrap::destroy);
|
||||||
|
middleBootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-demo-middle"))
|
||||||
|
.reference(clientReference)
|
||||||
|
.service(configureMiddleServer(clientReference))
|
||||||
|
.protocol(middleProtocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// setup middle service consumer
|
||||||
|
ProtocolConfig consumerProtocolConfig = new ProtocolConfig();
|
||||||
|
consumerProtocolConfig.setRegister(false);
|
||||||
|
|
||||||
|
ReferenceConfig<MiddleService> middleReference = configureMiddleClient(middlePort);
|
||||||
|
DubboBootstrap consumerBootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(consumerBootstrap::destroy);
|
||||||
|
consumerBootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-demo-api-consumer"))
|
||||||
|
.reference(middleReference)
|
||||||
|
.protocol(consumerProtocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
GenericService genericService = convertReference(middleReference).get();
|
||||||
|
|
||||||
|
Object response =
|
||||||
|
runWithSpan(
|
||||||
|
"parent",
|
||||||
|
() ->
|
||||||
|
genericService.$invoke(
|
||||||
|
"hello", new String[] {String.class.getName()}, new Object[] {"hello"}));
|
||||||
|
|
||||||
|
assertThat(response).isEqualTo("hello");
|
||||||
|
testing()
|
||||||
|
.waitAndAssertTraces(
|
||||||
|
trace ->
|
||||||
|
trace.hasSpansSatisfyingExactly(
|
||||||
|
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
|
||||||
|
span ->
|
||||||
|
span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke")
|
||||||
|
.hasKind(SpanKind.CLIENT)
|
||||||
|
.hasParent(trace.getSpan(0))
|
||||||
|
.hasAttributesSatisfyingExactly(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"org.apache.dubbo.rpc.service.GenericService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
|
||||||
|
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
|
||||||
|
satisfies(
|
||||||
|
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(String.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(Long.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6")))),
|
||||||
|
span ->
|
||||||
|
span.hasName(
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService/hello")
|
||||||
|
.hasKind(SpanKind.SERVER)
|
||||||
|
.hasParent(trace.getSpan(1))
|
||||||
|
.hasAttributesSatisfying(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k -> k.isInstanceOf(String.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6")))),
|
||||||
|
span ->
|
||||||
|
span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke")
|
||||||
|
.hasKind(SpanKind.CLIENT)
|
||||||
|
.hasParent(trace.getSpan(2))
|
||||||
|
.hasAttributesSatisfyingExactly(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"org.apache.dubbo.rpc.service.GenericService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
|
||||||
|
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
|
||||||
|
satisfies(
|
||||||
|
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(String.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(Long.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6")))),
|
||||||
|
span ->
|
||||||
|
span.hasName(
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello")
|
||||||
|
.hasKind(SpanKind.SERVER)
|
||||||
|
.hasParent(trace.getSpan(3))
|
||||||
|
.hasAttributesSatisfying(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k -> k.isInstanceOf(String.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6"))))));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("test ignore injvm calls")
|
||||||
|
void testDubboChainInJvm() throws ReflectiveOperationException {
|
||||||
|
int port = PortUtils.findOpenPorts(2);
|
||||||
|
int middlePort = port + 1;
|
||||||
|
|
||||||
|
// setup hello service provider
|
||||||
|
ProtocolConfig protocolConfig = new ProtocolConfig();
|
||||||
|
protocolConfig.setPort(port);
|
||||||
|
|
||||||
|
DubboBootstrap bootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(bootstrap::destroy);
|
||||||
|
bootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-test-provider"))
|
||||||
|
.service(configureServer())
|
||||||
|
.protocol(protocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// setup middle service provider, hello service consumer
|
||||||
|
ProtocolConfig middleProtocolConfig = new ProtocolConfig();
|
||||||
|
middleProtocolConfig.setPort(middlePort);
|
||||||
|
|
||||||
|
ReferenceConfig<HelloService> clientReference = configureLocalClient(port);
|
||||||
|
DubboBootstrap middleBootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(middleBootstrap::destroy);
|
||||||
|
middleBootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-demo-middle"))
|
||||||
|
.service(configureMiddleServer(clientReference))
|
||||||
|
.protocol(middleProtocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
// setup middle service consumer
|
||||||
|
ProtocolConfig consumerProtocolConfig = new ProtocolConfig();
|
||||||
|
consumerProtocolConfig.setRegister(false);
|
||||||
|
|
||||||
|
ReferenceConfig<MiddleService> middleReference = configureMiddleClient(middlePort);
|
||||||
|
DubboBootstrap consumerBootstrap = DubboTestUtil.newDubboBootstrap();
|
||||||
|
cleanup.deferCleanup(consumerBootstrap::destroy);
|
||||||
|
consumerBootstrap
|
||||||
|
.application(new ApplicationConfig("dubbo-demo-api-consumer"))
|
||||||
|
.reference(middleReference)
|
||||||
|
.protocol(consumerProtocolConfig)
|
||||||
|
.start();
|
||||||
|
|
||||||
|
GenericService genericService = convertReference(middleReference).get();
|
||||||
|
|
||||||
|
Object response =
|
||||||
|
runWithSpan(
|
||||||
|
"parent",
|
||||||
|
() ->
|
||||||
|
genericService.$invoke(
|
||||||
|
"hello", new String[] {String.class.getName()}, new Object[] {"hello"}));
|
||||||
|
|
||||||
|
assertThat(response).isEqualTo("hello");
|
||||||
|
testing()
|
||||||
|
.waitAndAssertTraces(
|
||||||
|
trace ->
|
||||||
|
trace.hasSpansSatisfyingExactly(
|
||||||
|
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
|
||||||
|
span ->
|
||||||
|
span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke")
|
||||||
|
.hasKind(SpanKind.CLIENT)
|
||||||
|
.hasParent(trace.getSpan(0))
|
||||||
|
.hasAttributesSatisfyingExactly(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"org.apache.dubbo.rpc.service.GenericService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "$invoke"),
|
||||||
|
equalTo(ServerAttributes.SERVER_ADDRESS, "localhost"),
|
||||||
|
satisfies(
|
||||||
|
ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(String.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isInstanceOf(Long.class))),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6")))),
|
||||||
|
span ->
|
||||||
|
span.hasName(
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService/hello")
|
||||||
|
.hasKind(SpanKind.SERVER)
|
||||||
|
.hasParent(trace.getSpan(1))
|
||||||
|
.hasAttributesSatisfying(
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SYSTEM,
|
||||||
|
RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO),
|
||||||
|
equalTo(
|
||||||
|
RpcIncubatingAttributes.RPC_SERVICE,
|
||||||
|
"io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"),
|
||||||
|
equalTo(RpcIncubatingAttributes.RPC_METHOD, "hello"),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_ADDRESS,
|
||||||
|
k -> k.isInstanceOf(String.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_PEER_PORT,
|
||||||
|
k -> k.isInstanceOf(Long.class)),
|
||||||
|
satisfies(
|
||||||
|
NetworkAttributes.NETWORK_TYPE,
|
||||||
|
k ->
|
||||||
|
k.satisfiesAnyOf(
|
||||||
|
val -> assertThat(val).isNull(),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv4"),
|
||||||
|
val -> assertThat(val).isEqualTo("ipv6"))))));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.opentelemetry.instrumentation.apachedubbo.v2_7;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
|
||||||
|
|
||||||
|
/** compatible with dubbo3.x and dubbo 2.7 */
|
||||||
|
class DubboTestUtil {
|
||||||
|
|
||||||
|
private DubboTestUtil() {}
|
||||||
|
|
||||||
|
static Object newFrameworkModel() {
|
||||||
|
try {
|
||||||
|
// only present in latest dep
|
||||||
|
return Class.forName("org.apache.dubbo.rpc.model.FrameworkModel")
|
||||||
|
.getDeclaredConstructor()
|
||||||
|
.newInstance();
|
||||||
|
} catch (ReflectiveOperationException exception) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static DubboBootstrap newDubboBootstrap() throws ReflectiveOperationException {
|
||||||
|
Object newFrameworkModel = newFrameworkModel();
|
||||||
|
if (newFrameworkModel == null) {
|
||||||
|
return newDubboBootstrapV27();
|
||||||
|
} else {
|
||||||
|
return newDubboBootstrapV3(newFrameworkModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DubboBootstrap newDubboBootstrapV3(Object newFrameworkModel)
|
||||||
|
throws ReflectiveOperationException {
|
||||||
|
Method getInstance =
|
||||||
|
DubboBootstrap.class.getDeclaredMethod("newInstance", newFrameworkModel.getClass());
|
||||||
|
return (DubboBootstrap) getInstance.invoke(null, newFrameworkModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DubboBootstrap newDubboBootstrapV27() throws ReflectiveOperationException {
|
||||||
|
Constructor<DubboBootstrap> constructor = DubboBootstrap.class.getDeclaredConstructor();
|
||||||
|
constructor.setAccessible(true);
|
||||||
|
return constructor.newInstance();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue