Skip to content
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

Send coverage on jvm shutdown event #166

Open
wants to merge 3 commits into
base: merge/v0.9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions java-agent/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,20 @@ kotlin {
val jvmMainCompilation = kotlin.targets.withType<KotlinJvmTarget>()["jvm"].compilations["main"]
val relocatePackages = setOf(
"javax.validation",
"javax.websocket",
"javassist",
"ch.qos.logback",
"io.aesy.datasize",
"com.alibaba",
"org.slf4j",
"org.jacoco",
"org.objectweb.asm",
"org.apache.bcel",
"org.apache.commons",
"org.apache.hc",
"org.apache",
"org.eclipse.jetty",
"org.intellij.lang.annotations",
"org.jetbrains.annotations",
"org.petitparser",
"net.bytebuddy"
"net.bytebuddy",
"mu",
)
val runtimeJar by registering(ShadowJar::class) {
mergeServiceFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ class Test2Code(
logger.info { "load: Waiting for transport availability for class metadata scanning" }
thread {
scanAndSendMetadataClasses()
coverageSender.startSendingCoverage()
}
coverageSender.startSendingCoverage()
Runtime.getRuntime().addShutdownHook(Thread { coverageSender.stopSendingCoverage() })
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class IntervalCoverageSender(

override fun stopSendingCoverage() {
scheduledThreadPool.shutdown()
if (!scheduledThreadPool.awaitTermination(5, TimeUnit.SECONDS)) {
Copy link
Member

Choose a reason for hiding this comment

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

I assume awaitTermination is required to have enough time to send coverage data.
I suggest to

        if (!scheduledThreadPool.awaitTermination(5, TimeUnit.SECONDS)) {
          logger.error("Failed to send some coverage data prior to shutdown") // signal to user that some coverage data is lost
          scheduledThreadPool.shutdownNow();
        }

If we'll get that error message a lot - we could investigate + make termination timeout configurable.

logger.error("Failed to send some coverage data prior to shutdown")
scheduledThreadPool.shutdownNow();
}
sendProbes(collectProbes())
logger.debug { "Coverage sending job is stopped." }
}

Expand Down