Skip to content

Conversation

AlexeyKuznetsov-DD
Copy link
Contributor

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD commented Aug 22, 2025

What Does This Do

Added script that will collect thread and heap dumps in case test timeout on CI.

Motivation

Green CI.

Additional Notes

Script will schedule taking thread and heap dump at test_timout_minus_2_minutes.
Dumps will be collected and stored as part of test GitLab Job artifact.

# Conflicts:
#	dd-java-agent/instrumentation/java-concurrent/java-concurrent-21/src/previewTest/groovy/StructuredConcurrencyTest.groovy
#	dd-java-agent/instrumentation/lettuce-4/src/test/groovy/Lettuce4ClientTestBase.groovy
@AlexeyKuznetsov-DD AlexeyKuznetsov-DD marked this pull request as ready for review September 10, 2025 20:44
@AlexeyKuznetsov-DD AlexeyKuznetsov-DD requested review from a team as code owners September 10, 2025 20:44
@AlexeyKuznetsov-DD AlexeyKuznetsov-DD requested review from PerfectSlayer and removed request for a team September 10, 2025 20:44
Copy link
Contributor

github-actions bot commented Sep 10, 2025

Hi! 👋 Thanks for your pull request! 🎉

To help us review it, please make sure to:

  • Add at least one type, and one component or instrumentation label to the pull request

If you need help, please check our contributing guidelines.

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD removed the tag: do not merge Do not merge changes label Sep 10, 2025
@AlexeyKuznetsov-DD AlexeyKuznetsov-DD changed the title Attempt to catch dump via Gradle Added script that will collect thread and heap dumps in case test timeout on CI. Sep 10, 2025
Copy link
Contributor

@amarziali amarziali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks that's really useful

@AlexeyKuznetsov-DD AlexeyKuznetsov-DD added type: enhancement Enhancements and improvements tag: no release notes Changes to exclude from release notes labels Sep 11, 2025
Copy link
Contributor

@bric3 bric3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok for me.

On a side note, I would prefer to see such features as convention plugins, and written in kotlin.

// Schedule thread and heap dumps collection near test timeout.
tasks.withType(Test).configureEach {
doFirst {
def isCI = System.getenv('CI') != null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This if ok, but you might prefer providers.environmentVariable("CI")

Comment on lines +10 to +14
String buildDir = layout.buildDirectory.asFile.get().absolutePath
if (isCI) {
// Move reports into the folder collected by the collect_reports.sh script.
buildDir = buildDir.replace('dd-trace-java/dd-java-agent', 'dd-trace-java/workspace/dd-java-agent')
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This is also fine, but prefer provider mappers, something like

Suggested change
String buildDir = layout.buildDirectory.asFile.get().absolutePath
if (isCI) {
// Move reports into the folder collected by the collect_reports.sh script.
buildDir = buildDir.replace('dd-trace-java/dd-java-agent', 'dd-trace-java/workspace/dd-java-agent')
}
def buildDir = layout.buildDirectory.asFile.map {
if (!isCI) {
// Move reports into the folder collected by the collect_reports.sh script.
it.absolutePath.replace('dd-trace-java/dd-java-agent', 'dd-trace-java/workspace/dd-java-agent')
} else {
it.asbsolutePath
}
}

Also, might be worth making dd-trace-java/workspace/dd-java-agent an explicit variable or constant.

Comment on lines +22 to +24
// Calculate delay for taking dumps as test timeout minus 2 minutes, but no less than 5 minutes.
def delay = timeout.get().minusMinutes(2)
long delayMinutes = Math.max(5L, delay.toMinutes())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: long startDelayMinutes, maybe also delay to delayMinutes

// Only process 'Gradle test executors'.
if (!line.contains('Gradle Test Executor')) return

def pid = line.substring(0, line.indexOf(' '))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polish: indentation

Suggested change
def pid = line.substring(0, line.indexOf(' '))
def pid = line.substring(0, line.indexOf(' '))

def pid = line.substring(0, line.indexOf(' '))

// Collect thread dump.
def threadDumpFile = new File(dumpDir, "${pid}-thread-dump-${System.currentTimeMillis()}.log")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Might be worth adding the path of the task, testTask.getPath(), which might return something like :dd-java-agent:instrumentation:mule-4:test, so it probably needs some cleaning to be used as a filename.

Comment on lines +57 to +59
finally {
scheduler.shutdown()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: This task stops after gathering a single thread dump by processes. I wonder if it would be useful to collect a sequence of thread dumps every X ms.

@@ -126,7 +128,7 @@ if (!project.property("activePartition")) {
}
}

tasks.withType(Test) {
tasks.withType(Test).configureEach {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Good fix !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: testing Testing tag: no release notes Changes to exclude from release notes type: enhancement Enhancements and improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants