Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Fix IllegalArgumentException thrown when creating a PIT #16781

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

peteralfonsi
Copy link
Contributor

@peteralfonsi peteralfonsi commented Dec 4, 2024

Description

Fixes java.lang.IllegalArgumentException: No enum constant org.opensearch.action.search.SearchPhaseName.CREATE_PIT which is thrown when creating a PIT.

The exception comes from SearchRequestStats. It doesn't track PIT stats as this is handled elsewhere. So, when it got search phases with the name "create_pit", it couldn't find a matching enum value and threw the error. Adds a try-catch block on search phase start/end/failure so that if no matching enum value is found, nothing happens.

Adds UTs. Also, manually tested that after making the change, the following commands no longer caused the exception:

curl -XPOST "http://localhost:9200/test-index/_doc/1?op_type=index" -H "Content-Type: application/json" -d '{ "field1": "value1", "field2": "value2", "field3": 123 }'

curl -XPOST "http://localhost:9200/test-index/_search/point_in_time?keep_alive=1h"

And confirmed the new catch-all doesn't show up in the output of curl -XGET "localhost:9200/_nodes/stats/indices/search".

Related Issues

Resolves #16750

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.

Signed-off-by: Peter Alfonsi <petealft@amazon.com>
@github-actions github-actions bot added bug Something isn't working Search Search query, autocomplete ...etc v2.19.0 Issues and PRs related to version 2.19.0 v3.0.0 Issues and PRs related to version 3.0.0 labels Dec 4, 2024
Signed-off-by: Peter Alfonsi <petealft@amazon.com>
@peteralfonsi peteralfonsi changed the title fix create_pit enum bug [Bugfix] Fix IllegalArgumentException thrown when creating a PIT Dec 4, 2024
Copy link
Contributor

github-actions bot commented Dec 4, 2024

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

@peteralfonsi peteralfonsi marked this pull request as draft December 4, 2024 21:47
Signed-off-by: Peter Alfonsi <petealft@amazon.com>
@peteralfonsi
Copy link
Contributor Author

Flaky test: #14293

Copy link
Contributor

github-actions bot commented Dec 4, 2024

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

@peteralfonsi
Copy link
Contributor Author

Flaky tests: #15829, #16015, #14311

Signed-off-by: Peter Alfonsi <petealft@amazon.com>
@peteralfonsi peteralfonsi added the backport 2.x Backport to 2.x branch label Dec 6, 2024
@peteralfonsi peteralfonsi marked this pull request as ready for review December 6, 2024 00:51
Copy link
Contributor

github-actions bot commented Dec 6, 2024

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

@peteralfonsi
Copy link
Contributor Author

Flaky test: #16576

Signed-off-by: Peter Alfonsi <petealft@amazon.com>
Copy link
Contributor

github-actions bot commented Dec 6, 2024

❕ Gradle check result for e20a4de: UNSTABLE

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

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.11%. Comparing base (d199096) to head (e20a4de).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #16781      +/-   ##
============================================
- Coverage     72.19%   72.11%   -0.09%     
+ Complexity    65274    65187      -87     
============================================
  Files          5318     5318              
  Lines        303993   303999       +6     
  Branches      43990    43990              
============================================
- Hits         219461   219222     -239     
- Misses        66517    66774     +257     
+ Partials      18015    18003      -12     

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

@@ -73,20 +73,32 @@ public long getTookMetric() {

@Override
protected void onPhaseStart(SearchPhaseContext context) {
phaseStatsMap.get(context.getCurrentPhase().getSearchPhaseName()).current.inc();
try {
phaseStatsMap.get(context.getCurrentPhase().getSearchPhaseName()).current.inc();
Copy link
Member

@andrross andrross Dec 6, 2024

Choose a reason for hiding this comment

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

I count 4 method calls in this line. The problem with this try-catch is that any one of them in theory could throw an IllegalArgumentException, and you probably don't want to swallow it in all cases. Also, exception handling in the control flow is generally something to avoid.

I might recommend revisiting that API on SearchPhase to make it explicit that it may not be possible to get a SearchPhaseName. Like if it returned an Optional you could do:

phase.asSearchPhaseName().ifPresent(name -> {
    phaseStatsMap.get(name).current.inc();
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. I've just pushed a commit changing getSearchPhaseName to return Optional<SearchPhaseName>.

Signed-off-by: Peter Alfonsi <petealft@amazon.com>
Copy link
Contributor

github-actions bot commented Dec 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch bug Something isn't working Search Search query, autocomplete ...etc v2.19.0 Issues and PRs related to version 2.19.0 v3.0.0 Issues and PRs related to version 3.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] No enum constant org.opensearch.action.search.SearchPhaseName.CREATE_PIT
3 participants