-
Notifications
You must be signed in to change notification settings - Fork 873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Nacos Client (#9961) #12849
base: main
Are you sure you want to change the base?
Conversation
- Improved code formatting - Enhanced muzzle validation - Managed dependency versions
docs/supported-libraries.md
Outdated
@@ -101,6 +101,7 @@ These are the supported libraries and frameworks: | |||
| [Micrometer](https://micrometer.io/) | 1.5+ | [opentelemetry-micrometer-1.5](../instrumentation/micrometer/micrometer-1.5/library) | none | | |||
| [MongoDB Driver](https://mongodb.github.io/mongo-java-driver/) | 3.1+ | [opentelemetry-mongo-3.1](../instrumentation/mongo/mongo-3.1/library) | [Database Client Spans] | | |||
| [MyBatis](https://mybatis.org/mybatis-3/) | 3.2+ | N/A | none | | |||
| [Nacos](https://nacos.io/) | 2.0.3+ | N/A | none | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use Nacos Client
since the instrumentation is for the client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will make changes here.
} | ||
|
||
dependencies { | ||
val nacosClientVersion = "2.0.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we don't use a separate variable for the instrumented library version, since this is used only in 1 place you could inline it
why are you suing 2.0.3
, as far as I can tell tests pass with 2.0.0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version 2.0.3 was chosen because I referred to the requirements described in issue #9961. However, after testing, I found that version 2.0.0 also works. I will make changes here.
|
||
dependencies { | ||
val nacosClientVersion = "2.0.3" | ||
implementation("com.alibaba.nacos:nacos-client:$nacosClientVersion") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implementation
may not be used here. implementation
dependencies are bundled inside the agent jar which is not desired. Usually we use library
that is our custom scope that means compileOnly
+ testImplementation
. library
also supports running tests with the latest version of the library with -PtestLatestDeps=true
(currently tests don't compile with the latest version, you can use latestDepTestLibrary
to limit the latest version or you could define tests suites)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will make changes here.
tasks.withType<Test>().configureEach { | ||
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED") | ||
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this really needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will make changes here.
|
||
@Override | ||
public List<TypeInstrumentation> typeInstrumentations() { | ||
return Arrays.asList(new GrpcConnectionInstrumentation(), new RpcClientInstrumentation()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we static import Arrays.asList
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will make changes here.
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isMethod().and(isPublic()).and(namedOneOf("request")).and(returns(Response.class)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we use named
instead of namedOneOf
when there is only one name
don't use returns(Response.class)
, use returns(named("com.alibaba.nacos.api.remote.response.Response"))
. This way you don't need to bundle the Response
class inside the agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will make changes here.
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isMethod().and(isPublic()).and(namedOneOf("request")).and(returns(Response.class)), | ||
GrpcConnectionRequestAdvice.class.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually we have advice classes as inner classes and here use this.getClass() + "$GrpcConnectionRequestAdvice"
. We avoid using the full class name to avoid loading the advice class when the advice is added, this way we can use the types from instrumented library inside the advice class without bundling the instrumented library inside the agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will make changes here.
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.alibaba.nacos.common.remote.client; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually we place test classes in the same package as the instrumentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this because com.alibaba.nacos.common.remote.client.RpcClient#handleServerRequest
is a protected
method. Is there a better way to handle this here?
public void handleServerRequestSuccessResponse() { | ||
when(serverRequestHandler.requestReply(any(Request.class))) | ||
.thenReturn(NacosClientTestHelper.SUCCESS_RESPONSE); | ||
for (Request request : nacosClientRequestList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when we need to run the same test with different arguments we use @ParameterizedTest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will make changes here.
@Target(TYPE) | ||
@Retention(RUNTIME) | ||
@Documented | ||
public @interface DoNotMock { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this used anywhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class added here is to resolve a test compilation error in the nacos-client
version 2.0.3 jar:
Compilation failed; see the compiler output below.
Error: Warning found, but specified -Werror
G:\temp.gradle\caches\modules-2\files-2.1\com.alibaba.nacos\nacos-client\2.0.3\a73c03b466a1f1565ee2b0e459c43046d6c8c15b\nacos-client-2.0.3.jar(/com/alibaba/nacos/shaded/com/google/common/util/concurrent/ListenableFuture.class): Warning: Unable to find class 'DoNotMock' annotation method 'value()': Can't find it com.alibaba.nacos.shaded.com.google.errorprone.annotations.DoNotMock class file.
This issue can be reproduced by removing the class file DoNotMock
and then running ./gradlew :instrumentation:nacos-client-2.0.0:javaagent:test -PtestLatestDeps=true
.
- Updated version to support Nacos client version 2.0.0 - Default the plugin to be disabled
Enhancement Methods
com.alibaba.nacos.common.remote.client.grpc.GrpcConnection#request
com.alibaba.nacos.common.remote.client.RpcClient#handleServerRequest
Enable Configuration
otel.instrumentation.nacos-client.default-enabled
false
Span Info Details