Skip to content

Conversation

phananh1010
Copy link
Owner

@phananh1010 phananh1010 commented Oct 8, 2025

Single commit with tree=a25ede51f680602cdeeae9b45d1540ca9fbcc04f^{tree}, parent=24bd70b9d1eb60747a7ba3b7c971e2096da843fd. Exact snapshot of upstream PR head. No conflict resolution attempted.

Summary by CodeRabbit

  • New Features

    • Test seed now regenerates on each run, with behavior compatible with Gradle configuration cache.
    • Randomized build settings now use lazy evaluation for more predictable, deferred resolution.
  • Refactor

    • Migrated seed and randomness handling to provider-based patterns across build and QA configurations.
    • Updated conditionals to use provider-backed values.
  • Tests

    • Added a functional test validating per-run seed changes and configuration cache reuse.
  • Chores

    • Removed unused imports in a QA build script.

BASE=24bd70b9d1eb60747a7ba3b7c971e2096da843fd
HEAD=a25ede51f680602cdeeae9b45d1540ca9fbcc04f
Branch=main
Copy link

coderabbitai bot commented Oct 8, 2025

Walkthrough

Introduces provider-based test seed and randomness handling across plugins and build scripts, integrates BuildFeatures checks, adds a ValueSource to supply tests.seed, updates GlobalBuildInfoPlugin and ElasticsearchTestBasePlugin to use providers, adjusts x-pack build scripts to map randomness via providers, and adds a functional test verifying per-invocation test seeds with configuration cache reuse.

Changes

Cohort / File(s) Summary
Seed provider & build features integration
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java, .../internal/info/BuildParameterExtension.java, .../internal/info/DefaultBuildParameterExtension.java, .../internal/info/GlobalBuildInfoPlugin.java, .../internal/info/TestSeedValueSource.java
Add BuildFeatures injection/usage; shift test seed and Random to Provider-based APIs; introduce TestSeedValueSource for lazily obtaining/generating tests.seed; update GlobalBuildInfoPlugin to use providers, apply VersionPropertiesPlugin, and avoid resolving seed under configuration cache.
Functional test for per-invocation seed and config cache reuse
build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchTestBasePluginFuncTest.groovy
Adds test verifying new seed on each build invocation, same seed within a single invocation across tasks, and configuration cache entry reuse on second run.
Provider-based randomness in x-pack build scripts
x-pack/plugin/security/qa/profile/build.gradle, x-pack/qa/multi-cluster-search-security/legacy-with-basic-license/build.gradle, x-pack/qa/multi-cluster-search-security/legacy-with-full-license/build.gradle, x-pack/qa/multi-cluster-search-security/legacy-with-restricted-trust/build.gradle
Replace eager boolean flags from Random with Provider-mapped values (buildParams.random.map{...}.get()), updating condition checks to use provider.get().
Build script cleanup
x-pack/plugin/sql/qa/jdbc/security/build.gradle
Remove unused imports; no functional changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant Gradle as Gradle Build
  participant GBIP as GlobalBuildInfoPlugin
  participant ETP as ElasticsearchTestBasePlugin
  participant BF as BuildFeatures
  participant VS as TestSeedValueSource
  participant Task as Test Task(s)

  Dev->>Gradle: Run build (with/without config cache)
  Gradle->>GBIP: apply()
  GBIP->>BF: isConfigurationCacheActive()
  alt CC active
    note over GBIP,Task: Defer seed resolution via Provider
  else CC inactive
    GBIP->>VS: obtain tests.seed (provider resolve)
    VS-->>GBIP: seed (from sysprop or generated)
    GBIP-->>Gradle: Log seed (non-CC path)
  end

  Gradle->>ETP: configure test tasks
  ETP->>BF: isConfigurationCacheActive() / ignore.tests.seed?
  alt Use Provider path
    ETP->>Task: systemProperty "tests.seed" <- buildParams.getTestSeedProvider()
  else Direct path
    ETP->>Task: systemProperty "tests.seed" <- buildParams.getTestSeed()
  end

  loop Within a single invocation
    Task->>Task: All tests use same provided seed
  end
  note over Gradle: Next invocation gets a new Provider value (different seed)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

