OpenSearch icon indicating copy to clipboard operation
OpenSearch copied to clipboard

Add support for deep copying SearchRequest

Open ansjcy opened this issue 2 years ago • 15 comments

Description

Add support for deep copying a SearchRequest with roundtriping the request to a stream.

Related Issues

Resolves #869

Check List

  • [x] New functionality includes testing.
    • [x] All tests pass
  • [x] New functionality has been documented.
    • [x] New functionality has javadoc added
  • [x] Failing checks are inspected and point to the corresponding known issue(s) (See: Troubleshooting Failing Builds)
  • [x] Commits are signed per the DCO using --signoff
  • [x] Commit changes are listed out in CHANGELOG.md file (See: Changelog)
  • [ ] Public documentation issue/PR created

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.

ansjcy avatar Feb 12 '24 22:02 ansjcy

:x: Gradle check result for bc4d842d0ef28e578b4ac86e52f87c6c0becd5ac: 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?

github-actions[bot] avatar Feb 12 '24 22:02 github-actions[bot]

Compatibility status:

Checks if related components are compatible with change a23b9c2

Incompatible components

Incompatible components: [https://github.com/opensearch-project/security.git]

Skipped components

Compatible components

Compatible components: [https://github.com/opensearch-project/custom-codecs.git, https://github.com/opensearch-project/asynchronous-search.git, https://github.com/opensearch-project/performance-analyzer-rca.git, https://github.com/opensearch-project/cross-cluster-replication.git, https://github.com/opensearch-project/flow-framework.git, https://github.com/opensearch-project/job-scheduler.git, https://github.com/opensearch-project/reporting.git, https://github.com/opensearch-project/geospatial.git, https://github.com/opensearch-project/opensearch-oci-object-storage.git, https://github.com/opensearch-project/common-utils.git, https://github.com/opensearch-project/k-nn.git, https://github.com/opensearch-project/neural-search.git, https://github.com/opensearch-project/performance-analyzer.git, https://github.com/opensearch-project/anomaly-detection.git, https://github.com/opensearch-project/security-analytics.git, https://github.com/opensearch-project/observability.git, https://github.com/opensearch-project/ml-commons.git, https://github.com/opensearch-project/notifications.git, https://github.com/opensearch-project/index-management.git, https://github.com/opensearch-project/alerting.git, https://github.com/opensearch-project/sql.git]

github-actions[bot] avatar Feb 12 '24 22:02 github-actions[bot]

:x: Gradle check result for 02bf180243a5e5c24fcbcf1c047e5da35f77c559: 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?

github-actions[bot] avatar Feb 12 '24 22:02 github-actions[bot]

:x: Gradle check result for 2f29630e3512176c0a103ab6ffb925a1696e1d97: 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?

github-actions[bot] avatar Feb 12 '24 23:02 github-actions[bot]

@peternied thanks for your comment. Let me quickly go though the core and plugin repos, to see if I can identify some use cases.

ansjcy avatar Feb 13 '24 22:02 ansjcy

:grey_exclamation: Gradle check result for 18ae8232a7633c429bfa1fa08d06d5ea02b7e1f1: UNSTABLE

  • TEST FAILURES:
      1 org.opensearch.cluster.MinimumClusterManagerNodesIT.testThreeNodesNoClusterManagerBlock

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

github-actions[bot] avatar Feb 13 '24 22:02 github-actions[bot]

Codecov Report

Attention: Patch coverage is 55.55556% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 71.42%. Comparing base (b15cb0c) to head (18ae823). Report is 255 commits behind head on main.

:exclamation: Current head 18ae823 differs from pull request most recent head 0750906. Consider uploading reports for the commit 0750906 to get more accurate results

Files Patch % Lines
...va/org/opensearch/action/search/SearchRequest.java 55.55% 4 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##               main   #12295     +/-   ##
===========================================
  Coverage     71.42%   71.42%             
+ Complexity    59978    59841    -137     
===========================================
  Files          4985     4959     -26     
  Lines        282275   281135   -1140     
  Branches      40946    40857     -89     
===========================================
- Hits         201603   200792    -811     
+ Misses        63999    63694    -305     
+ Partials      16673    16649     -24     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Feb 13 '24 22:02 codecov[bot]

This PR is stalled because it has been open for 30 days with no activity.

@peternied I added a bunch of use cases that can be replaced by this deep clone method in the original issue: https://github.com/opensearch-project/OpenSearch/issues/869#issuecomment-1942737900

Let me know what you think! thanks!

ansjcy avatar Mar 26 '24 00:03 ansjcy

Hi @peternied !

For those case that you've reference why is a deep copy needed instead of a 'slim' copy?

For the first use cases I identified (https://github.com/opensearch-project/search-processor/blob/c31475e5465fdce80c7c9b86519a4d8d0141c06b/amazon-kendra-intelligent-ranking/src/main/java/org/opensearch/search/relevance/actionfilter/SearchActionFilter.java#L91), I think we want to rewrite the originalSearchSource and don't want to change the previous request. For the second use case (https://github.com/opensearch-project/alerting/blob/719db46c7312edc265952c3ffe9c5233eb9dfe1f/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt#L199) , The developer mentioned there's a bug if we don't use deep copy, as mentioned in the comment.

Deep copying query before passing it to rewriteQuery since otherwise, the monitor.input is modified directly, which causes a strange bug where the rewritten query persists on the Monitor across executions

I think the use cases are all related to query rewrite/transform. We need to clone a new search query without impacting the original query. But based on the discussions of the original issue, I think we have already validated why this function is much needed.

ansjcy avatar Apr 10 '24 22:04 ansjcy

:x: Gradle check result for a23b9c2996e2fc7a7d30946a875c86225431e969: 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?

github-actions[bot] avatar Apr 10 '24 22:04 github-actions[bot]

Hi @peternied! I just updated the PR based on your comments. Let me know it make sense to you. Thank you!

ansjcy avatar Apr 23 '24 23:04 ansjcy

:x: Gradle check result for d77f578f8e56a5461ffaa6fd5678fa2f9d5149cd: 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?

github-actions[bot] avatar Apr 23 '24 23:04 github-actions[bot]

:x: Gradle check result for 47932809c933b0f4af52900e4224cf3642ef1cf6: 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?

github-actions[bot] avatar Apr 23 '24 23:04 github-actions[bot]

@ansjcy Please continue iterating to green on the pull request check failures & root cause the test failures (troubleshooting-failing-builds)

peternied avatar Apr 26 '24 18:04 peternied

:grey_exclamation: Gradle check result for 07509068b7597b9cbb6cbec7544650545d68acae: UNSTABLE

  • TEST FAILURES:
      1 org.opensearch.http.SearchRestCancellationIT.testAutomaticCancellationMultiSearchDuringFetchPhase

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

github-actions[bot] avatar May 02 '24 21:05 github-actions[bot]

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch/backport-2.x
# Create a new branch
git switch --create backport/backport-12295-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 79957ebc03c4af746a31cdeb47158bad96553505
# Push it to GitHub
git push --set-upstream origin backport/backport-12295-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-12295-to-2.x.

@ansjcy Could you please manually backport the change to 2.x?

peternied avatar May 02 '24 23:05 peternied