From 060c9c4e5cec810609d0c881ef84c3183928faf4 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Wed, 14 Aug 2024 15:19:51 +0800 Subject: [PATCH 01/28] convert module apache-dubbo-2.7 test case from groovy to java --- .../javaagent/build.gradle.kts | 28 +- .../apachedubbo/v2_7/DubboAgentTest.java | 21 + .../v2_7/DubboAgentTraceChainTest.java | 21 + .../apachedubbo/v2_7/DubboTest.groovy | 11 - .../v2_7/DubboTraceChainTest.groovy | 11 - .../apachedubbo/v2_7/DubboTest.groovy | 11 - .../v2_7/DubboTraceChainTest.groovy | 11 - .../apachedubbo/v2_7/DubboTest.java | 21 + .../apachedubbo/v2_7/DubboTraceChainTest.java | 21 + .../apachedubbo/v2_7/AbstractDubboTest.groovy | 211 --------- .../v2_7/AbstractDubboTraceChainTest.groovy | 287 ------------- .../apachedubbo/v2_7/DubboTestUtil.groovy | 26 -- .../apachedubbo/v2_7/AbstractDubboTest.java | 236 +++++++++++ .../v2_7/AbstractDubboTraceChainTest.java | 400 ++++++++++++++++++ .../apachedubbo/v2_7/DubboTestUtil.java | 59 +++ 15 files changed, 780 insertions(+), 595 deletions(-) create mode 100644 instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java create mode 100644 instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java delete mode 100644 instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.groovy delete mode 100644 instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.groovy delete mode 100644 instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.groovy delete mode 100644 instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.groovy create mode 100644 instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java create mode 100644 instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java delete mode 100644 instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy delete mode 100644 instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy delete mode 100644 instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.groovy create mode 100644 instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java create mode 100644 instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java create mode 100644 instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.java diff --git a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts index 6e1a666c9908..117a909551b8 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts +++ b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts @@ -15,28 +15,8 @@ dependencies { implementation(project(":instrumentation:apache-dubbo-2.7:library-autoconfigure")) library("org.apache.dubbo:dubbo:2.7.0") -} - -val latestDepTest = findProperty("testLatestDeps") as Boolean -testing { - suites { - // using a test suite to ensure that project(":instrumentation:apache-dubbo-2.7:library-autoconfigure") - // is not available on test runtime class path, otherwise instrumentation from library-autoconfigure - // module would be used instead of the javaagent instrumentation that we want to test - val testDubbo by registering(JvmTestSuite::class) { - dependencies { - implementation(project(":instrumentation:apache-dubbo-2.7:testing")) - if (latestDepTest) { - implementation("org.apache.dubbo:dubbo:+") - implementation("org.apache.dubbo:dubbo-config-api:+") - } else { - implementation("org.apache.dubbo:dubbo:2.7.0") - implementation("org.apache.dubbo:dubbo-config-api:2.7.0") - } - } - } - } + testImplementation(project(":instrumentation:apache-dubbo-2.7:testing")) } tasks.withType().configureEach { @@ -46,9 +26,3 @@ tasks.withType().configureEach { // required on jdk17 jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") } - -tasks { - check { - dependsOn(testing.suites) - } -} diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java b/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java new file mode 100644 index 000000000000..2697cd310a7d --- /dev/null +++ b/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java @@ -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.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class DubboAgentTest extends AbstractDubboTest { + + @RegisterExtension + static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + @Override + InstrumentationExtension testing() { + return testing; + } +} diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java b/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java new file mode 100644 index 000000000000..c42aed307555 --- /dev/null +++ b/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java @@ -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.AgentInstrumentationExtension; +import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import org.junit.jupiter.api.extension.RegisterExtension; + +public class DubboAgentTraceChainTest extends AbstractDubboTraceChainTest { + + @RegisterExtension + static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); + + @Override + InstrumentationExtension testing() { + return testing; + } +} diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.groovy b/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.groovy deleted file mode 100644 index 36f81f58b828..000000000000 --- a/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.groovy +++ /dev/null @@ -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 { -} diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.groovy b/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.groovy deleted file mode 100644 index 432be0305633..000000000000 --- a/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.groovy +++ /dev/null @@ -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 { -} diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.groovy b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.groovy deleted file mode 100644 index daa71bc333c6..000000000000 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.groovy +++ /dev/null @@ -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 { -} diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.groovy b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.groovy deleted file mode 100644 index ee0b1040dec5..000000000000 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.groovy +++ /dev/null @@ -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 { -} diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java new file mode 100644 index 000000000000..d91e30fb7db4 --- /dev/null +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java @@ -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; + +public class DubboTest extends AbstractDubboTest { + + @RegisterExtension + static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); + + @Override + InstrumentationExtension testing() { + return testing; + } +} diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java new file mode 100644 index 000000000000..b5e9a79a992f --- /dev/null +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java @@ -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; + +public class DubboTraceChainTest extends AbstractDubboTraceChainTest { + + @RegisterExtension + static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); + + @Override + InstrumentationExtension testing() { + return testing; + } +} diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy deleted file mode 100644 index 6cd2d132a41d..000000000000 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.groovy +++ /dev/null @@ -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 configureClient(int port) { - ReferenceConfig 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 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() - } -} diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy deleted file mode 100644 index a7e2f6150b67..000000000000 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.groovy +++ /dev/null @@ -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 configureClient(int port) { - ReferenceConfig reference = new ReferenceConfig<>() - reference.setInterface(HelloService) - reference.setGeneric("true") - reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000") - return reference - } - - ReferenceConfig configureLocalClient(int port) { - ReferenceConfig reference = new ReferenceConfig<>() - reference.setInterface(HelloService) - reference.setGeneric("true") - reference.setUrl("injvm://localhost:" + port + "/?timeout=30000") - return reference - } - - ReferenceConfig configureMiddleClient(int port) { - ReferenceConfig 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 service = new ServiceConfig<>() - service.setInterface(HelloService) - service.setRef(new HelloServiceImpl()) - service.setRegistry(registerConfig) - return service - } - - ServiceConfig configureMiddleServer(ReferenceConfig referenceConfig) { - def registerConfig = new RegistryConfig() - registerConfig.setAddress("N/A") - ServiceConfig 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() - } -} diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.groovy b/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.groovy deleted file mode 100644 index 03ec85a3955d..000000000000 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/groovy/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.groovy +++ /dev/null @@ -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) - } -} diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java new file mode 100644 index 000000000000..0b6be57bfee3 --- /dev/null +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -0,0 +1,236 @@ +/* + * 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.junit.jupiter.api.Assertions.assertEquals; + +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.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 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.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +abstract class AbstractDubboTest { + + private final ProtocolConfig protocolConfig = new ProtocolConfig(); + + abstract InstrumentationExtension testing(); + + private DubboBootstrap bootstrap; + private DubboBootstrap consumerBootstrap; + + @BeforeAll + static void setUp() throws Exception { + Field field = NetUtils.class.getDeclaredField("LOCAL_ADDRESS"); + field.setAccessible(true); + field.set(null, InetAddress.getLoopbackAddress()); + } + + @AfterEach + public void afterEach() { + if (bootstrap != null) bootstrap.destroy(); + if (consumerBootstrap != null) consumerBootstrap.destroy(); + } + + ReferenceConfig configureClient(int port) { + ReferenceConfig reference = new ReferenceConfig<>(); + reference.setInterface(HelloService.class); + reference.setGeneric("true"); + reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000"); + return reference; + } + + ServiceConfig configureServer() { + RegistryConfig registerConfig = new RegistryConfig(); + registerConfig.setAddress("N/A"); + ServiceConfig service = new ServiceConfig<>(); + service.setInterface(HelloService.class); + service.setRef(new HelloServiceImpl()); + service.setRegistry(registerConfig); + return service; + } + + @Test + @SuppressWarnings({"rawtypes", "unchecked"}) + void testApacheDubboBase() throws Exception { + int port = PortUtils.findOpenPort(); + protocolConfig.setPort(port); + // provider boostrap + bootstrap = DubboTestUtil.newDubboBootstrap(); + bootstrap + .application(new ApplicationConfig("dubbo-test-provider")) + .service(configureServer()) + .protocol(protocolConfig) + .start(); + + // consumer boostrap + consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + ReferenceConfig 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 reference = referenceConfig; + GenericService genericService = reference.get(); + + Object[] o = new Object[1]; + o[0] = "hello"; + Object response = + runWithSpan( + "parent", + () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); + + assertEquals("hello", response); + 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) + .hasAttributesSatisfyingExactly( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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, AbstractAssert::isNull), + satisfies( + NetworkAttributes.NETWORK_PEER_PORT, AbstractAssert::isNull), + satisfies(NetworkAttributes.NETWORK_TYPE, AbstractAssert::isNull)), + span -> + span.hasName( + "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello") + .hasKind(SpanKind.SERVER) + .hasAttributesSatisfying( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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 + @SuppressWarnings({"rawtypes", "unchecked"}) + void testApacheDubboTest() throws Exception { + int port = PortUtils.findOpenPort(); + protocolConfig.setPort(port); + + bootstrap = DubboTestUtil.newDubboBootstrap(); + bootstrap + .application(new ApplicationConfig("dubbo-test-async-provider")) + .service(configureServer()) + .protocol(protocolConfig) + .start(); + + ProtocolConfig consumerProtocolConfig = new ProtocolConfig(); + consumerProtocolConfig.setRegister(false); + + ReferenceConfig referenceConfig = configureClient(port); + consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + consumerBootstrap + .application(new ApplicationConfig("dubbo-demo-async-api-consumer")) + .reference(referenceConfig) + .protocol(consumerProtocolConfig) + .start(); + + // generic call + ReferenceConfig reference = referenceConfig; + GenericService genericService = reference.get(); + Object[] o = new Object[1]; + o[0] = "hello"; + CompletableFuture response = + runWithSpan( + "parent", + () -> genericService.$invokeAsync("hello", new String[] {String.class.getName()}, o)); + + assertEquals("hello", response.get()); + + 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) + .hasAttributesSatisfyingExactly( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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, AbstractAssert::isNull), + satisfies( + NetworkAttributes.NETWORK_PEER_PORT, AbstractAssert::isNull), + satisfies(NetworkAttributes.NETWORK_TYPE, AbstractAssert::isNull)), + span -> + span.hasName( + "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello") + .hasKind(SpanKind.SERVER) + .hasAttributesSatisfying( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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)))); + } +} diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java new file mode 100644 index 000000000000..bac70999fa8f --- /dev/null +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -0,0 +1,400 @@ +/* + * 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 static org.junit.jupiter.api.Assertions.assertEquals; + +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.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.Arrays; +import java.util.List; +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.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +abstract class AbstractDubboTraceChainTest { + + private final ProtocolConfig protocolConfig = new ProtocolConfig(); + private DubboBootstrap bootstrap; + private DubboBootstrap consumerBootstrap; + private DubboBootstrap middleBootstrap; + + @BeforeAll + static void setUp() throws Exception { + Field field = NetUtils.class.getDeclaredField("LOCAL_ADDRESS"); + field.setAccessible(true); + field.set(null, InetAddress.getLoopbackAddress()); + } + + abstract InstrumentationExtension testing(); + + @AfterEach + public void afterEach() { + List dubboBootstraps = + Arrays.asList(bootstrap, consumerBootstrap, middleBootstrap); + for (DubboBootstrap bootstrap : dubboBootstraps) { + try { + if (bootstrap != null) { + bootstrap.destroy(); + } + } catch (Exception e) { + // ignore + } + } + } + + ReferenceConfig configureClient(int port) { + ReferenceConfig reference = new ReferenceConfig<>(); + reference.setInterface(HelloService.class); + reference.setGeneric("true"); + reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000"); + return reference; + } + + ReferenceConfig configureLocalClient(int port) { + ReferenceConfig reference = new ReferenceConfig<>(); + reference.setInterface(HelloService.class); + reference.setGeneric("true"); + reference.setUrl("injvm://localhost:" + port + "/?timeout=30000"); + return reference; + } + + ReferenceConfig configureMiddleClient(int port) { + ReferenceConfig reference = new ReferenceConfig<>(); + reference.setInterface(MiddleService.class); + reference.setGeneric("true"); + reference.setUrl("dubbo://localhost:" + port + "/?timeout=30000"); + return reference; + } + + ServiceConfig configureServer() { + RegistryConfig registerConfig = new RegistryConfig(); + registerConfig.setAddress("N/A"); + ServiceConfig service = new ServiceConfig<>(); + service.setInterface(HelloService.class); + service.setRef(new HelloServiceImpl()); + service.setRegistry(registerConfig); + return service; + } + + ServiceConfig configureMiddleServer( + ReferenceConfig referenceConfig) { + RegistryConfig registerConfig = new RegistryConfig(); + registerConfig.setAddress("N/A"); + ServiceConfig service = new ServiceConfig<>(); + service.setInterface(MiddleService.class); + service.setRef(new MiddleServiceImpl(referenceConfig)); + service.setRegistry(registerConfig); + return service; + } + + @Test + @DisplayName("test that context is propagated correctly in chained dubbo calls") + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testDubboChain() { + int port = PortUtils.findOpenPorts(2); + int middlePort = port + 1; + + // setup hello service provider + ProtocolConfig protocolConfig = new ProtocolConfig(); + protocolConfig.setPort(port); + + bootstrap = DubboTestUtil.newDubboBootstrap(); + 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 clientReference = configureClient(port); + middleBootstrap = DubboTestUtil.newDubboBootstrap(); + 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 middleReference = configureMiddleClient(middlePort); + consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + consumerBootstrap + .application(new ApplicationConfig("dubbo-demo-api-consumer")) + .reference(middleReference) + .protocol(consumerProtocolConfig) + .start(); + + GenericService genericService = (GenericService) middleReference.get(); + + Object[] o = new Object[1]; + o[0] = "hello"; + Object response = + runWithSpan( + "parent", + () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); + + assertEquals("hello", response); + 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) + .hasAttributesSatisfyingExactly( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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) + .hasAttributesSatisfying( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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) + .hasAttributesSatisfyingExactly( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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) + .hasAttributesSatisfying( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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") + @SuppressWarnings({"rawtypes", "unchecked"}) + public void testDubboChainInJvm() { + int port = PortUtils.findOpenPorts(2); + int middlePort = port + 1; + + // setup hello service provider + ProtocolConfig protocolConfig = new ProtocolConfig(); + protocolConfig.setPort(port); + + bootstrap = DubboTestUtil.newDubboBootstrap(); + 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 clientReference = configureLocalClient(port); + middleBootstrap = DubboTestUtil.newDubboBootstrap(); + 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 middleReference = configureMiddleClient(middlePort); + consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + consumerBootstrap + .application(new ApplicationConfig("dubbo-demo-api-consumer")) + .reference(middleReference) + .protocol(consumerProtocolConfig) + .start(); + + GenericService genericService = (GenericService) middleReference.get(); + + Object[] o = new Object[1]; + o[0] = "hello"; + Object response = + runWithSpan( + "parent", + () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); + + assertEquals("hello", response); + 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) + .hasAttributesSatisfyingExactly( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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) + .hasAttributesSatisfying( + equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "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")))))); + } +} diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.java new file mode 100644 index 000000000000..6c7e72c154bf --- /dev/null +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.java @@ -0,0 +1,59 @@ +/* + * 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.InvocationTargetException; +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; + } + } + + @SuppressWarnings("ThrowSpecificExceptions") + static DubboBootstrap newDubboBootstrap() { + Object newFrameworkModel = newFrameworkModel(); + try { + if (newFrameworkModel == null) { + return newDubboBootstrapV27(); + } else { + return newDubboBootstrapV3(newFrameworkModel); + } + } catch (ReflectiveOperationException exception) { + throw new RuntimeException("Error creating new DubboBootstrap instance", exception); + } + } + + private static DubboBootstrap newDubboBootstrapV3(Object newFrameworkModel) + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + Method getInstance = + DubboBootstrap.class.getDeclaredMethod("newInstance", newFrameworkModel.getClass()); + return (DubboBootstrap) getInstance.invoke(null, newFrameworkModel); + } + + private static DubboBootstrap newDubboBootstrapV27() + throws NoSuchMethodException, + InstantiationException, + IllegalAccessException, + InvocationTargetException { + Constructor constructor = DubboBootstrap.class.getDeclaredConstructor(); + constructor.setAccessible(true); + return constructor.newInstance(); + } +} From 6085bcc55c9a46d435ad6c1d9b52faf9ddfc1526 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Wed, 14 Aug 2024 19:30:03 +0800 Subject: [PATCH 02/28] fix compile error --- .../apachedubbo/v2_7/AbstractDubboTest.java | 20 +++++++++++++++---- .../v2_7/AbstractDubboTraceChainTest.java | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 0b6be57bfee3..2f3134b67df0 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -20,7 +20,10 @@ import io.opentelemetry.semconv.incubating.RpcIncubatingAttributes; import java.lang.reflect.Field; import java.net.InetAddress; +import java.util.Arrays; +import java.util.List; 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; @@ -53,9 +56,18 @@ static void setUp() throws Exception { } @AfterEach + @SuppressWarnings("CatchingUnchecked") public void afterEach() { - if (bootstrap != null) bootstrap.destroy(); - if (consumerBootstrap != null) consumerBootstrap.destroy(); + List dubboBootstraps = Arrays.asList(bootstrap, consumerBootstrap); + for (DubboBootstrap bootstrap : dubboBootstraps) { + try { + if (bootstrap != null) { + bootstrap.destroy(); + } + } catch (Exception e) { + // ignore + } + } } ReferenceConfig configureClient(int port) { @@ -78,7 +90,7 @@ ServiceConfig configureServer() { @Test @SuppressWarnings({"rawtypes", "unchecked"}) - void testApacheDubboBase() throws Exception { + void testApacheDubboBase() { int port = PortUtils.findOpenPort(); protocolConfig.setPort(port); // provider boostrap @@ -157,7 +169,7 @@ void testApacheDubboBase() throws Exception { @Test @SuppressWarnings({"rawtypes", "unchecked"}) - void testApacheDubboTest() throws Exception { + void testApacheDubboTest() throws ExecutionException, InterruptedException { int port = PortUtils.findOpenPort(); protocolConfig.setPort(port); diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index bac70999fa8f..490114bc4b69 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -42,7 +42,6 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) abstract class AbstractDubboTraceChainTest { - private final ProtocolConfig protocolConfig = new ProtocolConfig(); private DubboBootstrap bootstrap; private DubboBootstrap consumerBootstrap; private DubboBootstrap middleBootstrap; @@ -57,6 +56,7 @@ static void setUp() throws Exception { abstract InstrumentationExtension testing(); @AfterEach + @SuppressWarnings("CatchingUnchecked") public void afterEach() { List dubboBootstraps = Arrays.asList(bootstrap, consumerBootstrap, middleBootstrap); From 855291b5510559422dcb27acfc8ea65409a300d1 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Wed, 14 Aug 2024 19:33:47 +0800 Subject: [PATCH 03/28] fix ut --- .../instrumentation/apachedubbo/v2_7/AbstractDubboTest.java | 2 -- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 2f3134b67df0..daeb9f6ef0d3 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -133,7 +133,6 @@ void testApacheDubboBase() { span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( RpcIncubatingAttributes.RPC_SERVICE, @@ -212,7 +211,6 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { span.hasName("org.apache.dubbo.rpc.service.GenericService/$invokeAsync") .hasKind(SpanKind.CLIENT) .hasAttributesSatisfyingExactly( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( RpcIncubatingAttributes.RPC_SERVICE, diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 490114bc4b69..259484cc196a 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -119,7 +119,7 @@ ServiceConfig configureMiddleServer( @Test @DisplayName("test that context is propagated correctly in chained dubbo calls") @SuppressWarnings({"rawtypes", "unchecked"}) - public void testDubboChain() { + void testDubboChain() { int port = PortUtils.findOpenPorts(2); int middlePort = port + 1; @@ -287,7 +287,7 @@ public void testDubboChain() { @Test @DisplayName("test ignore injvm calls") @SuppressWarnings({"rawtypes", "unchecked"}) - public void testDubboChainInJvm() { + void testDubboChainInJvm() { int port = PortUtils.findOpenPorts(2); int middlePort = port + 1; From ff776e060c95ed65c031ea01ec587854f0457f18 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Wed, 14 Aug 2024 19:39:20 +0800 Subject: [PATCH 04/28] fix ut class --- .../instrumentation/apachedubbo/v2_7/DubboAgentTest.java | 2 +- .../apachedubbo/v2_7/DubboAgentTraceChainTest.java | 2 +- .../instrumentation/apachedubbo/v2_7/DubboTest.java | 2 +- .../instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java b/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java index 2697cd310a7d..98d4553f8b52 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java +++ b/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import org.junit.jupiter.api.extension.RegisterExtension; -public class DubboAgentTest extends AbstractDubboTest { +class DubboAgentTest extends AbstractDubboTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java b/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java index c42aed307555..014f12041809 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; import org.junit.jupiter.api.extension.RegisterExtension; -public class DubboAgentTraceChainTest extends AbstractDubboTraceChainTest { +class DubboAgentTraceChainTest extends AbstractDubboTraceChainTest { @RegisterExtension static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java index d91e30fb7db4..734ef4184419 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; import org.junit.jupiter.api.extension.RegisterExtension; -public class DubboTest extends AbstractDubboTest { +class DubboTest extends AbstractDubboTest { @RegisterExtension static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java index b5e9a79a992f..8d55176fbdd6 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java @@ -9,7 +9,7 @@ import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; import org.junit.jupiter.api.extension.RegisterExtension; -public class DubboTraceChainTest extends AbstractDubboTraceChainTest { +class DubboTraceChainTest extends AbstractDubboTraceChainTest { @RegisterExtension static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); From 33790bb0c856063f04829d5b78ea8d2463549a7e Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Thu, 15 Aug 2024 14:29:58 +0800 Subject: [PATCH 05/28] fix ut fail --- instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts index 117a909551b8..4966d6e615da 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts +++ b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts @@ -14,7 +14,7 @@ muzzle { dependencies { implementation(project(":instrumentation:apache-dubbo-2.7:library-autoconfigure")) - library("org.apache.dubbo:dubbo:2.7.0") + library("org.apache.dubbo:dubbo:2.7.5") testImplementation(project(":instrumentation:apache-dubbo-2.7:testing")) } From 051d877310d3dc26ff5affc0f0d6467f72e8a4a4 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Thu, 15 Aug 2024 20:16:37 +0800 Subject: [PATCH 06/28] fix some ut fail with dubbo 3.2.15 --- .../apachedubbo/v2_7/AbstractDubboTest.java | 55 ++++++++++++++++--- .../v2_7/AbstractDubboTraceChainTest.java | 9 ++- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index daeb9f6ef0d3..b46971589628 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -8,6 +8,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 static org.junit.jupiter.api.Assertions.assertEquals; import io.opentelemetry.api.trace.SpanKind; @@ -33,6 +34,7 @@ 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.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -50,11 +52,17 @@ abstract class AbstractDubboTest { @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 setDown() { + System.clearProperty("dubbo.application.qos-enable"); + } + @AfterEach @SuppressWarnings("CatchingUnchecked") public void afterEach() { @@ -142,10 +150,24 @@ void testApacheDubboBase() { satisfies( ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)), satisfies( - NetworkAttributes.NETWORK_PEER_ADDRESS, AbstractAssert::isNull), + 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_PEER_PORT, AbstractAssert::isNull), - satisfies(NetworkAttributes.NETWORK_TYPE, AbstractAssert::isNull)), + 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") @@ -220,10 +242,24 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { satisfies( ServerAttributes.SERVER_PORT, k -> k.isInstanceOf(Long.class)), satisfies( - NetworkAttributes.NETWORK_PEER_ADDRESS, AbstractAssert::isNull), + 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_PEER_PORT, AbstractAssert::isNull), - satisfies(NetworkAttributes.NETWORK_TYPE, AbstractAssert::isNull)), + 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") @@ -241,6 +277,11 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { NetworkAttributes.NETWORK_PEER_PORT, k -> k.isInstanceOf(Long.class)), satisfies( - NetworkAttributes.NETWORK_TYPE, AbstractAssert::isNull)))); + NetworkAttributes.NETWORK_TYPE, + k -> + k.satisfiesAnyOf( + val -> assertThat(val).isNull(), + val -> assertThat(val).isEqualTo("ipv4"), + val -> assertThat(val).isEqualTo("ipv6")))))); } } diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 259484cc196a..7c5d20e18787 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -33,6 +33,7 @@ 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.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; @@ -48,11 +49,17 @@ abstract class AbstractDubboTraceChainTest { @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 setDown() { + System.clearProperty("dubbo.application.qos-enable"); + } + abstract InstrumentationExtension testing(); @AfterEach @@ -310,7 +317,7 @@ void testDubboChainInJvm() { middleBootstrap = DubboTestUtil.newDubboBootstrap(); middleBootstrap .application(new ApplicationConfig("dubbo-demo-middle")) - .reference(clientReference) + // .reference(clientReference) .service(configureMiddleServer(clientReference)) .protocol(middleProtocolConfig) .start(); From f3c6b5ceb60fd27a71163f7180d4d2ccc4b9a4f5 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Fri, 16 Aug 2024 10:45:17 +0800 Subject: [PATCH 07/28] fix more ut problem --- instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts | 4 +++- .../apache-dubbo-2.7/library-autoconfigure/build.gradle.kts | 5 +++-- .../instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java | 2 ++ .../instrumentation/apachedubbo/v2_7/TracingFilter.java | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts index 4966d6e615da..24066794da23 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts +++ b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts @@ -10,13 +10,15 @@ muzzle { assertInverse.set(true) } } +val apacheDubboVersion = "2.7.5" dependencies { implementation(project(":instrumentation:apache-dubbo-2.7:library-autoconfigure")) - library("org.apache.dubbo:dubbo:2.7.5") + library("org.apache.dubbo:dubbo:$apacheDubboVersion") testImplementation(project(":instrumentation:apache-dubbo-2.7:testing")) + testLibrary("org.apache.dubbo:dubbo-config-api:$apacheDubboVersion") } tasks.withType().configureEach { diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts b/instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts index c37558dd4f6d..d052006d185c 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts @@ -1,16 +1,17 @@ plugins { id("otel.library-instrumentation") } +val apacheDubboVersion = "2.7.5" dependencies { compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") - library("org.apache.dubbo:dubbo:2.7.0") + library("org.apache.dubbo:dubbo:$apacheDubboVersion") testImplementation(project(":instrumentation:apache-dubbo-2.7:testing")) - testLibrary("org.apache.dubbo:dubbo-config-api:2.7.0") + testLibrary("org.apache.dubbo:dubbo-config-api:$apacheDubboVersion") } tasks.withType().configureEach { diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java index 2b8e262bf7b0..eef5238bb46d 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboHeadersGetter.java @@ -11,11 +11,13 @@ enum DubboHeadersGetter implements TextMapGetter { INSTANCE; @Override + @SuppressWarnings("deprecation") // deprecation for dubbo 3.2.15 public Iterable keys(DubboRequest request) { return request.invocation().getAttachments().keySet(); } @Override + @SuppressWarnings("deprecation") // deprecation for dubbo 3.2.15 public String get(DubboRequest request, String key) { return request.invocation().getAttachment(key); } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/TracingFilter.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/TracingFilter.java index a19e8ef6d5db..d3d239096bb1 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/TracingFilter.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/TracingFilter.java @@ -29,6 +29,7 @@ final class TracingFilter implements Filter { } @Override + @SuppressWarnings("deprecation") // deprecation for RpcContext.getContext() public Result invoke(Invoker invoker, Invocation invocation) { if (!(invocation instanceof RpcInvocation)) { return invoker.invoke(invocation); From deef59c63f813636382c16c8048171a3a7e4e403 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Fri, 16 Aug 2024 11:44:42 +0800 Subject: [PATCH 08/28] add comments --- instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts index 24066794da23..474e7d80226e 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts +++ b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts @@ -10,6 +10,8 @@ muzzle { assertInverse.set(true) } } +// The testing module use `class DubboBootstrap` which is since 2.7.5, the ut will fail for 2.7.0 +// so we only test it on (2.7.5,) val apacheDubboVersion = "2.7.5" dependencies { From 0a0c324628b5262c73086cf35797d9c53709897d Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Sat, 17 Aug 2024 15:51:43 +0800 Subject: [PATCH 09/28] Update AbstractDubboTraceChainTest.java clean code --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 7c5d20e18787..cd730d0b5421 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -317,7 +317,6 @@ void testDubboChainInJvm() { middleBootstrap = DubboTestUtil.newDubboBootstrap(); middleBootstrap .application(new ApplicationConfig("dubbo-demo-middle")) - // .reference(clientReference) .service(configureMiddleServer(clientReference)) .protocol(middleProtocolConfig) .start(); From e2f880b0bf9e544a6d6a13a5c92c6522d692f711 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:31:51 +0800 Subject: [PATCH 10/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java Co-authored-by: Jay DeLuca --- .../instrumentation/apachedubbo/v2_7/AbstractDubboTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index b46971589628..8c1168026829 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -131,7 +131,7 @@ void testApacheDubboBase() { "parent", () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); - assertEquals("hello", response); + assertThat(response).isEqualTo("hello"); testing() .waitAndAssertTraces( trace -> From 7bf8fe6c374cf12a7ba13d4e9f0ee34c1435029e Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:32:26 +0800 Subject: [PATCH 11/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java Co-authored-by: Jay DeLuca --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index cd730d0b5421..6dd53693cabd 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -184,6 +184,7 @@ void testDubboChain() { span -> span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From 5c211175726464667570f20678d65ea796d43c69 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:33:05 +0800 Subject: [PATCH 12/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java Co-authored-by: Jay DeLuca --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 6dd53693cabd..5d570e361895 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -343,7 +343,7 @@ void testDubboChainInJvm() { "parent", () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); - assertEquals("hello", response); + assertThat(response).isEqualTo("hello"); testing() .waitAndAssertTraces( trace -> From 14492132ee4c0b55982489a092e79ed545da9e0d Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:33:39 +0800 Subject: [PATCH 13/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java Co-authored-by: Jay DeLuca --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 5d570e361895..5b3bc5d1f6bc 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -384,6 +384,7 @@ void testDubboChainInJvm() { span.hasName( "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService/hello") .hasKind(SpanKind.SERVER) + .hasParent(trace.getSpan(1)) .hasAttributesSatisfying( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From 7a4ffbddb21b9a79db0f02d5a08b9ad018635865 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:40:00 +0800 Subject: [PATCH 14/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java Co-authored-by: Jay DeLuca --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 5b3bc5d1f6bc..1fc59e9ec7bd 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -352,6 +352,7 @@ void testDubboChainInJvm() { span -> span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From bf2da2ac6eee3ca1d91d9b03853044b130149dd4 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:40:36 +0800 Subject: [PATCH 15/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java Co-authored-by: Jay DeLuca --- .../instrumentation/apachedubbo/v2_7/AbstractDubboTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 8c1168026829..9e0bd42a1e47 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -172,6 +172,7 @@ void testApacheDubboBase() { span.hasName( "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello") .hasKind(SpanKind.SERVER) + .hasParent(trace.getSpan(1)) .hasAttributesSatisfying( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From 538ebf6a5b23dda731ff90bdbd14a11780f61447 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:41:02 +0800 Subject: [PATCH 16/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java Co-authored-by: Jay DeLuca --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 1fc59e9ec7bd..e27913bb17ed 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -239,6 +239,7 @@ void testDubboChain() { span -> span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(2)) .hasAttributesSatisfyingExactly( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From f9d90d303f9141d7ca00956158c7c816753a6af1 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:41:24 +0800 Subject: [PATCH 17/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java Co-authored-by: Jay DeLuca --- .../instrumentation/apachedubbo/v2_7/AbstractDubboTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 9e0bd42a1e47..11163c924ab2 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -265,6 +265,7 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { span.hasName( "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello") .hasKind(SpanKind.SERVER) + .hasParent(trace.getSpan(1)) .hasAttributesSatisfying( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From 99455e9eaae01385eebda0c99ffa4d764e5e8259 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:42:28 +0800 Subject: [PATCH 18/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java Co-authored-by: Jay DeLuca --- .../instrumentation/apachedubbo/v2_7/AbstractDubboTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 11163c924ab2..10732c0faf4b 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -223,7 +223,7 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { "parent", () -> genericService.$invokeAsync("hello", new String[] {String.class.getName()}, o)); - assertEquals("hello", response.get()); + assertThat(response.get()).isEqualTo("hello"); testing() .waitAndAssertTraces( From c4ccf1afca1a40f55c33ab54505401ccda68b2de Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:43:06 +0800 Subject: [PATCH 19/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java Co-authored-by: Jay DeLuca --- .../instrumentation/apachedubbo/v2_7/AbstractDubboTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 10732c0faf4b..a1f3cdad879f 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -233,6 +233,7 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { span -> span.hasName("org.apache.dubbo.rpc.service.GenericService/$invokeAsync") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From a15a8684f756d43b9a1e56c330b71728fb3b9284 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:43:46 +0800 Subject: [PATCH 20/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java Co-authored-by: Jay DeLuca --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index e27913bb17ed..95a1fffb9bf4 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -175,7 +175,7 @@ void testDubboChain() { "parent", () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); - assertEquals("hello", response); + assertThat(response).isEqualTo("hello"); testing() .waitAndAssertTraces( trace -> From b39442957a04031772d49fe45f3554e6085fba15 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:46:14 +0800 Subject: [PATCH 21/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java Co-authored-by: Jay DeLuca --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 95a1fffb9bf4..b1526bb7467b 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -272,6 +272,7 @@ void testDubboChain() { span.hasName( "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService/hello") .hasKind(SpanKind.SERVER) + .hasParent(trace.getSpan(3)) .hasAttributesSatisfying( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From 7abd7b503e8c8740e099dbb761ce9b61f916b3d5 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:47:26 +0800 Subject: [PATCH 22/28] Update instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java Co-authored-by: Jay DeLuca --- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index b1526bb7467b..9aae4af22b41 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -217,6 +217,7 @@ void testDubboChain() { span.hasName( "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService/hello") .hasKind(SpanKind.SERVER) + .hasParent(trace.getSpan(1)) .hasAttributesSatisfying( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( From a4ba31d0b0361649609338b1cc2374a45e5f4196 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 19 Aug 2024 10:52:39 +0800 Subject: [PATCH 23/28] fix compile warn --- .../instrumentation/apachedubbo/v2_7/AbstractDubboTest.java | 2 +- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index a1f3cdad879f..903550a0c816 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -9,7 +9,6 @@ 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 static org.junit.jupiter.api.Assertions.assertEquals; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService; @@ -140,6 +139,7 @@ void testApacheDubboBase() { span -> span.hasName("org.apache.dubbo.rpc.service.GenericService/$invoke") .hasKind(SpanKind.CLIENT) + .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), equalTo( diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 9aae4af22b41..92e48b578245 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -9,7 +9,6 @@ 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 static org.junit.jupiter.api.Assertions.assertEquals; import io.opentelemetry.api.trace.SpanKind; import io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService; From 3d6fe13ca2c1ced34d44dd9788eddfe331d00a25 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 26 Aug 2024 15:00:16 +0800 Subject: [PATCH 24/28] use setUp/tearDown --- .../instrumentation/apachedubbo/v2_7/AbstractDubboTest.java | 2 +- .../apachedubbo/v2_7/AbstractDubboTraceChainTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 903550a0c816..460c2b18af68 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -58,7 +58,7 @@ static void setUp() throws Exception { } @AfterAll - static void setDown() { + static void tearDown() { System.clearProperty("dubbo.application.qos-enable"); } diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 92e48b578245..b296af04230f 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -55,7 +55,7 @@ static void setUp() throws Exception { } @AfterAll - static void setDown() { + static void tearDown() { System.clearProperty("dubbo.application.qos-enable"); } From b6f5cfd4d0c161de932eea7223a6753bdf5415fb Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Tue, 27 Aug 2024 19:18:01 +0800 Subject: [PATCH 25/28] revert dubbo build.gradle.kts --- .../javaagent/build.gradle.kts | 34 +++++++++++++++---- .../apachedubbo/v2_7/DubboAgentTest.java | 0 .../v2_7/DubboAgentTraceChainTest.java | 0 .../library-autoconfigure/build.gradle.kts | 5 ++- 4 files changed, 30 insertions(+), 9 deletions(-) rename instrumentation/apache-dubbo-2.7/javaagent/src/{test => testDubbo}/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java (100%) rename instrumentation/apache-dubbo-2.7/javaagent/src/{test => testDubbo}/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java (100%) diff --git a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts index 474e7d80226e..6e1a666c9908 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts +++ b/instrumentation/apache-dubbo-2.7/javaagent/build.gradle.kts @@ -10,17 +10,33 @@ muzzle { assertInverse.set(true) } } -// The testing module use `class DubboBootstrap` which is since 2.7.5, the ut will fail for 2.7.0 -// so we only test it on (2.7.5,) -val apacheDubboVersion = "2.7.5" dependencies { implementation(project(":instrumentation:apache-dubbo-2.7:library-autoconfigure")) - library("org.apache.dubbo:dubbo:$apacheDubboVersion") + library("org.apache.dubbo:dubbo:2.7.0") +} + +val latestDepTest = findProperty("testLatestDeps") as Boolean - testImplementation(project(":instrumentation:apache-dubbo-2.7:testing")) - testLibrary("org.apache.dubbo:dubbo-config-api:$apacheDubboVersion") +testing { + suites { + // using a test suite to ensure that project(":instrumentation:apache-dubbo-2.7:library-autoconfigure") + // is not available on test runtime class path, otherwise instrumentation from library-autoconfigure + // module would be used instead of the javaagent instrumentation that we want to test + val testDubbo by registering(JvmTestSuite::class) { + dependencies { + implementation(project(":instrumentation:apache-dubbo-2.7:testing")) + if (latestDepTest) { + implementation("org.apache.dubbo:dubbo:+") + implementation("org.apache.dubbo:dubbo-config-api:+") + } else { + implementation("org.apache.dubbo:dubbo:2.7.0") + implementation("org.apache.dubbo:dubbo-config-api:2.7.0") + } + } + } + } } tasks.withType().configureEach { @@ -30,3 +46,9 @@ tasks.withType().configureEach { // required on jdk17 jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") } + +tasks { + check { + dependsOn(testing.suites) + } +} diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java b/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java similarity index 100% rename from instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java rename to instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java b/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java similarity index 100% rename from instrumentation/apache-dubbo-2.7/javaagent/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java rename to instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts b/instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts index d052006d185c..c37558dd4f6d 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/build.gradle.kts @@ -1,17 +1,16 @@ plugins { id("otel.library-instrumentation") } -val apacheDubboVersion = "2.7.5" dependencies { compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") - library("org.apache.dubbo:dubbo:$apacheDubboVersion") + library("org.apache.dubbo:dubbo:2.7.0") testImplementation(project(":instrumentation:apache-dubbo-2.7:testing")) - testLibrary("org.apache.dubbo:dubbo-config-api:$apacheDubboVersion") + testLibrary("org.apache.dubbo:dubbo-config-api:2.7.0") } tasks.withType().configureEach { From 85878d78e9750631980fd19eb09fc80a7ba5aed2 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Mon, 2 Sep 2024 20:37:16 +0800 Subject: [PATCH 26/28] refine ut suppresswarning and cleanup --- .../apachedubbo/v2_7/DubboAgentTest.java | 5 +- .../v2_7/DubboAgentTraceChainTest.java | 5 +- .../apachedubbo/v2_7/DubboTest.java | 2 +- .../apachedubbo/v2_7/DubboTraceChainTest.java | 2 +- .../apachedubbo/v2_7/AbstractDubboTest.java | 68 ++++++++-------- .../v2_7/AbstractDubboTraceChainTest.java | 78 ++++++++++--------- 6 files changed, 85 insertions(+), 75 deletions(-) rename instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/{ => javaagent}/instrumentation/apachedubbo/v2_7/DubboAgentTest.java (72%) rename instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/{ => javaagent}/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java (72%) diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java b/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/DubboAgentTest.java similarity index 72% rename from instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java rename to instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/DubboAgentTest.java index 98d4553f8b52..1a7e2fb42405 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTest.java +++ b/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/DubboAgentTest.java @@ -3,8 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.apachedubbo.v2_7; +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; @@ -15,7 +16,7 @@ class DubboAgentTest extends AbstractDubboTest { static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @Override - InstrumentationExtension testing() { + protected InstrumentationExtension testing() { return testing; } } diff --git a/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java b/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java similarity index 72% rename from instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java rename to instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java index 014f12041809..bf34ae8633fe 100644 --- a/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/javaagent/src/testDubbo/java/io/opentelemetry/javaagent/instrumentation/apachedubbo/v2_7/DubboAgentTraceChainTest.java @@ -3,8 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package io.opentelemetry.instrumentation.apachedubbo.v2_7; +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; @@ -15,7 +16,7 @@ class DubboAgentTraceChainTest extends AbstractDubboTraceChainTest { static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); @Override - InstrumentationExtension testing() { + protected InstrumentationExtension testing() { return testing; } } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java index 734ef4184419..84667a51e074 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTest.java @@ -15,7 +15,7 @@ class DubboTest extends AbstractDubboTest { static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); @Override - InstrumentationExtension testing() { + protected InstrumentationExtension testing() { return testing; } } diff --git a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java index 8d55176fbdd6..dab4e6f03150 100644 --- a/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/library-autoconfigure/src/test/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTraceChainTest.java @@ -15,7 +15,7 @@ class DubboTraceChainTest extends AbstractDubboTraceChainTest { static final InstrumentationExtension testing = LibraryInstrumentationExtension.create(); @Override - InstrumentationExtension testing() { + protected InstrumentationExtension testing() { return testing; } } diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 460c2b18af68..32a8bd61a58f 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -14,14 +14,13 @@ 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.Arrays; -import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import org.apache.dubbo.common.utils.NetUtils; @@ -37,14 +36,15 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.RegisterExtension; -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -abstract class AbstractDubboTest { +public abstract class AbstractDubboTest { private final ProtocolConfig protocolConfig = new ProtocolConfig(); - abstract InstrumentationExtension testing(); + protected abstract InstrumentationExtension testing(); + + @RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create(); private DubboBootstrap bootstrap; private DubboBootstrap consumerBootstrap; @@ -63,18 +63,9 @@ static void tearDown() { } @AfterEach - @SuppressWarnings("CatchingUnchecked") public void afterEach() { - List dubboBootstraps = Arrays.asList(bootstrap, consumerBootstrap); - for (DubboBootstrap bootstrap : dubboBootstraps) { - try { - if (bootstrap != null) { - bootstrap.destroy(); - } - } catch (Exception e) { - // ignore - } - } + cleanup.deferCleanup(bootstrap::destroy); + cleanup.deferCleanup(consumerBootstrap::destroy); } ReferenceConfig configureClient(int port) { @@ -95,8 +86,12 @@ ServiceConfig configureServer() { return service; } - @Test @SuppressWarnings({"rawtypes", "unchecked"}) + ReferenceConfig convertReference(ReferenceConfig config) { + return (ReferenceConfig) config; + } + + @Test void testApacheDubboBase() { int port = PortUtils.findOpenPort(); protocolConfig.setPort(port); @@ -110,7 +105,7 @@ void testApacheDubboBase() { // consumer boostrap consumerBootstrap = DubboTestUtil.newDubboBootstrap(); - ReferenceConfig referenceConfig = configureClient(port); + ReferenceConfig referenceConfig = configureClient(port); ProtocolConfig consumerProtocolConfig = new ProtocolConfig(); consumerProtocolConfig.setRegister(false); consumerBootstrap @@ -120,15 +115,15 @@ void testApacheDubboBase() { .start(); // generic call - ReferenceConfig reference = referenceConfig; + ReferenceConfig reference = convertReference(referenceConfig); GenericService genericService = reference.get(); - Object[] o = new Object[1]; - o[0] = "hello"; Object response = runWithSpan( "parent", - () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); + () -> + genericService.$invoke( + "hello", new String[] {String.class.getName()}, new Object[] {"hello"})); assertThat(response).isEqualTo("hello"); testing() @@ -141,7 +136,9 @@ void testApacheDubboBase() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"), @@ -174,7 +171,9 @@ void testApacheDubboBase() { .hasKind(SpanKind.SERVER) .hasParent(trace.getSpan(1)) .hasAttributesSatisfying( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"), @@ -190,7 +189,6 @@ void testApacheDubboBase() { } @Test - @SuppressWarnings({"rawtypes", "unchecked"}) void testApacheDubboTest() throws ExecutionException, InterruptedException { int port = PortUtils.findOpenPort(); protocolConfig.setPort(port); @@ -205,7 +203,7 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { ProtocolConfig consumerProtocolConfig = new ProtocolConfig(); consumerProtocolConfig.setRegister(false); - ReferenceConfig referenceConfig = configureClient(port); + ReferenceConfig referenceConfig = configureClient(port); consumerBootstrap = DubboTestUtil.newDubboBootstrap(); consumerBootstrap .application(new ApplicationConfig("dubbo-demo-async-api-consumer")) @@ -214,14 +212,14 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { .start(); // generic call - ReferenceConfig reference = referenceConfig; + ReferenceConfig reference = convertReference(referenceConfig); GenericService genericService = reference.get(); - Object[] o = new Object[1]; - o[0] = "hello"; CompletableFuture response = runWithSpan( "parent", - () -> genericService.$invokeAsync("hello", new String[] {String.class.getName()}, o)); + () -> + genericService.$invokeAsync( + "hello", new String[] {String.class.getName()}, new Object[] {"hello"})); assertThat(response.get()).isEqualTo("hello"); @@ -235,7 +233,9 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"), @@ -268,7 +268,9 @@ void testApacheDubboTest() throws ExecutionException, InterruptedException { .hasKind(SpanKind.SERVER) .hasParent(trace.getSpan(1)) .hasAttributesSatisfying( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"), diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index b296af04230f..0717ee34051c 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -16,14 +16,13 @@ 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 java.util.Arrays; -import java.util.List; import org.apache.dubbo.common.utils.NetUtils; import org.apache.dubbo.config.ApplicationConfig; import org.apache.dubbo.config.ProtocolConfig; @@ -37,15 +36,16 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.RegisterExtension; -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -abstract class AbstractDubboTraceChainTest { +public abstract class AbstractDubboTraceChainTest { private DubboBootstrap bootstrap; private DubboBootstrap consumerBootstrap; private DubboBootstrap middleBootstrap; + @RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create(); + @BeforeAll static void setUp() throws Exception { System.setProperty("dubbo.application.qos-enable", "false"); @@ -59,22 +59,13 @@ static void tearDown() { System.clearProperty("dubbo.application.qos-enable"); } - abstract InstrumentationExtension testing(); + protected abstract InstrumentationExtension testing(); @AfterEach - @SuppressWarnings("CatchingUnchecked") public void afterEach() { - List dubboBootstraps = - Arrays.asList(bootstrap, consumerBootstrap, middleBootstrap); - for (DubboBootstrap bootstrap : dubboBootstraps) { - try { - if (bootstrap != null) { - bootstrap.destroy(); - } - } catch (Exception e) { - // ignore - } - } + cleanup.deferCleanup(bootstrap::destroy); + cleanup.deferCleanup(consumerBootstrap::destroy); + cleanup.deferCleanup(middleBootstrap::destroy); } ReferenceConfig configureClient(int port) { @@ -122,9 +113,13 @@ ServiceConfig configureMiddleServer( return service; } + @SuppressWarnings({"rawtypes", "unchecked"}) + ReferenceConfig convertReference(ReferenceConfig config) { + return (ReferenceConfig) config; + } + @Test @DisplayName("test that context is propagated correctly in chained dubbo calls") - @SuppressWarnings({"rawtypes", "unchecked"}) void testDubboChain() { int port = PortUtils.findOpenPorts(2); int middlePort = port + 1; @@ -157,7 +152,7 @@ void testDubboChain() { ProtocolConfig consumerProtocolConfig = new ProtocolConfig(); consumerProtocolConfig.setRegister(false); - ReferenceConfig middleReference = configureMiddleClient(middlePort); + ReferenceConfig middleReference = configureMiddleClient(middlePort); consumerBootstrap = DubboTestUtil.newDubboBootstrap(); consumerBootstrap .application(new ApplicationConfig("dubbo-demo-api-consumer")) @@ -165,14 +160,14 @@ void testDubboChain() { .protocol(consumerProtocolConfig) .start(); - GenericService genericService = (GenericService) middleReference.get(); + GenericService genericService = convertReference(middleReference).get(); - Object[] o = new Object[1]; - o[0] = "hello"; Object response = runWithSpan( "parent", - () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); + () -> + genericService.$invoke( + "hello", new String[] {String.class.getName()}, new Object[] {"hello"})); assertThat(response).isEqualTo("hello"); testing() @@ -185,7 +180,9 @@ void testDubboChain() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"), @@ -218,7 +215,9 @@ void testDubboChain() { .hasKind(SpanKind.SERVER) .hasParent(trace.getSpan(1)) .hasAttributesSatisfying( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"), @@ -241,7 +240,9 @@ void testDubboChain() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(2)) .hasAttributesSatisfyingExactly( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"), @@ -274,7 +275,9 @@ void testDubboChain() { .hasKind(SpanKind.SERVER) .hasParent(trace.getSpan(3)) .hasAttributesSatisfying( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.HelloService"), @@ -296,7 +299,6 @@ void testDubboChain() { @Test @DisplayName("test ignore injvm calls") - @SuppressWarnings({"rawtypes", "unchecked"}) void testDubboChainInJvm() { int port = PortUtils.findOpenPorts(2); int middlePort = port + 1; @@ -328,7 +330,7 @@ void testDubboChainInJvm() { ProtocolConfig consumerProtocolConfig = new ProtocolConfig(); consumerProtocolConfig.setRegister(false); - ReferenceConfig middleReference = configureMiddleClient(middlePort); + ReferenceConfig middleReference = configureMiddleClient(middlePort); consumerBootstrap = DubboTestUtil.newDubboBootstrap(); consumerBootstrap .application(new ApplicationConfig("dubbo-demo-api-consumer")) @@ -336,14 +338,14 @@ void testDubboChainInJvm() { .protocol(consumerProtocolConfig) .start(); - GenericService genericService = (GenericService) middleReference.get(); + GenericService genericService = convertReference(middleReference).get(); - Object[] o = new Object[1]; - o[0] = "hello"; Object response = runWithSpan( "parent", - () -> genericService.$invoke("hello", new String[] {String.class.getName()}, o)); + () -> + genericService.$invoke( + "hello", new String[] {String.class.getName()}, new Object[] {"hello"})); assertThat(response).isEqualTo("hello"); testing() @@ -356,7 +358,9 @@ void testDubboChainInJvm() { .hasKind(SpanKind.CLIENT) .hasParent(trace.getSpan(0)) .hasAttributesSatisfyingExactly( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "org.apache.dubbo.rpc.service.GenericService"), @@ -389,7 +393,9 @@ void testDubboChainInJvm() { .hasKind(SpanKind.SERVER) .hasParent(trace.getSpan(1)) .hasAttributesSatisfying( - equalTo(RpcIncubatingAttributes.RPC_SYSTEM, "apache_dubbo"), + equalTo( + RpcIncubatingAttributes.RPC_SYSTEM, + RpcIncubatingAttributes.RpcSystemValues.APACHE_DUBBO), equalTo( RpcIncubatingAttributes.RPC_SERVICE, "io.opentelemetry.instrumentation.apachedubbo.v2_7.api.MiddleService"), From dba165848c7ee9c8e34c985e84695ea031268a5f Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Tue, 3 Sep 2024 20:41:24 +0800 Subject: [PATCH 27/28] fix SuppressWarnings --- .../apachedubbo/v2_7/AbstractDubboTest.java | 5 ++-- .../v2_7/AbstractDubboTraceChainTest.java | 4 ++-- .../apachedubbo/v2_7/DubboTestUtil.java | 24 ++++++------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index 32a8bd61a58f..bbcc1096efd1 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -92,7 +92,7 @@ ReferenceConfig convertReference(ReferenceConfig c } @Test - void testApacheDubboBase() { + void testApacheDubboBase() throws ReflectiveOperationException { int port = PortUtils.findOpenPort(); protocolConfig.setPort(port); // provider boostrap @@ -189,7 +189,8 @@ void testApacheDubboBase() { } @Test - void testApacheDubboTest() throws ExecutionException, InterruptedException { + void testApacheDubboTest() + throws ExecutionException, InterruptedException, ReflectiveOperationException { int port = PortUtils.findOpenPort(); protocolConfig.setPort(port); diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index 0717ee34051c..b02109d30460 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -120,7 +120,7 @@ ReferenceConfig convertReference(ReferenceConfig @Test @DisplayName("test that context is propagated correctly in chained dubbo calls") - void testDubboChain() { + void testDubboChain() throws ReflectiveOperationException { int port = PortUtils.findOpenPorts(2); int middlePort = port + 1; @@ -299,7 +299,7 @@ void testDubboChain() { @Test @DisplayName("test ignore injvm calls") - void testDubboChainInJvm() { + void testDubboChainInJvm() throws ReflectiveOperationException { int port = PortUtils.findOpenPorts(2); int middlePort = port + 1; diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.java index 6c7e72c154bf..1de3cef738ce 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/DubboTestUtil.java @@ -6,7 +6,6 @@ package io.opentelemetry.instrumentation.apachedubbo.v2_7; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.apache.dubbo.config.bootstrap.DubboBootstrap; @@ -26,32 +25,23 @@ static Object newFrameworkModel() { } } - @SuppressWarnings("ThrowSpecificExceptions") - static DubboBootstrap newDubboBootstrap() { + static DubboBootstrap newDubboBootstrap() throws ReflectiveOperationException { Object newFrameworkModel = newFrameworkModel(); - try { - if (newFrameworkModel == null) { - return newDubboBootstrapV27(); - } else { - return newDubboBootstrapV3(newFrameworkModel); - } - } catch (ReflectiveOperationException exception) { - throw new RuntimeException("Error creating new DubboBootstrap instance", exception); + if (newFrameworkModel == null) { + return newDubboBootstrapV27(); + } else { + return newDubboBootstrapV3(newFrameworkModel); } } private static DubboBootstrap newDubboBootstrapV3(Object newFrameworkModel) - throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { + throws ReflectiveOperationException { Method getInstance = DubboBootstrap.class.getDeclaredMethod("newInstance", newFrameworkModel.getClass()); return (DubboBootstrap) getInstance.invoke(null, newFrameworkModel); } - private static DubboBootstrap newDubboBootstrapV27() - throws NoSuchMethodException, - InstantiationException, - IllegalAccessException, - InvocationTargetException { + private static DubboBootstrap newDubboBootstrapV27() throws ReflectiveOperationException { Constructor constructor = DubboBootstrap.class.getDeclaredConstructor(); constructor.setAccessible(true); return constructor.newInstance(); From f29c195b77a6614ad51fa40608b18c61bfd2cbd3 Mon Sep 17 00:00:00 2001 From: "shalk(xiao kun)" Date: Tue, 3 Sep 2024 20:47:29 +0800 Subject: [PATCH 28/28] fix cleanup --- .../apachedubbo/v2_7/AbstractDubboTest.java | 22 +++++--------- .../v2_7/AbstractDubboTraceChainTest.java | 30 ++++++++----------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java index bbcc1096efd1..85ea385128cd 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTest.java @@ -33,7 +33,6 @@ import org.apache.dubbo.rpc.service.GenericService; import org.assertj.core.api.AbstractAssert; import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -46,9 +45,6 @@ public abstract class AbstractDubboTest { @RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create(); - private DubboBootstrap bootstrap; - private DubboBootstrap consumerBootstrap; - @BeforeAll static void setUp() throws Exception { System.setProperty("dubbo.application.qos-enable", "false"); @@ -62,12 +58,6 @@ static void tearDown() { System.clearProperty("dubbo.application.qos-enable"); } - @AfterEach - public void afterEach() { - cleanup.deferCleanup(bootstrap::destroy); - cleanup.deferCleanup(consumerBootstrap::destroy); - } - ReferenceConfig configureClient(int port) { ReferenceConfig reference = new ReferenceConfig<>(); reference.setInterface(HelloService.class); @@ -96,7 +86,8 @@ void testApacheDubboBase() throws ReflectiveOperationException { int port = PortUtils.findOpenPort(); protocolConfig.setPort(port); // provider boostrap - bootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap bootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(bootstrap::destroy); bootstrap .application(new ApplicationConfig("dubbo-test-provider")) .service(configureServer()) @@ -104,7 +95,8 @@ void testApacheDubboBase() throws ReflectiveOperationException { .start(); // consumer boostrap - consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(consumerBootstrap::destroy); ReferenceConfig referenceConfig = configureClient(port); ProtocolConfig consumerProtocolConfig = new ProtocolConfig(); consumerProtocolConfig.setRegister(false); @@ -194,7 +186,8 @@ void testApacheDubboTest() int port = PortUtils.findOpenPort(); protocolConfig.setPort(port); - bootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap bootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(bootstrap::destroy); bootstrap .application(new ApplicationConfig("dubbo-test-async-provider")) .service(configureServer()) @@ -205,7 +198,8 @@ void testApacheDubboTest() consumerProtocolConfig.setRegister(false); ReferenceConfig referenceConfig = configureClient(port); - consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(consumerBootstrap::destroy); consumerBootstrap .application(new ApplicationConfig("dubbo-demo-async-api-consumer")) .reference(referenceConfig) diff --git a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java index b02109d30460..4f90694b49f8 100644 --- a/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java +++ b/instrumentation/apache-dubbo-2.7/testing/src/main/java/io/opentelemetry/instrumentation/apachedubbo/v2_7/AbstractDubboTraceChainTest.java @@ -32,7 +32,6 @@ 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.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -40,10 +39,6 @@ public abstract class AbstractDubboTraceChainTest { - private DubboBootstrap bootstrap; - private DubboBootstrap consumerBootstrap; - private DubboBootstrap middleBootstrap; - @RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create(); @BeforeAll @@ -61,13 +56,6 @@ static void tearDown() { protected abstract InstrumentationExtension testing(); - @AfterEach - public void afterEach() { - cleanup.deferCleanup(bootstrap::destroy); - cleanup.deferCleanup(consumerBootstrap::destroy); - cleanup.deferCleanup(middleBootstrap::destroy); - } - ReferenceConfig configureClient(int port) { ReferenceConfig reference = new ReferenceConfig<>(); reference.setInterface(HelloService.class); @@ -128,7 +116,8 @@ void testDubboChain() throws ReflectiveOperationException { ProtocolConfig protocolConfig = new ProtocolConfig(); protocolConfig.setPort(port); - bootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap bootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(bootstrap::destroy); bootstrap .application(new ApplicationConfig("dubbo-test-provider")) .service(configureServer()) @@ -140,7 +129,8 @@ void testDubboChain() throws ReflectiveOperationException { middleProtocolConfig.setPort(middlePort); ReferenceConfig clientReference = configureClient(port); - middleBootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap middleBootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(middleBootstrap::destroy); middleBootstrap .application(new ApplicationConfig("dubbo-demo-middle")) .reference(clientReference) @@ -153,7 +143,8 @@ void testDubboChain() throws ReflectiveOperationException { consumerProtocolConfig.setRegister(false); ReferenceConfig middleReference = configureMiddleClient(middlePort); - consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(consumerBootstrap::destroy); consumerBootstrap .application(new ApplicationConfig("dubbo-demo-api-consumer")) .reference(middleReference) @@ -307,7 +298,8 @@ void testDubboChainInJvm() throws ReflectiveOperationException { ProtocolConfig protocolConfig = new ProtocolConfig(); protocolConfig.setPort(port); - bootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap bootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(bootstrap::destroy); bootstrap .application(new ApplicationConfig("dubbo-test-provider")) .service(configureServer()) @@ -319,7 +311,8 @@ void testDubboChainInJvm() throws ReflectiveOperationException { middleProtocolConfig.setPort(middlePort); ReferenceConfig clientReference = configureLocalClient(port); - middleBootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap middleBootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(middleBootstrap::destroy); middleBootstrap .application(new ApplicationConfig("dubbo-demo-middle")) .service(configureMiddleServer(clientReference)) @@ -331,7 +324,8 @@ void testDubboChainInJvm() throws ReflectiveOperationException { consumerProtocolConfig.setRegister(false); ReferenceConfig middleReference = configureMiddleClient(middlePort); - consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + DubboBootstrap consumerBootstrap = DubboTestUtil.newDubboBootstrap(); + cleanup.deferCleanup(consumerBootstrap::destroy); consumerBootstrap .application(new ApplicationConfig("dubbo-demo-api-consumer")) .reference(middleReference)