Refactor ShardStats, WarmerStats and IndexingPressureStats with Builder pattern#19966
Conversation
|
❌ Gradle check result for 3e77dca: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
❌ Gradle check result for 3e77dca: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
❌ Gradle check result for 3e77dca: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java (1)
117-121: Consider improving deprecation guidance.The past review comment suggested making the migration path more explicit by referencing
ShardStats.Builderinstead of justBuilder, or providing a brief usage hint likeShardStats.builder().<setters>().build().Apply this diff to provide clearer migration guidance:
/** * This constructor will be deprecated starting in version 3.4.0. - * Use {@link Builder} instead. + * Use {@link ShardStats.Builder} to construct instances instead. + * Example: {@code new ShardStats.Builder().shardRouting(...).shardPath(...).commonStats(...).build()} */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java (1)
server/src/main/java/org/opensearch/index/stats/IndexingPressureStats.java (1)
Builder(141-224)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: check-files
- GitHub Check: detect-breaking-change
- GitHub Check: precommit (25, macos-15-intel)
- GitHub Check: precommit (25, ubuntu-24.04-arm)
- GitHub Check: precommit (21, ubuntu-24.04-arm)
- GitHub Check: precommit (25, macos-15)
- GitHub Check: precommit (21, windows-2025, true)
- GitHub Check: precommit (21, macos-15)
- GitHub Check: precommit (25, windows-latest)
- GitHub Check: precommit (25, ubuntu-latest)
- GitHub Check: precommit (21, ubuntu-latest)
- GitHub Check: precommit (21, macos-15-intel)
- GitHub Check: precommit (21, windows-latest)
- GitHub Check: assemble (25, ubuntu-latest)
- GitHub Check: assemble (25, ubuntu-24.04-arm)
- GitHub Check: assemble (25, windows-latest)
- GitHub Check: assemble (21, windows-latest)
- GitHub Check: assemble (21, ubuntu-24.04-arm)
- GitHub Check: assemble (21, ubuntu-latest)
- GitHub Check: Analyze (java)
server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java
Show resolved
Hide resolved
|
❌ Gradle check result for 9af35fe: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
❌ Gradle check result for 9af35fe: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
❌ Gradle check result for 9af35fe: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #19966 +/- ##
============================================
- Coverage 73.33% 73.18% -0.16%
+ Complexity 71679 71619 -60
============================================
Files 5790 5786 -4
Lines 327549 327754 +205
Branches 47181 47206 +25
============================================
- Hits 240217 239871 -346
- Misses 68080 68657 +577
+ Partials 19252 19226 -26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
It succeeded on my local. |
Signed-off-by: Jean Kim <bgshhd95@gmail.com>
Signed-off-by: Jean Kim <bgshhd95@gmail.com>
Signed-off-by: Jean Kim <bgshhd95@gmail.com>
Signed-off-by: Jean Kim <bgshhd95@gmail.com>
Signed-off-by: Jean Kim <bgshhd95@gmail.com>
Signed-off-by: Jean Kim <bgshhd95@gmail.com>
There was a problem hiding this comment.
Actionable comments posted: 0
♻️ Duplicate comments (1)
server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java (1)
91-101: Null validation still missing - risk of NPE at runtime.The private constructor dereferences
builder.shardPath(lines 93-95) and other builder fields without null checks. Ifbuild()is called without setting required fields (shardPath,shardRouting,commonStats), aNullPointerExceptionwill be thrown.This issue was previously flagged. Please add validation in the
Builder.build()method (lines 234-236) before constructingShardStats:public ShardStats build() { + if (shardRouting == null) { + throw new IllegalStateException("shardRouting must be set"); + } + if (shardPath == null) { + throw new IllegalStateException("shardPath must be set"); + } + if (commonStats == null) { + throw new IllegalStateException("commonStats must be set"); + } return new ShardStats(this); }
🧹 Nitpick comments (2)
server/src/main/java/org/opensearch/index/stats/IndexingPressureStats.java (1)
67-85: IndexingPressureStats.Builder implementation and deprecation strategy look sound
- The private constructor correctly copies every field from
Builder, and the builder exposes setters for all existing stats plusmemoryLimit, so behavior matches the old all‑args constructor.- Serialization and deserialization paths (
StreamInputctor andwriteTo) are unchanged, so wire compatibility is preserved while internal construction moves to the builder.- Very minor nit: the Javadoc on the private constructor calling it “the sole entry point for creating a new IndexingPressureStats object” is no longer strictly true with the public (deprecated) ctor and
StreamInputctor still present. If you want to avoid confusion for future readers, consider softening that wording (e.g., “primary entry point used by the Builder”).Also applies to: 104-108, 137-225
server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java (1)
117-121: Deprecation javadoc could be more explicit about migration path.The javadoc references
{@link Builder}which is an improvement, but could provide a clearer migration example for developers.Consider adding a brief migration hint:
/** * This constructor will be deprecated starting in version 3.4.0. - * Use {@link Builder} instead. + * Use {@link Builder} instead. Example: + * {@code new ShardStats.Builder().shardRouting(...).shardPath(...).commonStats(...).build()} */
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (18)
CHANGELOG.md(2 hunks)server/src/main/java/org/opensearch/action/admin/cluster/stats/TransportClusterStatsAction.java(2 hunks)server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java(3 hunks)server/src/main/java/org/opensearch/action/admin/indices/stats/TransportIndicesStatsAction.java(1 hunks)server/src/main/java/org/opensearch/index/IndexingPressure.java(1 hunks)server/src/main/java/org/opensearch/index/stats/IndexingPressureStats.java(3 hunks)server/src/main/java/org/opensearch/index/warmer/ShardIndexWarmerService.java(1 hunks)server/src/main/java/org/opensearch/index/warmer/WarmerStats.java(2 hunks)server/src/main/java/org/opensearch/indices/IndicesService.java(1 hunks)server/src/test/java/org/opensearch/action/admin/cluster/node/stats/NodeStatsTests.java(2 hunks)server/src/test/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodesTests.java(1 hunks)server/src/test/java/org/opensearch/action/admin/cluster/stats/ClusterStatsResponseTests.java(1 hunks)server/src/test/java/org/opensearch/action/admin/indices/rollover/TransportRolloverActionTests.java(1 hunks)server/src/test/java/org/opensearch/action/admin/indices/shards/CatShardsResponseTests.java(1 hunks)server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponseTests.java(1 hunks)server/src/test/java/org/opensearch/cluster/DiskUsageTests.java(1 hunks)server/src/test/java/org/opensearch/index/shard/IndexShardTests.java(2 hunks)server/src/test/java/org/opensearch/rest/action/cat/RestShardsActionTests.java(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
- server/src/main/java/org/opensearch/index/warmer/ShardIndexWarmerService.java
- server/src/test/java/org/opensearch/action/admin/cluster/stats/ClusterStatsNodesTests.java
- server/src/main/java/org/opensearch/index/warmer/WarmerStats.java
- server/src/main/java/org/opensearch/indices/IndicesService.java
- server/src/test/java/org/opensearch/index/shard/IndexShardTests.java
- server/src/test/java/org/opensearch/action/admin/indices/stats/IndicesStatsResponseTests.java
- CHANGELOG.md
🧰 Additional context used
🧬 Code graph analysis (2)
server/src/main/java/org/opensearch/index/stats/IndexingPressureStats.java (1)
server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java (1)
Builder(184-237)
server/src/main/java/org/opensearch/action/admin/indices/stats/ShardStats.java (1)
server/src/main/java/org/opensearch/index/stats/IndexingPressureStats.java (1)
Builder(141-224)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
- GitHub Check: gradle-check
- GitHub Check: assemble (25, windows-latest)
- GitHub Check: precommit (25, macos-15)
- GitHub Check: precommit (25, windows-latest)
- GitHub Check: precommit (25, macos-15-intel)
- GitHub Check: precommit (25, ubuntu-24.04-arm)
- GitHub Check: precommit (21, windows-2025, true)
- GitHub Check: precommit (21, ubuntu-24.04-arm)
- GitHub Check: precommit (25, ubuntu-latest)
- GitHub Check: precommit (21, windows-latest)
- GitHub Check: assemble (21, windows-latest)
- GitHub Check: precommit (21, macos-15-intel)
- GitHub Check: assemble (25, ubuntu-latest)
- GitHub Check: precommit (21, macos-15)
- GitHub Check: assemble (25, ubuntu-24.04-arm)
- GitHub Check: assemble (21, ubuntu-24.04-arm)
- GitHub Check: precommit (21, ubuntu-latest)
- GitHub Check: assemble (21, ubuntu-latest)
- GitHub Check: Analyze (java)
- GitHub Check: detect-breaking-change
🔇 Additional comments (9)
server/src/main/java/org/opensearch/index/IndexingPressure.java (1)
220-233: IndexingPressureStats builder wiring looks correctThe builder invocation sets all the same fields that were previously passed to the constructor, preserving semantics including the
memoryLimitvalue fromprimaryAndCoordinatingLimits. Looks good.server/src/test/java/org/opensearch/action/admin/indices/shards/CatShardsResponseTests.java (1)
155-164: ShardStats test construction migrated cleanly to BuilderThe builder call mirrors the previous constructor usage (routing, path,
CommonStats, and null optional stats). No behavior change; tests remain clear and aligned with the new API.server/src/test/java/org/opensearch/cluster/DiskUsageTests.java (1)
138-153: ShardStats.Builder usage in disk usage test is equivalent to prior ctorBoth shard entries correctly use
shardRouting,ShardPath,CommonStats, and explicit nulls for optional stats, matching the old constructor contract.server/src/main/java/org/opensearch/action/admin/indices/stats/TransportIndicesStatsAction.java (1)
158-165: ShardStats.Builder wiring in shardOperation() matches previous constructorThe builder sets
routingEntry,shardPath,commonStats, and all optional stats (commitStats,seqNoStats,retentionLeaseStats,pollingIngestStats) exactly as before, so behavior is preserved while adopting the new pattern.server/src/main/java/org/opensearch/action/admin/cluster/stats/TransportClusterStatsAction.java (1)
228-235: Cluster stats shard collection now correctly uses ShardStats.BuilderThe builder call in
shardsStats.add(...)sets routing, shard path,CommonStats, and the four stats objects identically to the old constructor. The small Javadoc formatting tweak onisMetricRequiredis harmless.Also applies to: 259-259
server/src/test/java/org/opensearch/action/admin/indices/rollover/TransportRolloverActionTests.java (1)
505-513: Rollover tests use ShardStats.Builder consistently with previous ctorThe builder setup (routing,
ShardPath, richCommonStats, null optional stats) is a direct translation of the old constructor-based call; good alignment with the new API.server/src/test/java/org/opensearch/action/admin/cluster/stats/ClusterStatsResponseTests.java (1)
277-284: Cluster stats response tests correctly adopt ShardStats.Builder
createShardStatsnow uses the builder to set routing, shard path, andCommonStats, with explicit nulls for optional stats, preserving the prior test behavior.server/src/test/java/org/opensearch/rest/action/cat/RestShardsActionTests.java (1)
90-97: LGTM - Builder pattern migration complete.The ShardStats construction correctly uses the new Builder pattern with all required fields (
shardRouting,shardPath,commonStats) and explicitly sets optional stats tonull.server/src/test/java/org/opensearch/action/admin/cluster/node/stats/NodeStatsTests.java (1)
1421-1428: LGTM - Consistent Builder pattern migration.Both ShardStats construction sites correctly use the Builder pattern with all required fields and explicit null values for optional stats. The migration is consistent across the test suite.
Also applies to: 1472-1479
|
❌ Gradle check result for 022b88e: FAILURE Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change? |
|
Thanks @pado0 for being patient on the last one with CI failure noise. Thanks for working through all these refactoring PRs. |
Description
This PR refactors the
ShardStats,WarmerStatsandIndexingPressureStatsclass to use the Builder pattern instead of relying on multiple constructors.By adopting the Builder pattern, it becomes easier to evolve the stats API, add new metrics, and maintain backward compatibility without forcing disruptive constructor changes.
Based on the related issue:
There are multiple stats-related classes that need similar refactoring, and we are addressing them in priority order. This PR covers
ShardStats,WarmerStatsandIndexingPressureStatsas part of that effort.Related Issues
Related to #19225
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
Summary by CodeRabbit
Refactor
Tests
Documentation
✏️ Tip: You can customize this high-level summary in your review settings.