I nibbled the seeds of tests today,
Each run a fresh and skittery sway—
Providers whisper, “Not yet, wait,”
Then pop! a hex decides our fate.
Cache purrs, reuse in place,
New roll next hop—such bunny grace. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly states that this pull request mirrors upstream elastic#133811 for AI review and notes that it is a snapshot of the HEAD tree, which succinctly captures the PR’s primary purpose without unnecessary detail. It is a single concise sentence that accurately reflects the main action taken in the changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch eval/pr-133811-diff

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
x-pack/qa/multi-cluster-search-security/legacy-with-basic-license/build.gradle (1)

60-69: Avoid multiple .get() calls on the random provider

Each call to proxyModeProvider.get() re-runs the map closure, advancing the shared Random and yielding different booleans. The cluster configuration and blacklist can therefore diverge (e.g. cluster configured for proxy mode while the task assumes sniff), breaking test setup nondeterministically. Resolve the provider once and reuse the same value everywhere.

-def proxyModeProvider = buildParams.random.map{r -> r.nextBoolean()}
+def proxyModeProvider = buildParams.random.map { r -> r.nextBoolean() }
+def proxyMode = proxyModeProvider.get()
 ...
-  if (proxyModeProvider.get()) {
+  if (proxyMode) {
 ...
-  if (proxyModeProvider.get()) {
+  if (proxyMode) {

Also applies to: 82-89

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24bd70b and ff535f5.

📒 Files selected for processing (11)
  • build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchTestBasePluginFuncTest.groovy (1 hunks)
  • build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/ElasticsearchTestBasePlugin.java (3 hunks)
  • build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/BuildParameterExtension.java (2 hunks)
  • build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/DefaultBuildParameterExtension.java (4 hunks)
  • build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java (7 hunks)
  • build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/TestSeedValueSource.java (1 hunks)
  • x-pack/plugin/security/qa/profile/build.gradle (1 hunks)
  • x-pack/plugin/sql/qa/jdbc/security/build.gradle (0 hunks)
  • x-pack/qa/multi-cluster-search-security/legacy-with-basic-license/build.gradle (3 hunks)
  • x-pack/qa/multi-cluster-search-security/legacy-with-full-license/build.gradle (2 hunks)
  • x-pack/qa/multi-cluster-search-security/legacy-with-restricted-trust/build.gradle (2 hunks)
💤 Files with no reviewable changes (1)
  • x-pack/plugin/sql/qa/jdbc/security/build.gradle

Comment on lines +165 to +169
verifyAll {
seeds1[0] != null
seeds2[0] != null
seeds1[0] != seeds2[0]
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guard against empty seed lists before indexing

If neither test nor test2 emits the TESTSEED=[…] line, seeds1[0]/seeds2[0] will throw IndexOutOfBoundsException. Please assert the lists are non-empty before indexing, e.g. !seeds1.isEmpty() / !seeds2.isEmpty().

🤖 Prompt for AI Agents
In
build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/ElasticsearchTestBasePluginFuncTest.groovy
around lines 165 to 169, guard against empty seed lists before indexing by first
asserting both lists are non-empty (e.g. !seeds1.isEmpty() and
!seeds2.isEmpty()) and only then index into [0] for null checks and comparison;
update the verifyAll block to check !seeds1.isEmpty() && !seeds2.isEmpty()
before evaluating seeds1[0] != null, seeds2[0] != null and seeds1[0] !=
seeds2[0].

Comment on lines +20 to +23
@Override
public ValueSourceParameters.None getParameters() {
return null;
}
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Return the ValueSourceParameters.None singleton instead of null.

Using the provided singleton clarifies intent and avoids any accidental null-handling edge cases inside Gradle’s value source plumbing.

     @Override
     public ValueSourceParameters.None getParameters() {
-        return null;
+        return ValueSourceParameters.None.INSTANCE;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Override
public ValueSourceParameters.None getParameters() {
return null;
}
@Override
public ValueSourceParameters.None getParameters() {
return ValueSourceParameters.None.INSTANCE;
}
🤖 Prompt for AI Agents
In
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/TestSeedValueSource.java
around lines 20 to 23, the getParameters() method currently returns null;
replace that null with the provided singleton by returning
ValueSourceParameters.None.INSTANCE instead so the method returns the
appropriate non-null singleton value and avoids null-handling issues in Gradle's
value source plumbing.

tasks.named("javaRestTest").configure {
usesDefaultDistribution("to be triaged")
systemProperty 'test.literalUsername', literalUsername
systemProperty 'test.literalUsername', buildParams.random.map{r -> r.nextBoolean()}.get()
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Don't eagerly resolve the random provider.

Calling .get() here forces the provider to resolve during configuration, which locks the boolean into the configuration cache and still reuses the same value on subsequent invocations. Use the provider directly (via systemProperty’s provider overload or systemPropertyProviders) so the boolean is generated when the task runs.

-  systemProperty 'test.literalUsername', buildParams.random.map{ r -> r.nextBoolean() }.get()
+  systemPropertyProviders.put('test.literalUsername', buildParams.random.map { r -> Boolean.toString(r.nextBoolean()) })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
systemProperty 'test.literalUsername', buildParams.random.map{r -> r.nextBoolean()}.get()
systemPropertyProviders.put('test.literalUsername', buildParams.random.map { r -> Boolean.toString(r.nextBoolean()) })
🤖 Prompt for AI Agents
In x-pack/plugin/security/qa/profile/build.gradle around line 17, the call to
buildParams.random.map{r -> r.nextBoolean()}.get() eagerly resolves the provider
at configuration time; change it to pass the Provider itself to the system
property (use the systemProperty overload that accepts a Provider or use
systemPropertyProviders) so the boolean is produced at execution time rather
than calling .get() during configuration.


// randomise between sniff and proxy modes
boolean proxyMode = buildParams.random.nextBoolean()
var proxyModeProvider = buildParams.random.map{r -> r.nextBoolean()}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Fix Groovy variable declaration

var is not valid in Groovy build scripts and causes unable to resolve class var. Declare the provider with def (or an explicit Provider<Boolean>).

-var proxyModeProvider = buildParams.random.map{r -> r.nextBoolean()}
+def proxyModeProvider = buildParams.random.map { r -> r.nextBoolean() }
🤖 Prompt for AI Agents
In
x-pack/qa/multi-cluster-search-security/legacy-with-basic-license/build.gradle
around line 22, the script uses the invalid Groovy keyword "var" causing "unable
to resolve class var"; replace the declaration with a Groovy-compatible one such
as "def proxyModeProvider = buildParams.random.map { r -> r.nextBoolean() }" or
an explicit typed provider like "Provider<Boolean> proxyModeProvider =
buildParams.random.map { r -> r.nextBoolean() }" so the variable is declared
correctly and the build script resolves.


// randomise between sniff and proxy modes
boolean proxyMode = buildParams.random.nextBoolean()
var proxyModeProvider = buildParams.random.map{r -> r.nextBoolean()}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Replace var with a Groovy-compatible declaration

build.gradle uses the Groovy DSL, which does not recognize var as a type. This line will fail with unable to resolve class var. Declare the provider with def (or an explicit Provider<Boolean> type) instead.

-var proxyModeProvider = buildParams.random.map{r -> r.nextBoolean()}
+def proxyModeProvider = buildParams.random.map { r -> r.nextBoolean() }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
var proxyModeProvider = buildParams.random.map{r -> r.nextBoolean()}
def proxyModeProvider = buildParams.random.map { r -> r.nextBoolean() }
🤖 Prompt for AI Agents
In x-pack/qa/multi-cluster-search-security/legacy-with-full-license/build.gradle
around line 22, the declaration uses the Java/Kotlin-style keyword "var" which
Groovy DSL doesn't recognize; replace "var" with a Groovy-compatible declaration
such as "def proxyModeProvider = buildParams.random.map { r -> r.nextBoolean()
}" or declare an explicit Provider<Boolean> type so the build resolves
correctly.


// randomise between sniff and proxy modes
boolean proxyMode = buildParams.random.nextBoolean()
var proxyModeProvider = buildParams.random.map{r -> r.nextBoolean()}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Use def instead of var in Groovy build scripts

Groovy DSL scripts cannot declare variables with var; this triggers unable to resolve class var at configuration time. Switch to def (or an explicit Provider<Boolean> type).

-var proxyModeProvider = buildParams.random.map{r -> r.nextBoolean()}
+def proxyModeProvider = buildParams.random.map { r -> r.nextBoolean() }
🤖 Prompt for AI Agents
In
x-pack/qa/multi-cluster-search-security/legacy-with-restricted-trust/build.gradle
around line 32, the Groovy build script incorrectly uses the JavaScript/Java
'var' keyword which causes "unable to resolve class var" at configuration time;
replace 'var' with 'def' (or an explicit Provider<Boolean> type) so the
declaration becomes valid Groovy and the expression buildParams.random.map{ r ->
r.nextBoolean() } is assigned correctly.

@phananh1010 phananh1010 closed this Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant