-
Notifications
You must be signed in to change notification settings - Fork 186
Refactor checks to ML Indices to return true when MultiTenancy enabled #4089
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
Refactor checks to ML Indices to return true when MultiTenancy enabled #4089
Conversation
Signed-off-by: Brian Flores <iflorbri@amazon.com>
ml-algorithms/src/main/java/org/opensearch/ml/engine/indices/MLIndicesHandler.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Brian Flores <iflorbri@amazon.com>
dbwiddis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a grammar nit and needed test.
| * @implNote It is recommended that if your environment enables multi tenancy, your plugin indices are | ||
| * pre-populated otherwise this method will result in unwanted early returns without checking the clusterService | ||
| */ | ||
| public static boolean doesMultiTenantIndexExists(ClusterService clusterService, boolean isMultiTenancyEnabled, String indexName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar nit: doesFooExists is wrong, either fooExists or doesFooExist should be used. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you need a test added for this method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, Not sure why the test went through my head. I appreciate your feedback!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to steal my flow framework test. I got help from Claude anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I ended up mocking the responses and check for the actual search when multi-tenancy is disabled
@Test
public void doesMultiTenantIndexExist_multiTenancyEnabled_returnsTrue() {
assertTrue(MLIndicesHandler.doesMultiTenantIndexExist(null, true, null));
MLIndicesHandler mlIndicesHandler = new MLIndicesHandler(clusterService, client, mlFeatureEnabledSetting);
assertTrue(mlIndicesHandler.doesIndexExists(ML_CONFIG_INDEX));
}
@Test
public void doesMultiTenantIndexExist_multiTenancyDisabledSearchesClusterService_returnsValidSearchResult() {
assertFalse(MLIndicesHandler.doesMultiTenantIndexExist(clusterService, false, null));
String sampleIndexName = "test-index";
when(mlFeatureEnabledSetting.isMultiTenancyEnabled()).thenReturn(false);
MLIndicesHandler mlIndicesHandler = new MLIndicesHandler(clusterService, client, mlFeatureEnabledSetting);
when(clusterService.state().metadata().hasIndex(sampleIndexName)).thenReturn(true);
assertTrue(mlIndicesHandler.doesIndexExists(sampleIndexName));
when(clusterService.state().metadata().hasIndex(sampleIndexName)).thenReturn(false);
assertFalse(mlIndicesHandler.doesIndexExists(sampleIndexName));
}
Signed-off-by: Brian Flores <iflorbri@amazon.com>
dbwiddis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one doc recommendation.
| * @implNote It is recommended that if your environment enables multi tenancy, your plugin indices are | ||
| * pre-populated otherwise this method will result in unwanted early returns without checking the clusterService |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't aware of this javadoc. I like it... more than "recommended" I'd say it's assumed that when multitenancy is enabled that indices (or tables in DDB) are already created.
Yep thats what I did and tests pass now :) @dhrubo-os I moved the Setting above |
Signed-off-by: Brian Flores <iflorbri@amazon.com>
Signed-off-by: Brian Flores <iflorbri@amazon.com>
Signed-off-by: Brian Flores <iflorbri@amazon.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4089 +/- ##
============================================
+ Coverage 79.06% 79.07% +0.01%
- Complexity 8621 8628 +7
============================================
Files 755 755
Lines 38352 38361 +9
Branches 4287 4287
============================================
+ Hits 30324 30335 +11
+ Misses 6220 6218 -2
Partials 1808 1808
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Brian Flores <iflorbri@amazon.com>
|
The backport to 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-2.19 2.19
# Navigate to the new working tree
cd .worktrees/backport-2.19
# Create a new branch
git switch --create backport/backport-4089-to-2.19
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 b8da64257bcf1dcdb953a153ca88c1c1f27a6e1a
# Push it to GitHub
git push --set-upstream origin backport/backport-4089-to-2.19
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.19Then, create a pull request where the |
|
@brianf-aws could you please raise a backport PR manually. |
opensearch-project#4089) * refactor checks to ml indices to return true when MultiTenancy enabled Signed-off-by: Brian Flores <iflorbri@amazon.com> * add JavaDoc to doesMultiTenantIndexExists Signed-off-by: Brian Flores <iflorbri@amazon.com> * updates naming & adds UTs to doesMultiTenantIndexExist Signed-off-by: Brian Flores <iflorbri@amazon.com> * assert MLIndicesHandler has non-null MLFeatureEnabledSettingObject Signed-off-by: Brian Flores <iflorbri@amazon.com> * update JavaDoc with better grammar Signed-off-by: Brian Flores <iflorbri@amazon.com> * apply spotless Signed-off-by: Brian Flores <iflorbri@amazon.com> --------- Signed-off-by: Brian Flores <iflorbri@amazon.com>
Description
Currently in environments where MultiTenancy is Enabled and indices are pre-populated outside of the local environment there is a cache invalidation issue. When this occurs there exists a local cold node that checks that the index exists.
Instead we want to check that multi-tenancy is enabled and return early that we can assert logic that has the above line can continue.
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Testing
Check List
--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.