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

Run muzzle check against OpenTelemetry API instrumentation (bridge) #4797

Merged
merged 5 commits into from
Dec 6, 2021
Merged
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
3 changes: 3 additions & 0 deletions gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ apply(from = "../version.gradle.kts")

repositories {
mavenCentral()
gradlePluginPortal()
}

val bbGradlePlugin by configurations.creating
Expand All @@ -33,6 +34,8 @@ dependencies {
implementation("org.eclipse.aether:aether-transport-http:1.1.0")
implementation("org.apache.maven:maven-aether-provider:3.3.9")

implementation("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:7.0.0")

testImplementation("org.assertj:assertj-core:3.19.0")

testImplementation(enforcedPlatform("org.junit:junit-bom:5.7.2"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import io.opentelemetry.javaagent.muzzle.AcceptableVersions
import io.opentelemetry.javaagent.muzzle.MuzzleDirective
import io.opentelemetry.javaagent.muzzle.MuzzleExtension
Expand All @@ -27,6 +28,8 @@ import java.util.stream.StreamSupport

plugins {
`java-library`

id("io.opentelemetry.instrumentation.javaagent-shadowing")
}

// Select a random set of versions to test
Expand All @@ -38,14 +41,37 @@ val muzzleTooling: Configuration by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
}

val muzzleBootstrap: Configuration by configurations.creating {
isCanBeConsumed = false
isCanBeResolved = true
}

val shadowModule by tasks.registering(ShadowJar::class) {
from(tasks.jar)

configurations = listOf(project.configurations.runtimeClasspath.get())
Copy link
Contributor

Choose a reason for hiding this comment

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

this is default, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

defaults are only applied to the default "shadowJar" task, see GradleUp/shadow#108 (comment)


archiveFileName.set("module-for-muzzle-check.jar")

dependsOn(tasks.jar)
}

val shadowMuzzleTooling by tasks.registering(ShadowJar::class) {
configurations = listOf(muzzleTooling)

archiveFileName.set("tooling-for-muzzle-check.jar")
}

val shadowMuzzleBootstrap by tasks.registering(ShadowJar::class) {
configurations = listOf(muzzleBootstrap)

archiveFileName.set("bootstrap-for-muzzle-check.jar")
}

val compileMuzzle by tasks.registering {
dependsOn(muzzleBootstrap)
dependsOn(muzzleTooling)
dependsOn(shadowMuzzleBootstrap)
dependsOn(shadowMuzzleTooling)
dependsOn(tasks.named("classes"))
}

Expand All @@ -59,6 +85,7 @@ tasks.register("printMuzzleReferences") {
group = "Muzzle"
description = "Print references created by instrumentation muzzle"
dependsOn(compileMuzzle)
dependsOn(shadowModule)
doLast {
val instrumentationCL = createInstrumentationClassloader()
withContextClassLoader(instrumentationCL) {
Expand Down Expand Up @@ -126,8 +153,9 @@ if (hasRelevantTask) {

fun createInstrumentationClassloader(): ClassLoader {
logger.info("Creating instrumentation class loader for: $path")
val runtimeClasspath = sourceSets.main.get().runtimeClasspath
return classpathLoader(runtimeClasspath + muzzleTooling, ClassLoader.getPlatformClassLoader())
val muzzleShadowJar = shadowModule.get().archiveFile.get()
val muzzleToolingShadowJar = shadowMuzzleTooling.get().archiveFile.get()
return classpathLoader(files(muzzleShadowJar, muzzleToolingShadowJar), ClassLoader.getPlatformClassLoader())
}

fun classpathLoader(classpath: FileCollection, parent: ClassLoader): ClassLoader {
Expand Down Expand Up @@ -214,6 +242,7 @@ fun addMuzzleTask(muzzleDirective: MuzzleDirective, versionArtifact: Artifact?,

val muzzleTask = tasks.register(taskName) {
dependsOn(configurations.named("runtimeClasspath"))
dependsOn(shadowModule)
doLast {
val instrumentationCL = createInstrumentationClassloader()
val userCL = createClassLoaderForTask(config)
Expand All @@ -238,7 +267,8 @@ fun addMuzzleTask(muzzleDirective: MuzzleDirective, versionArtifact: Artifact?,

fun createClassLoaderForTask(muzzleTaskConfiguration: Configuration): ClassLoader {
logger.info("Creating user classloader for muzzle check")
return classpathLoader(muzzleTaskConfiguration + muzzleBootstrap, ClassLoader.getPlatformClassLoader())
val muzzleBootstrapShadowJar = shadowMuzzleBootstrap.get().archiveFile.get()
return classpathLoader(muzzleTaskConfiguration + files(muzzleBootstrapShadowJar), ClassLoader.getPlatformClassLoader())
}

fun inverseOf(muzzleDirective: MuzzleDirective, system: RepositorySystem, session: RepositorySystemSession): Set<MuzzleDirective> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ plugins {
id("otel.javaagent-instrumentation")
}

// TODO: add muzzle once 1.4.0 is released
muzzle {
pass {
group.set("io.opentelemetry")
module.set("opentelemetry-extension-annotations")
versions.set("[0.16.0,)")
skip("0.13.0") // opentelemetry-api has a bad dependency on non-alpha api-metric 0.13.0
assertInverse.set(true)
}
}

val versions: Map<String, String> by project

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@ plugins {
id("otel.javaagent-instrumentation")
}

// TODO: add muzzle once 1.4.0 is released
muzzle {
pass {
group.set("io.opentelemetry")
module.set("opentelemetry-api")
versions.set("[0.17.0,)")
skip("0.13.0") // has a bad dependency on non-alpha api-metric 0.13.0
skip("0.9.0") // has no pom file in maven central
assertInverse.set(true)
}
}

dependencies {
// this instrumentation needs to be able to reference both the OpenTelemetry API
Expand Down