-
Notifications
You must be signed in to change notification settings - Fork 303
Fix Gradle Launcher instrumentation to not interfere with Gradle Test Kit #8465
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
Merged
nikita-tkachenko-datadog
merged 8 commits into
master
from
nikita-tkachenko/gradle-test-kit-fix
Feb 28, 2025
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
19ad3f2
Fix Gradle Launcher instrumentation to not interfere with Gradle Test…
nikita-tkachenko-datadog dce601d
Fix smoke test
nikita-tkachenko-datadog ec50d69
Disable Git client in smoke tests
nikita-tkachenko-datadog 21e18e9
Add some debug logging
nikita-tkachenko-datadog 69b6d91
Fix code formatting
nikita-tkachenko-datadog d271acd
Fix typo
nikita-tkachenko-datadog 687cdff
Do not disable Git client
nikita-tkachenko-datadog 0ba5cb2
Fix the smoke test to report the same spans in CI and locally
nikita-tkachenko-datadog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...n/groovy/datadog/trace/instrumentation/gradle/GradleServiceValidationInstrumentation.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package datadog.trace.instrumentation.gradle; | ||
|
||
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import datadog.trace.agent.tooling.InstrumenterModule; | ||
import datadog.trace.api.Config; | ||
import java.util.Set; | ||
import net.bytebuddy.asm.Advice; | ||
|
||
/** | ||
* We inject {@link CiVisibilityGradleListener} into Gradle and register it with {@code | ||
* Scope.Build.class} scope. | ||
* | ||
* <p>A class named {@code org.gradle.internal.service.ServiceScopeValidator} checks that every | ||
* service registered with a scope is annotated with {@code @ServiceScope(<ScopeClass>.class)}. | ||
* | ||
* <p>We cannot annotate our service, as {@code Scope.Build.class} is a recent addition: we need to | ||
* support older Gradle versions, besides this class is absent in the Gradle API version that the | ||
* tracer currently uses. | ||
* | ||
* <p>To suppress validation for our service we patch a "workaround" class that is used internally | ||
* by Gradle. | ||
*/ | ||
@AutoService(InstrumenterModule.class) | ||
public class GradleServiceValidationInstrumentation extends InstrumenterModule.CiVisibility | ||
implements Instrumenter.ForSingleType, Instrumenter.HasMethodAdvice { | ||
|
||
public GradleServiceValidationInstrumentation() { | ||
super("gradle", "gradle-build-scope-services"); | ||
} | ||
|
||
@Override | ||
public String instrumentedType() { | ||
return "org.gradle.internal.service.ServiceScopeValidatorWorkarounds"; | ||
} | ||
|
||
@Override | ||
public boolean isApplicable(Set<TargetSystem> enabledSystems) { | ||
return super.isApplicable(enabledSystems) | ||
&& Config.get().isCiVisibilityBuildInstrumentationEnabled(); | ||
} | ||
|
||
@Override | ||
public void methodAdvice(MethodTransformer transformer) { | ||
transformer.applyAdvice( | ||
named("shouldSuppressValidation").and(takesArgument(0, Class.class)), | ||
getClass().getName() + "$SuppressValidation"); | ||
} | ||
|
||
public static class SuppressValidation { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void suppressValidationForCiVisService( | ||
@Advice.Argument(0) final Class<?> validatedClass, | ||
@Advice.Return(readOnly = false) boolean suppressValidation) { | ||
if (validatedClass.getName().endsWith("CiVisibilityGradleListener")) { | ||
suppressValidation = true; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
dd-smoke-tests/gradle/src/test/resources/test-succeed-gradle-plugin-test/build.gradleTest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id 'java' | ||
id 'java-gradle-plugin' | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
mySimplePlugin { | ||
id = 'datadog.smoke.helloplugin' | ||
implementationClass = 'datadog.smoke.HelloPlugin' | ||
} | ||
} | ||
} | ||
|
||
repositories { | ||
mavenLocal() | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
testImplementation gradleTestKit() | ||
|
||
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.2' | ||
} | ||
|
||
tasks.withType(Test).configureEach { | ||
useJUnitPlatform() | ||
} |
9 changes: 9 additions & 0 deletions
9
dd-smoke-tests/gradle/src/test/resources/test-succeed-gradle-plugin-test/coverages.ftl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ { | ||
"files" : [ { | ||
"bitmap" : "AAAAx98=", | ||
"filename" : "src/test/java/datadog/smoke/HelloPluginFunctionalTest.java" | ||
} ], | ||
"span_id" : ${content_span_id_4}, | ||
"test_session_id" : ${content_test_session_id}, | ||
"test_suite_id" : ${content_test_suite_id} | ||
} ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Just leaving a comment here to check if this is for testing purposes in CI
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.
Yeah, I've added this to debug a failure that only happened in CI and not locally.
The thing is that when the tests are run in an IDE, the
AssertionFailedError
message contains the diffs, which is very convenient for debugging, but when running in CI, the diffs are not printed.So I'll leave these logs in place with an
if (ciRun)
condition.