-
Notifications
You must be signed in to change notification settings - Fork 870
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use caffeine3 on jdk11 and caffeine2 on older jdks (#4154)
* Use caffeine3 on jdk11 and caffein2 on older jdks * ignore caffeine3 classes on java 8 * Update dependencyManagement/build.gradle.kts Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com> Co-authored-by: Mateusz Rzeszutek <mrzeszutek@splunk.com>
- Loading branch information
Showing
15 changed files
with
436 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
plugins { | ||
id("com.github.johnrengelman.shadow") | ||
|
||
id("otel.java-conventions") | ||
} | ||
|
||
val shadowInclude by configurations.creating { | ||
isCanBeResolved = true | ||
isCanBeConsumed = false | ||
} | ||
|
||
val caffeine2Version: String by project | ||
|
||
dependencies { | ||
compileOnly("com.github.ben-manes.caffeine:caffeine:$caffeine2Version") | ||
shadowInclude("com.github.ben-manes.caffeine:caffeine:$caffeine2Version") { | ||
exclude("com.google.errorprone", "error_prone_annotations") | ||
exclude("org.checkerframework", "checker-qual") | ||
} | ||
} | ||
|
||
// patch inner class from Caffeine to avoid ForkJoinTask from being loaded too early in the javaagent | ||
val patch by sourceSets.creating { | ||
java {} | ||
} | ||
|
||
tasks { | ||
shadowJar { | ||
configurations = listOf(shadowInclude) | ||
|
||
relocate("com.github.benmanes.caffeine", "io.opentelemetry.instrumentation.api.internal.shaded.caffeine2") | ||
|
||
minimize() | ||
} | ||
|
||
javadoc { | ||
enabled = false | ||
} | ||
|
||
val extractShadowJar by registering(Copy::class) { | ||
dependsOn(shadowJar) | ||
|
||
// replace caffeine class with our patched version | ||
from(zipTree(shadowJar.get().archiveFile)) { | ||
exclude("io/opentelemetry/instrumentation/api/internal/shaded/caffeine2/cache/BoundedLocalCache\$PerformCleanupTask.class") | ||
exclude("META-INF/**") | ||
} | ||
from(patch.output) { | ||
include("io/opentelemetry/instrumentation/api/internal/shaded/caffeine2/cache/BoundedLocalCache\$PerformCleanupTask.class") | ||
} | ||
|
||
into("build/extracted/shadow") | ||
// prevents empty com/github/benmanes/caffeine/cache path from ending up in instrumentation-api | ||
includeEmptyDirs = false | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
plugins { | ||
id("com.github.johnrengelman.shadow") | ||
|
||
id("otel.java-conventions") | ||
} | ||
|
||
val shadowInclude by configurations.creating { | ||
isCanBeResolved = true | ||
isCanBeConsumed = false | ||
} | ||
|
||
val caffeine3Version: String by project | ||
|
||
dependencies { | ||
compileOnly("com.github.ben-manes.caffeine:caffeine:$caffeine3Version") | ||
shadowInclude("com.github.ben-manes.caffeine:caffeine:$caffeine3Version") { | ||
exclude("com.google.errorprone", "error_prone_annotations") | ||
exclude("org.checkerframework", "checker-qual") | ||
} | ||
} | ||
|
||
// patch inner class from Caffeine to avoid ForkJoinTask from being loaded too early in the javaagent | ||
val patch by sourceSets.creating { | ||
java {} | ||
} | ||
|
||
tasks { | ||
shadowJar { | ||
configurations = listOf(shadowInclude) | ||
|
||
relocate("com.github.benmanes.caffeine", "io.opentelemetry.instrumentation.api.internal.shaded.caffeine3") | ||
|
||
minimize() | ||
} | ||
|
||
javadoc { | ||
enabled = false | ||
} | ||
|
||
val extractShadowJar by registering(Copy::class) { | ||
dependsOn(shadowJar) | ||
|
||
// replace caffeine class with our patched version | ||
from(zipTree(shadowJar.get().archiveFile)) { | ||
exclude("io/opentelemetry/instrumentation/api/internal/shaded/caffeine3/cache/BoundedLocalCache\$PerformCleanupTask.class") | ||
exclude("META-INF/**") | ||
} | ||
from(patch.output) { | ||
include("io/opentelemetry/instrumentation/api/internal/shaded/caffeine3/cache/BoundedLocalCache\$PerformCleanupTask.class") | ||
} | ||
|
||
into("build/extracted/shadow") | ||
// prevents empty com/github/benmanes/caffeine/cache path from ending up in instrumentation-api | ||
includeEmptyDirs = false | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...hing/caffeine3/src/main/java/com/github/benmanes/caffeine/cache/CacheImplementations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.github.benmanes.caffeine.cache; | ||
|
||
// Caffeine uses reflection to load cache implementations based on parameters specified by a user. | ||
// We use gradle-shadow-plugin to minimize the dependency on Caffeine, but it does not allow | ||
// specifying classes to keep, only artifacts. It's a relatively simple workaround for us to use | ||
// this non-public class to create a static link to the required implementations we use. | ||
final class CacheImplementations { | ||
|
||
// Each type of cache has a cache implementation and a node implementation. | ||
|
||
// Strong keys, strong values, maximum size | ||
SSMS<?, ?> ssms; // cache | ||
PSMS<?, ?> psms; // node | ||
|
||
// Weak keys, strong values, maximum size | ||
WSMS<?, ?> wsms; // cache | ||
FSMS<?, ?> fsms; // node | ||
|
||
// Weak keys, weak values | ||
WI<?, ?> wi; // cache | ||
FW<?, ?> fw; // node | ||
|
||
private CacheImplementations() {} | ||
} |
64 changes: 64 additions & 0 deletions
64
.../opentelemetry/instrumentation/api/internal/shaded/caffeine3/cache/BoundedLocalCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
// Includes work from: | ||
/* | ||
* Copyright 2017 Datadog, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* | ||
* Copyright 2014 Ben Manes. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.api.internal.shaded.caffeine3.cache; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
/** skeleton outer class just for compilation purposes, not included in the final patch. */ | ||
abstract class BoundedLocalCache<K, V> { | ||
abstract void performCleanUp(Runnable task); | ||
|
||
/** patched to not extend ForkJoinTask as we don't want that class loaded too early. */ | ||
static final class PerformCleanupTask implements Runnable { | ||
private static final long serialVersionUID = 1L; | ||
|
||
final WeakReference<BoundedLocalCache<?, ?>> reference; | ||
|
||
PerformCleanupTask(BoundedLocalCache<?, ?> cache) { | ||
reference = new WeakReference<>(cache); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
BoundedLocalCache<?, ?> cache = reference.get(); | ||
if (cache != null) { | ||
cache.performCleanUp(/* ignored */ null); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.