Skip to content

Commit

Permalink
Create abstraction for library dependencies for instrumentation. (#977)
Browse files Browse the repository at this point in the history
* Create abstraction for library dependencies for instrumentation.

Co-authored-by: Trask Stalnaker <[email protected]>

Co-authored-by: Trask Stalnaker <[email protected]>
  • Loading branch information
Anuraag Agrawal and trask authored Aug 18, 2020
1 parent 6df6e6f commit bbfdbb3
Show file tree
Hide file tree
Showing 78 changed files with 336 additions and 905 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:
S3_BUILD_CACHE_ACCESS_KEY_ID: ${{ secrets.S3_BUILD_CACHE_ACCESS_KEY_ID }}
S3_BUILD_CACHE_SECRET_KEY: ${{ secrets.S3_BUILD_CACHE_SECRET_KEY }}
with:
command: ./gradlew latestDepTest --stacktrace
command: ./gradlew test -PtestLatestDeps=true --stacktrace
timeout_minutes: 60
max_attempts: 3

Expand Down
76 changes: 76 additions & 0 deletions gradle/instrumentation-common.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/** Common setup for manual instrumentation of libraries and auto instrumentation. */


/**
* We define three dependency configurations to use when adding dependencies to libraries being
* instrumented.
*
* - library: A dependency on the instrumented library. Results in the dependency being added to
* compileOnly and testImplementation. If the build is run with -PtestLatestDeps=true, the
* version when added to testImplementation will be overridden by `+`, the latest version
* possible. For simple libraries without different behavior between versions, it is possible
* to have a single dependency on library only.
*
* - testLibrary: A dependency on a library for testing. This will usually be used to either
* a) use a different version of the library for compilation and testing and b) to add a helper
* that is only required for tests (e.g., library-testing artifact). The dependency will be
* added to testImplementation and will have a version of `+` when testing latest deps as
* described above.
*
* - latestDepTestLibrary: A dependency on a library for testing when testing of latest dependency
* version is enabled. This dependency will be added as-is to testImplementation, but only if
* -PtestLatestDeps=true. The version will not be modified but it will be given highest
* precedence. Use this to restrict the latest version dependency from the default `+`, for
* example to restrict to just a major version by specifying `2.+`.
*/

ext.testLatestDeps = findProperty('testLatestDeps')
configurations {
// library is where to define dependencies on the library that is being instrumented. It will not
// be packaged in the agent but will be available at runtime for tests.
library {
canBeResolved = false
canBeConsumed = false
}
testLibrary {
canBeResolved = false
canBeConsumed = false
}
latestDepTestLibrary {
canBeResolved = false
canBeConsumed = false
}
[library, testLibrary].each {configuration ->
// We use whenObjectAdded and copy into the real configurations instead of extension to allow
// mutating the version for latest dep tests.
configuration.dependencies.whenObjectAdded {
def dep = it.copy()
if (testLatestDeps) {
dep.version {
it.require '+'
}
}
testImplementation.dependencies.add(dep)
}
}
if (testLatestDeps) {
latestDepTestLibrary.dependencies.whenObjectAdded {
def dep = it.copy()
def declaredVersion = dep.version
dep.version {
it.strictly declaredVersion
}
testImplementation.dependencies.add(dep)
}
}
compileOnly.extendsFrom(library)
}

if (testLatestDeps) {
afterEvaluate {
def latestDepTest = tasks.findByName('latestDepTest')
if (latestDepTest) {
tasks.test.dependsOn latestDepTest
}
}
}
1 change: 1 addition & 0 deletions gradle/instrumentation-library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ group = 'io.opentelemetry.instrumentation'

apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/publish.gradle"
apply from: "$rootDir/gradle/instrumentation-common.gradle"

archivesBaseName = projectDir.parentFile.name

Expand Down
2 changes: 2 additions & 0 deletions gradle/instrumentation.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ if (project.ext.find("skipPublish") != true) {
apply from: "$rootDir/gradle/publish.gradle"
}

apply from: "$rootDir/gradle/instrumentation-common.gradle"

afterEvaluate {
byteBuddy {
transformation {
Expand Down
22 changes: 4 additions & 18 deletions instrumentation-core/reactor-3.1/reactor-3.1.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,12 @@ ext {

group = 'io.opentelemetry.instrumentation'

apply from: "$rootDir/gradle/java.gradle"
apply from: "$rootDir/gradle/publish.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

testSets {
latestDepTest {
dirName = 'test'
}
}
apply from: "$rootDir/gradle/instrumentation-library.gradle"

dependencies {
compileOnly group: 'io.projectreactor', name: 'reactor-core', version: '3.1.0.RELEASE'

implementation deps.opentelemetryApi

testImplementation project(':testing-common')

testImplementation group: 'io.projectreactor', name: 'reactor-core', version: '3.1.0.RELEASE'
library group: 'io.projectreactor', name: 'reactor-core', version: '3.1.0.RELEASE'

latestDepTestImplementation group: 'io.projectreactor', name: 'reactor-core', version: '3.+'
latestDepTestLibrary group: 'io.projectreactor', name: 'reactor-core', version: '3.+'
// Looks like later versions on reactor need this dependency for some reason even though it is marked as optional.
latestDepTestImplementation group: 'io.micrometer', name: 'micrometer-core', version: '1.+'
latestDepTestLibrary group: 'io.micrometer', name: 'micrometer-core', version: '1.+'
}
17 changes: 2 additions & 15 deletions instrumentation/akka-http-10.0/akka-http-10.0.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ testSets {
version101Test {
dirName = 'test'
}

latestDepTest {
dirName = 'test'
}
}

compileLagomTestJava {
Expand All @@ -29,7 +25,6 @@ compileLagomTestGroovy {
targetCompatibility = 1.8
}


muzzle {
pass {
group = 'com.typesafe.akka'
Expand Down Expand Up @@ -70,13 +65,13 @@ muzzle {
}

dependencies {
compileOnly group: 'com.typesafe.akka', name: 'akka-http_2.11', version: '10.0.0'
library group: 'com.typesafe.akka', name: 'akka-http_2.11', version: '10.0.0'
library group: 'com.typesafe.akka', name: 'akka-stream_2.11', version: '2.4.14'

implementation project(':javaagent-tooling')
implementation deps.autoservice
annotationProcessor deps.autoservice

testImplementation group: 'com.typesafe.akka', name: 'akka-http_2.11', version: '10.0.0'
testImplementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.6.0'

lagomTestImplementation project(':instrumentation:akka-http-10.0')
Expand All @@ -86,9 +81,6 @@ dependencies {
// There are some internal API changes in 10.1 that we would like to test separately for
version101TestImplementation group: 'com.typesafe.akka', name: 'akka-http_2.11', version: '10.1.0'
version101TestImplementation group: 'com.typesafe.akka', name: 'akka-stream_2.11', version: '2.5.11'

latestDepTestImplementation group: 'com.typesafe.akka', name: 'akka-http_2.11', version: '+'
latestDepTestImplementation group: 'com.typesafe.akka', name: 'akka-stream_2.11', version: '+'
}

test.dependsOn lagomTest
Expand All @@ -99,11 +91,6 @@ compileVersion101TestGroovy {
dependsOn compileVersion101TestScala
}

compileLatestDepTestGroovy {
classpath = classpath.plus(files(compileLatestDepTestScala.destinationDir))
dependsOn compileLatestDepTestScala
}

// Lagom test supports running only on java 8 for now.
// To run it on java 11 requires some complicated juggling of scala dependencies
// At the same time, "minJavaVersionForTests"/"maxJavaVersionForTests" functionality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ext {
}

apply from: "$rootDir/gradle/instrumentation.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

muzzle {
pass {
Expand All @@ -14,16 +13,6 @@ muzzle {
}
}

testSets {
latestDepTest {
dirName = 'test'
}
}

dependencies {
compileOnly group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.0'

testImplementation group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.0'

latestDepTestImplementation group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '+'
library group: 'org.apache.httpcomponents', name: 'httpasyncclient', version: '4.0'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply from: "$rootDir/gradle/instrumentation.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

muzzle {
pass {
Expand All @@ -11,16 +10,6 @@ muzzle {
}
}

testSets {
latestDepTest {
dirName = 'test'
}
}

dependencies {
compileOnly group: 'commons-httpclient', name: 'commons-httpclient', version: '2.0'

testImplementation group: 'commons-httpclient', name: 'commons-httpclient', version: '2.0'

latestDepTestImplementation group: 'commons-httpclient', name: 'commons-httpclient', version: '+'
library group: 'commons-httpclient', name: 'commons-httpclient', version: '2.0'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply from: "$rootDir/gradle/instrumentation.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

muzzle {
fail {
Expand All @@ -23,16 +22,6 @@ muzzle {
}
}

testSets {
latestDepTest {
dirName = 'test'
}
}

dependencies {
compileOnly group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.0'

testImplementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.0'

latestDepTestImplementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '+'
library group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.0'
}
2 changes: 1 addition & 1 deletion instrumentation/armeria-1.0/auto/armeria-1.0-auto.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ muzzle {
dependencies {
implementation project(':instrumentation:armeria-1.0:library')

compileOnly group: 'com.linecorp.armeria', name: 'armeria', version: '0.99.8'
library group: 'com.linecorp.armeria', name: 'armeria', version: '0.99.8'

testImplementation project(':instrumentation:armeria-1.0:testing')
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
apply from: "$rootDir/gradle/instrumentation-library.gradle"

dependencies {
compileOnly group: 'com.linecorp.armeria', name: 'armeria', version: '0.99.8'
library group: 'com.linecorp.armeria', name: 'armeria', version: '0.99.8'

testImplementation project(':instrumentation:armeria-1.0:testing')
}
29 changes: 10 additions & 19 deletions instrumentation/aws-sdk/aws-sdk-1.11/aws-sdk-1.11.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ testSets {
test_before_1_11_106 {
dirName = 'test_before_1_11_106'
}

latestDepTest {
dirName = 'test'
}
}

configurations {
Expand All @@ -45,16 +41,16 @@ configurations {
}

dependencies {
compileOnly group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.0'
library group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.0'

// Include httpclient instrumentation for testing because it is a dependency for aws-sdk.
testImplementation project(':instrumentation:apache-httpclient:apache-httpclient-4.0')
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.106'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk-rds', version: '1.11.106'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk-ec2', version: '1.11.106'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk-kinesis', version: '1.11.106'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.106'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.11.106'
testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.106'
testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-rds', version: '1.11.106'
testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-ec2', version: '1.11.106'
testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-kinesis', version: '1.11.106'
testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.106'
testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.11.106'

// needed for kinesis:
testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-cbor', version: versions.jackson
Expand All @@ -65,13 +61,8 @@ dependencies {
test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-kinesis', version: '1.11.0')
test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.0')
test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.11.0')

latestDepTestImplementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '+'
latestDepTestImplementation group: 'com.amazonaws', name: 'aws-java-sdk-rds', version: '+'
latestDepTestImplementation group: 'com.amazonaws', name: 'aws-java-sdk-ec2', version: '+'
latestDepTestImplementation group: 'com.amazonaws', name: 'aws-java-sdk-kinesis', version: '+'
latestDepTestImplementation group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '+'
latestDepTestImplementation group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '+'
}

test.dependsOn test_before_1_11_106
if (!testLatestDeps) {
test.dependsOn test_before_1_11_106
}
17 changes: 1 addition & 16 deletions instrumentation/aws-sdk/aws-sdk-2.2/auto/aws-sdk-2.2-auto.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ext {
}

apply from: "$rootDir/gradle/instrumentation.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

// TODO(anuraaga): Move into instrumentation.gradle
archivesBaseName = projectDir.parentFile.name
Expand All @@ -16,24 +15,10 @@ muzzle {
}
}

testSets {
latestDepTest {
dirName = 'test'
}
}

dependencies {
implementation project(':instrumentation:aws-sdk:aws-sdk-2.2:library')

compileOnly group: 'software.amazon.awssdk', name: 'aws-core', version: '2.2.0'
library group: 'software.amazon.awssdk', name: 'aws-core', version: '2.2.0'

testImplementation project(':instrumentation:aws-sdk:aws-sdk-2.2:testing')

latestDepTestImplementation group: 'software.amazon.awssdk', name: 'apache-client', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 's3', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'rds', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'ec2', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'sqs', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'dynamodb', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'kinesis', version: '+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,9 @@ ext {
}

apply from: "$rootDir/gradle/instrumentation-library.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

testSets {
latestDepTest {
dirName = 'test'
}
}

dependencies {
compileOnly group: 'software.amazon.awssdk', name: 'aws-core', version: '2.2.0'
library group: 'software.amazon.awssdk', name: 'aws-core', version: '2.2.0'

testImplementation project(':instrumentation:aws-sdk:aws-sdk-2.2:testing')

latestDepTestImplementation group: 'software.amazon.awssdk', name: 'apache-client', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 's3', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'rds', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'ec2', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'sqs', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'dynamodb', version: '+'
latestDepTestImplementation group: 'software.amazon.awssdk', name: 'kinesis', version: '+'
}
Loading

0 comments on commit bbfdbb3

Please sign in to comment.