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

Check if indices exist in the presence of empty search results #495

Merged
merged 3 commits into from
Apr 11, 2022

Conversation

kaituo
Copy link
Collaborator

@kaituo kaituo commented Apr 8, 2022

Description

Previously, CompositeRetriever throws an IllegalArgumentException in the presence of empty results, which gets translated to internal failure and increments AD failure count. When the source index is a regex like blah*, we will get an empty response even if the index does not exist. This PR checks indices exist in the presence of empty search results. If yes, we throw an IndexNotFoundException that ends up being converted to EndRunException; if no, we still throw an IllegalArgumentException.

Testing done:

  1. added unit tests
  2. reproduced manually and verified the change fixed the issue.

Signed-off-by: Kaituo Li [email protected]

Check List

  • Commits are signed per the DCO using --signoff

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.

Previously, CompositeRetriever throws an IllegalArgumentException in the presence of empty results, which gets translated to internal failure and increments AD failure count. When the source index is a regex like blah*, we will get an empty response even if the index does not exist. This PR checks indices exist in the presence of empty search results. If yes, we throw an IndexNotFoundException that ends up being converted to EndRunException; if no, we still throw an IllegalArgumentException.

Testing done:
1. added unit tests
2. reproduced manually and verified the change fixed the issue.

Signed-off-by: Kaituo Li <[email protected]>
@kaituo kaituo requested a review from a team April 8, 2022 19:44
@kaituo kaituo requested review from amitgalitz and ylwu-amzn April 8, 2022 19:44
* 2) next detection interval has not started
* @return true if the iteration has more pages.
*/
public boolean hasNext() {
return (totalResults == 0 || (totalResults > 0 && afterKey != null)) && expirationEpochMs > clock.millis();
return (iterations == 0 || (totalResults > 0 && afterKey != null)) && expirationEpochMs > clock.millis();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible iterations == 0 and afterKey == null? Not sure if this is enough afterKey != null && expirationEpochMs > clock.millis()

Copy link
Collaborator Author

@kaituo kaituo Apr 8, 2022

Choose a reason for hiding this comment

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

Is it possible iterations == 0 and afterKey == null

It is possible.

afterKey != null && expirationEpochMs > clock.millis()

This is not enough as at the beginning afterKey = null.

Signed-off-by: Kaituo Li <[email protected]>
@kaituo kaituo requested review from ylwu-amzn and amitgalitz April 8, 2022 22:47
amitgalitz
amitgalitz previously approved these changes Apr 8, 2022
Copy link
Member

@amitgalitz amitgalitz left a comment

Choose a reason for hiding this comment

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

Thanks for making this fix!

ylwu-amzn
ylwu-amzn previously approved these changes Apr 8, 2022
Copy link
Collaborator

@ylwu-amzn ylwu-amzn left a comment

Choose a reason for hiding this comment

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

LGTM.

@kaituo kaituo dismissed stale reviews from ylwu-amzn and amitgalitz via 1da59c5 April 9, 2022 00:40
Signed-off-by: Kaituo Li <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Apr 9, 2022

Codecov Report

Merging #495 (9da20e1) into main (ee057e2) will increase coverage by 0.06%.
The diff coverage is 80.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #495      +/-   ##
============================================
+ Coverage     78.14%   78.20%   +0.06%     
- Complexity     4155     4162       +7     
============================================
  Files           296      296              
  Lines         17654    17663       +9     
  Branches       1877     1878       +1     
============================================
+ Hits          13795    13814      +19     
+ Misses         2963     2954       -9     
+ Partials        896      895       -1     
Flag Coverage Δ
plugin 78.20% <80.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...rch/ad/transport/AnomalyResultTransportAction.java 80.13% <ø> (ø)
.../org/opensearch/ad/feature/CompositeRetriever.java 84.48% <80.00%> (+0.37%) ⬆️
.../main/java/org/opensearch/ad/cluster/HashRing.java 81.37% <0.00%> (-0.41%) ⬇️
...ain/java/org/opensearch/ad/model/ModelProfile.java 70.90% <0.00%> (ø)
...opensearch/ad/indices/AnomalyDetectionIndices.java 72.31% <0.00%> (+0.18%) ⬆️
...ain/java/org/opensearch/ad/task/ADTaskManager.java 76.90% <0.00%> (+0.22%) ⬆️
...java/org/opensearch/ad/task/ADBatchTaskRunner.java 82.52% <0.00%> (+0.75%) ⬆️
...va/org/opensearch/ad/AnomalyDetectorJobRunner.java 64.17% <0.00%> (+0.78%) ⬆️
...ava/org/opensearch/ad/task/ADHCBatchTaskCache.java 90.12% <0.00%> (+1.23%) ⬆️

@kaituo kaituo merged commit 9d44f1b into opensearch-project:main Apr 11, 2022
@opensearch-trigger-bot
Copy link

The backport to 1.x failed:

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

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.x 1.x
# Navigate to the new working tree
cd .worktrees/backport-1.x
# Create a new branch
git switch --create backport/backport-495-to-1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 9d44f1bad1bd674c8a03b2629ababab21783f2f3
# Push it to GitHub
git push --set-upstream origin backport/backport-495-to-1.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.x

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

@opensearch-trigger-bot
Copy link

The backport to 1.3 failed:

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

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-1.3 1.3
# Navigate to the new working tree
cd .worktrees/backport-1.3
# Create a new branch
git switch --create backport/backport-495-to-1.3
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 9d44f1bad1bd674c8a03b2629ababab21783f2f3
# Push it to GitHub
git push --set-upstream origin backport/backport-495-to-1.3
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-1.3

Then, create a pull request where the base branch is 1.3 and the compare/head branch is backport/backport-495-to-1.3.

@amitgalitz amitgalitz added the bug Something isn't working label Apr 20, 2022
kaituo added a commit to kaituo/anomaly-detection-1 that referenced this pull request Apr 25, 2022
…rch results (opensearch-project#495)

* Check if indices exist in the presence of empty search results

Previously, CompositeRetriever throws an IllegalArgumentException in the presence of empty results, which gets translated to internal failure and increments AD failure count. When the source index is a regex like blah*, we will get an empty response even if the index does not exist. This PR checks indices exist in the presence of empty search results. If yes, we throw an IndexNotFoundException that ends up being converted to EndRunException; if no, we still throw an IllegalArgumentException.

Testing done:
1. added unit tests
2. reproduced manually and verified the change fixed the issue.

Signed-off-by: Kaituo Li <[email protected]>
kaituo added a commit that referenced this pull request Apr 25, 2022
…rch results (#495) (#522)

* Check if indices exist in the presence of empty search results

Previously, CompositeRetriever throws an IllegalArgumentException in the presence of empty results, which gets translated to internal failure and increments AD failure count. When the source index is a regex like blah*, we will get an empty response even if the index does not exist. This PR checks indices exist in the presence of empty search results. If yes, we throw an IndexNotFoundException that ends up being converted to EndRunException; if no, we still throw an IllegalArgumentException.

Testing done:
1. added unit tests
2. reproduced manually and verified the change fixed the issue.

Signed-off-by: Kaituo Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.x backport 1.3 bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants