Skip to content

Conversation

@RajatGupta02
Copy link
Contributor

@RajatGupta02 RajatGupta02 commented Aug 13, 2025

Description

Adding a toBuilder() method for easy modification of specific fields while preserving all other configs.

Motivation

For our opensearch storage encryption plugin, while implementing translog encryption, in our CryptoEngineFactory we needed to create an EngineConfig identical to the original except for the translogFactory (to enable encrypted translogs).

This would mean copying all fields like below, and we would miss the configs if the original configs changed in Builder :

// Must manually copy 25+ fields to change just one field
EngineConfig cryptoConfig = new EngineConfig.Builder()
    .shardId(config.getShardId())
    .threadPool(config.getThreadPool())
    .indexSettings(config.getIndexSettings())
    .warmer(config.getWarmer())
    .store(config.getStore())
    .mergePolicy(config.getMergePolicy())
    .analyzer(config.getAnalyzer())
    .similarity(config.getSimilarity())
    .codecService(getCodecService(config))
    .eventListener(config.getEventListener())
    // ... 15+ more manual field copies
    .translogFactory(cryptoTranslogFactory)  // The only field we actually want to change
    .build();

Hence, with this PR, it enables selective modification of specific fields while preserving others.

Related Issues

Resolves

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

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.

@github-actions
Copy link
Contributor

❌ Gradle check result for 522d865: 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?

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>
@github-actions
Copy link
Contributor

❌ Gradle check result for ce9558c: 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?

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>
Copy link
Member

@cwperks cwperks left a comment

Choose a reason for hiding this comment

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

Thank you @RajatGupta02 ! The changes look good to me. For any other maintainer reviewing this PR, you can see the usage here: https://github.com/opensearch-project/opensearch-storage-encryption/pull/39/files#diff-e1145e4d7e594b9d06cdc9d1a8da84d0756b05bbab95c57174ecfa82ada15facR47-R52

The responsibility for ensuring that the builder has all necessary values would fall on the EngineConfig constructor that accepts the builder so I think the changes in here are reasonable.

@andrross @mch2 wdyt?

@github-actions
Copy link
Contributor

❌ Gradle check result for 707c7cf: 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?

@kumargu
Copy link
Contributor

kumargu commented Aug 13, 2025

@RajatGupta02 i think we should also point out the problem we were facing in the encryption plugin which motivated us to make this change.

@github-actions
Copy link
Contributor

❌ Gradle check result for 707c7cf: 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?

Signed-off-by: Craig Perkins <cwperx@amazon.com>
@github-actions
Copy link
Contributor

✅ Gradle check result for 6f58967: SUCCESS

@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

❌ Patch coverage is 3.22581% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.97%. Comparing base (292407b) to head (6f58967).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...java/org/opensearch/index/engine/EngineConfig.java 0.00% 30 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #19054      +/-   ##
============================================
- Coverage     73.02%   72.97%   -0.05%     
+ Complexity    69548    69478      -70     
============================================
  Files          5647     5647              
  Lines        319106   319136      +30     
  Branches      46163    46163              
============================================
- Hits         233034   232900     -134     
- Misses        67232    67423     +191     
+ Partials      18840    18813      -27     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cwperks cwperks merged commit 04d9b49 into opensearch-project:main Aug 14, 2025
30 of 32 checks passed
RajatGupta02 added a commit to RajatGupta02/OpenSearch that referenced this pull request Aug 18, 2025
* Add a toBuilder() method

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

* Fix release version

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

---------

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Rajat Gupta <gptrajat@amazon.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
karenyrx pushed a commit to karenyrx/OpenSearch that referenced this pull request Aug 21, 2025
* Add a toBuilder() method

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

* Fix release version

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

---------

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Rajat Gupta <gptrajat@amazon.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
atris pushed a commit to atris/OpenSearch that referenced this pull request Aug 28, 2025
* Add a toBuilder() method

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

* Fix release version

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

---------

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Rajat Gupta <gptrajat@amazon.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
kh3ra pushed a commit to kh3ra/OpenSearch that referenced this pull request Sep 5, 2025
* Add a toBuilder() method

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

* Fix release version

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

---------

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Rajat Gupta <gptrajat@amazon.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
vinaykpud pushed a commit to vinaykpud/OpenSearch that referenced this pull request Sep 26, 2025
* Add a toBuilder() method

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

* Fix release version

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>

---------

Signed-off-by: Rajat Gupta <gptrajat@amazon.com>
Signed-off-by: Craig Perkins <cwperx@amazon.com>
Co-authored-by: Rajat Gupta <gptrajat@amazon.com>
Co-authored-by: Craig Perkins <cwperx@amazon.com>
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.

3 participants