Skip to content
Merged
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
107 changes: 56 additions & 51 deletions gcp-auth-extension/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,64 @@ dependencies {
agent("io.opentelemetry.javaagent:opentelemetry-javaagent")
}

tasks {
test {
useJUnitPlatform()
// Unset relevant environment variables to provide a clean state for the tests
environment("GOOGLE_CLOUD_PROJECT", "")
environment("GOOGLE_CLOUD_QUOTA_PROJECT", "")
// exclude integration test
exclude("io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class")
testing {
suites {
val test by getting(JvmTestSuite::class) {
targets.all {
testTask.configure {
// Unset relevant environment variables to provide a clean state for the tests
environment("GOOGLE_CLOUD_PROJECT", "")
environment("GOOGLE_CLOUD_QUOTA_PROJECT", "")
// exclude integration test
exclude("io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class")
}
}
}

val integrationTestUserCreds by registering(JvmTestSuite::class) {
dependencies {
implementation(project())
}

targets.all {
testTask.configure {
dependsOn(tasks.shadowJar)

// include only the integration test file
include("io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class")

val fakeCredsFilePath = project.file("src/test/resources/fake_user_creds.json").absolutePath

environment("GOOGLE_CLOUD_QUOTA_PROJECT", "quota-project-id")
environment("GOOGLE_APPLICATION_CREDENTIALS", fakeCredsFilePath)

val agentJar = configurations.named("agent").map { it.singleFile.absolutePath }
val extensionJarPath = tasks.shadowJar.flatMap { it.archiveFile }.map { it.asFile.absolutePath }

jvmArgumentProviders.add(CommandLineArgumentProvider {
listOf(
"-javaagent:${agentJar.get()}",
"-Dotel.javaagent.extensions=${extensionJarPath.get()}",
"-Dgoogle.cloud.project=my-gcp-project",
"-Dotel.java.global-autoconfigure.enabled=true",
"-Dotel.exporter.otlp.endpoint=http://localhost:4318",
"-Dotel.resource.providers.gcp.enabled=true",
"-Dotel.traces.exporter=otlp",
"-Dotel.bsp.schedule.delay=2000",
"-Dotel.metrics.exporter=none",
"-Dotel.logs.exporter=none",
"-Dotel.exporter.otlp.protocol=http/protobuf",
"-Dotel.javaagent.debug=false",
"-Dmockserver.logLevel=trace"
)
})
}
}
}
}
}

tasks {
shadowJar {
/**
* Shaded version of this extension is required when using it as a OpenTelemetry Java Agent
Expand Down Expand Up @@ -90,46 +138,3 @@ tasks {
dependsOn(shadowJar)
}
}

val builtLibsDir = layout.buildDirectory.dir("libs").get().asFile.absolutePath
val javaAgentJarPath = "$builtLibsDir/otel-agent.jar"
val authExtensionJarPath = "${tasks.shadowJar.get().archiveFile.get()}"

tasks.register<Copy>("copyAgent") {
into(layout.buildDirectory.dir("libs"))
from(configurations.named("agent") {
rename("opentelemetry-javaagent(.*).jar", "otel-agent.jar")
})
}

tasks.register<Test>("IntegrationTestUserCreds") {
Copy link
Member Author

Choose a reason for hiding this comment

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

noticed that this test wasn't running in the build, but fixing in different PR: #2344

testClassesDirs = sourceSets.test.get().output.classesDirs
classpath = sourceSets.test.get().runtimeClasspath

dependsOn(tasks.shadowJar)
dependsOn(tasks.named("copyAgent"))

useJUnitPlatform()
// include only the integration test file
include("io/opentelemetry/contrib/gcp/auth/GcpAuthExtensionEndToEndTest.class")

val fakeCredsFilePath = project.file("src/test/resources/fake_user_creds.json").absolutePath

environment("GOOGLE_CLOUD_QUOTA_PROJECT", "quota-project-id")
environment("GOOGLE_APPLICATION_CREDENTIALS", fakeCredsFilePath)
jvmArgs = listOf(
"-javaagent:$javaAgentJarPath",
"-Dotel.javaagent.extensions=$authExtensionJarPath",
"-Dgoogle.cloud.project=my-gcp-project",
"-Dotel.java.global-autoconfigure.enabled=true",
"-Dotel.exporter.otlp.endpoint=http://localhost:4318",
"-Dotel.resource.providers.gcp.enabled=true",
"-Dotel.traces.exporter=otlp",
"-Dotel.bsp.schedule.delay=2000",
"-Dotel.metrics.exporter=none",
"-Dotel.logs.exporter=none",
"-Dotel.exporter.otlp.protocol=http/protobuf",
"-Dotel.javaagent.debug=false",
"-Dmockserver.logLevel=trace"
)
}