Attempt to improve muzzle time by randomly ignoring versions until 10 remain (DataDog/dd-trace-java#1451)
MODIFY
.circleci/config.yml
.circleci/config.yml
@@ -9,11 +9,11 @@ defaults: &defaults
JAVA_HOME: /usr/local/openjdk-11
cache_keys: &cache_keys
- # Reset the cache approx every release
keys:
- - trace-java-{{ checksum "trace-java.gradle" }}-{{ .Branch }}-{{ .Revision }}
- - trace-java-{{ checksum "trace-java.gradle" }}-{{ .Branch }}
- - trace-java-{{ checksum "trace-java.gradle" }}
+ # Rev the version when the cache gets too big
+ - trace-java-v1-{{ .Branch }}-{{ .Revision }}
+ - trace-java-v1-{{ .Branch }}
+ # - dd-trace-java-v1-
jobs:
build:
@@ -189,16 +189,18 @@ jobs:
- checkout
- restore_cache:
- # Reset the cache approx every release
keys:
- - trace-java-muzzle-{{ checksum "trace-java.gradle" }}
+ # Rev the version when the cache gets too big
+ - trace-java-muzzle-v1-{{ .Branch }}-{{ .Revision }}
+ - trace-java-muzzle-v1-{{ .Branch }}
+ # - dd-trace-java-muzzle-v1-
- run:
name: Verify Muzzle
command: SKIP_BUILDSCAN="true" GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx4G -Xms64M' -Dota.forkedMaxHeapSize=4G -Dota.forkedMinHeapSize=64M" ./gradlew muzzle --parallel --stacktrace --no-daemon --max-workers=16
- save_cache:
- key: trace-java-muzzle-{{ checksum "trace-java.gradle" }}
+ key: trace-java-muzzle-v1-{{ .Branch }}-{{ .Revision }}
paths: ~/.gradle
publish: &publish

MODIFY
buildSrc/src/main/groovy/MuzzlePlugin.groovy
buildSrc/src/main/groovy/MuzzlePlugin.groovy
@@ -16,7 +16,6 @@ import org.eclipse.aether.transport.http.HttpTransporterFactory
import org.eclipse.aether.version.Version
import org.gradle.api.Action
import org.gradle.api.GradleException
-import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
@@ -31,11 +30,16 @@ import java.util.regex.Pattern
* muzzle task plugin which runs muzzle validation against a range of dependencies.
*/
class MuzzlePlugin implements Plugin<Project> {
+ /**
+ * Select a random set of versions to test
+ */
+ private static final int RANGE_COUNT_LIMIT = 10
/**
* Remote repositories used to query version ranges and fetch dependencies
*/
private static final List<RemoteRepository> MUZZLE_REPOS
private static final AtomicReference<ClassLoader> TOOLING_LOADER = new AtomicReference<>()
+
static {
RemoteRepository central = new RemoteRepository.Builder("central", "default", "https://repo1.maven.org/maven2/").build()
RemoteRepository sonatype = new RemoteRepository.Builder("sonatype", "default", "https://oss.sonatype.org/content/repositories/releases/").build()
@@ -205,20 +209,23 @@ class MuzzlePlugin implements Plugin<Project> {
/**
* Convert a muzzle directive to a list of artifacts
*/
- private static List<Artifact> muzzleDirectiveToArtifacts(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) {
+ private static Set<Artifact> muzzleDirectiveToArtifacts(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) {
final Artifact directiveArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", muzzleDirective.versions)
final VersionRangeRequest rangeRequest = new VersionRangeRequest()
rangeRequest.setRepositories(MUZZLE_REPOS)
rangeRequest.setArtifact(directiveArtifact)
final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest)
+ final Set<Version> versions = rangeResult.versions.toSet()
+
+ limitLargeRanges(rangeResult, versions, muzzleDirective.skipVersions)
// println "Range Request: " + rangeRequest
// println "Range Result: " + rangeResult
- final List<Artifact> allVersionArtifacts = filterVersion(rangeResult.versions, muzzleDirective.skipVersions).collect { version ->
+ final Set<Artifact> allVersionArtifacts = filterVersion(versions, muzzleDirective.skipVersions).collect { version ->
new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", version.toString())
- }
+ }.toSet()
if (allVersionArtifacts.isEmpty()) {
throw new GradleException("No muzzle artifacts found for $muzzleDirective.group:$muzzleDirective.module $muzzleDirective.versions")
@@ -230,8 +237,8 @@ class MuzzlePlugin implements Plugin<Project> {
/**
* Create a list of muzzle directives which assert the opposite of the given MuzzleDirective.
*/
- private static List<MuzzleDirective> inverseOf(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) {
- List<MuzzleDirective> inverseDirectives = new ArrayList<>()
+ private static Set<MuzzleDirective> inverseOf(MuzzleDirective muzzleDirective, RepositorySystem system, RepositorySystemSession session) {
+ Set<MuzzleDirective> inverseDirectives = new HashSet<>()
final Artifact allVerisonsArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", "[,)")
final Artifact directiveArtifact = new DefaultArtifact(muzzleDirective.group, muzzleDirective.module, "jar", muzzleDirective.versions)
@@ -246,9 +253,10 @@ class MuzzlePlugin implements Plugin<Project> {
rangeRequest.setRepositories(MUZZLE_REPOS)
rangeRequest.setArtifact(directiveArtifact)
final VersionRangeResult rangeResult = system.resolveVersionRange(session, rangeRequest)
+ final Set<Version> versions = rangeResult.versions.toSet()
- filterVersion(allRangeResult.versions, muzzleDirective.skipVersions).collect { version ->
- if (!rangeResult.versions.contains(version)) {
+ filterVersion(allRangeResult.versions.toSet(), muzzleDirective.skipVersions).collect { version ->
+ if (!versions.contains(version)) {
final MuzzleDirective inverseDirective = new MuzzleDirective()
inverseDirective.group = muzzleDirective.group
inverseDirective.module = muzzleDirective.module
@@ -261,6 +269,21 @@ class MuzzlePlugin implements Plugin<Project> {
return inverseDirectives
}
+ private static void limitLargeRanges(VersionRangeResult result, Set<Version> versions, Set<String> skipVersions) {
+ List<Version> copy = new ArrayList<>(versions)
+ copy.removeAll(skipVersions)
+ Collections.shuffle(copy)
+ while (RANGE_COUNT_LIMIT <= copy.size()) {
+ Version version = copy.pop()
+ if (!(version.equals(result.lowestVersion) || version.equals(result.highestVersion))) {
+ skipVersions.add(version.toString())
+ }
+ }
+ if (skipVersions.size() > 0) {
+ println "Muzzle skipping " + skipVersions.size() + " versions"
+ }
+ }
+
/**
* Configure a muzzle task to pass or fail a given version.
*
@@ -361,7 +384,7 @@ class MuzzlePlugin implements Plugin<Project> {
/**
* Filter out snapshot-type builds from versions list.
*/
- private static filterVersion(List<Version> list, Set<String> skipVersions) {
+ private static filterVersion(Set<Version> list, Set<String> skipVersions) {
list.removeIf {
def version = it.toString().toLowerCase()
return version.contains("rc") ||

Attempt to improve muzzle time by randomly ignoring versions until 10 remain (DataDog/dd-trace-java#1451)