Skip to content

Commit

Permalink
[Gradle] Add buildkite ci validation script for configuration cache (e…
Browse files Browse the repository at this point in the history
…lastic#110269)

We see gradle cache incompatibilities sneaking into our code base. Until
we can enable this feature by default we should regular run checks
existing configuration cache achievements are not degrading.

This change includes: - updating spotless gradle plugin to configuration
cache compatible version (its still BETA but imo good enough for our
needs)
  • Loading branch information
breskeby authored Aug 7, 2024
1 parent 0b18f71 commit fcc5d37
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ curl -s -L -O https://github.com/gradle/gradle-enterprise-build-validation-scrip
tmpOutputFile=$(mktemp)
trap "rm $tmpOutputFile" EXIT

set +e
gradle-enterprise-gradle-build-validation/03-validate-local-build-caching-different-locations.sh -r https://github.com/elastic/elasticsearch.git -b $BUILDKITE_BRANCH --gradle-enterprise-server https://gradle-enterprise.elastic.co -t precommit --fail-if-not-fully-cacheable | tee $tmpOutputFile

# Capture the return value
retval=$?
set -e

# Now read the content from the temporary file into a variable
perfOutput=$(cat $tmpOutputFile | sed -n '/Performance Characteristics/,/See https:\/\/gradle.com\/bvs\/main\/Gradle.md#performance-characteristics for details./p' | sed '$d' | sed 's/\x1b\[[0-9;]*m//g')
investigationOutput=$(cat $tmpOutputFile | sed -n '/Investigation Quick Links/,$p' | sed 's/\x1b\[[0-9;]*m//g')

# Initialize HTML output variable
summaryHtml="<h4>Performance Characteristics</h4>"
summaryHtml="<h4>Build Cache Performance Characteristics</h4>"
summaryHtml+="<ul>"

# Process each line of the string
Expand Down
27 changes: 27 additions & 0 deletions .buildkite/scripts/gradle-configuration-cache-validation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -euo pipefail

# TODO/ FIXIT without a full resolved gradle home, we see issues configuration cache reuse
./gradlew --max-workers=8 --parallel --scan --no-daemon precommit

./gradlew --max-workers=8 --parallel --scan --configuration-cache precommit -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2

# Create a temporary file
tmpOutputFile=$(mktemp)
trap "rm $tmpOutputFile" EXIT

echo "2nd run"
# TODO run-gradle.sh script causes issues because of init script handling
./gradlew --max-workers=8 --parallel --scan --configuration-cache precommit -Dorg.gradle.configuration-cache.inputs.unsafe.ignore.file-system-checks=build/*.tar.bz2 | tee $tmpOutputFile

# Check if the command was successful
if grep -q "Configuration cache entry reused." $tmpOutputFile; then
echo "Gradle configuration cache reused"
exit 0
else
echo "Failed to reuse Gradle configuration cache."
exit 1
fi


Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void apply(Project target) {
: System.getenv("BUILDKITE_BUILD_NUMBER");
String performanceTest = System.getenv("BUILD_PERFORMANCE_TEST");
if (buildNumber != null && performanceTest == null && GradleUtils.isIncludedBuild(target) == false) {
File targetFile = target.file("build/" + buildNumber + ".tar.bz2");
File targetFile = calculateTargetFile(target, buildNumber);
File projectDir = target.getProjectDir();
File gradleWorkersDir = new File(target.getGradle().getGradleUserHomeDir(), "workers/");
DevelocityConfiguration extension = target.getExtensions().getByType(DevelocityConfiguration.class);
Expand All @@ -86,9 +86,19 @@ public void apply(Project target) {
}
}

private File calculateTargetFile(Project target, String buildNumber) {
File uploadFile = target.file("build/" + buildNumber + ".tar.bz2");
int artifactIndex = 1;
while (uploadFile.exists()) {
uploadFile = target.file("build/" + buildNumber + "-" + artifactIndex++ + ".tar.bz2");
}
return uploadFile;
}

private List<File> resolveProjectLogs(File projectDir) {
var projectDirFiles = getFileOperations().fileTree(projectDir);
projectDirFiles.include("**/*.hprof");
projectDirFiles.include("**/build/reports/configuration-cache/**");
projectDirFiles.include("**/build/test-results/**/*.xml");
projectDirFiles.include("**/build/testclusters/**");
projectDirFiles.include("**/build/testrun/*/temp/**");
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugin/esql/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ dependencies {
internalClusterTestImplementation project(":modules:mapper-extras")
}

def projectDirectory = project.layout.projectDirectory
def generatedSourceDir = projectDirectory.dir("src/main/generated")
tasks.named("compileJava").configure {
options.compilerArgumentProviders.add(new SourceDirectoryCommandLineArgumentProvider(project.layout.projectDirectory.dir("src/main/generated")))
options.compilerArgumentProviders.add(new SourceDirectoryCommandLineArgumentProvider(generatedSourceDir))
// IntelliJ sticks generated files here and we can't stop it....
exclude { it.file.toString().contains("$projectDir/src/main/generated-src/generated") }
exclude { it.file.toString().contains("src/main/generated-src/generated") }
}

interface Injected {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugin/esql/compute/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ dependencies {
testImplementation(project(xpackModule('esql-core')))
}

def projectDirectory = project.layout.projectDirectory
def generatedSourceDir = projectDirectory.dir("src/main/generated")
tasks.named("compileJava").configure {
options.compilerArgumentProviders.add(new SourceDirectoryCommandLineArgumentProvider(project.layout.projectDirectory.dir("src/main/generated")))
options.compilerArgumentProviders.add(new SourceDirectoryCommandLineArgumentProvider(generatedSourceDir))
}

tasks.named('checkstyleMain').configure {
Expand Down

0 comments on commit fcc5d37

Please sign in to comment.