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

applying multi-tenancy in search [model, model group, agent, connector] #3433

Merged
merged 2 commits into from
Jan 28, 2025

Conversation

dhrubo-os
Copy link
Collaborator

Description

[Describe what this change achieves]

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • 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.

@dhrubo-os dhrubo-os force-pushed the multi_tenancy_search branch 2 times, most recently from 93b04e5 to 0b4eded Compare January 25, 2025 18:44
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_search branch from 0b4eded to 57f9afa Compare January 28, 2025 01:02
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_search branch from 57f9afa to 90745b2 Compare January 28, 2025 01:20
@dhrubo-os dhrubo-os marked this pull request as ready for review January 28, 2025 01:51
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_search branch from 90745b2 to 7f32eb9 Compare January 28, 2025 02:09
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_search branch from 7f32eb9 to 22620bc Compare January 28, 2025 03:06
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_search branch from 22620bc to 88dc346 Compare January 28, 2025 04:26
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_search branch from 88dc346 to 9f653e8 Compare January 28, 2025 04:35
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env January 28, 2025 04:37 — with GitHub Actions Inactive
import lombok.Getter;

@Getter
public class MLSearchActionRequest extends SearchRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add java documentation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added

@@ -96,4 +129,26 @@ private void search(SearchRequest request, ActionListener<SearchResponse> action
actionListener.onFailure(e);
}
}

@VisibleForTesting
public static void wrapListenerToHandleConnectorIndexNotFound(Exception e, ActionListener<SearchResponse> listener) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is currently not being used.

Copy link
Collaborator Author

@dhrubo-os dhrubo-os Jan 28, 2025

Choose a reason for hiding this comment

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

This method is being used in unit tests. And after sdkclient implementation we will use it here if we need too.

Comment on lines 121 to 125

// For multi-tenancy
if (tenantId != null) {
shouldQuery.should(QueryBuilders.termQuery(TENANT_ID_FIELD, tenantId));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicate

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks, removed.

queryBuilder.must(request.source().query());
}
// Add tenancy filter
queryBuilder.filter(QueryBuilders.termQuery(TENANT_ID_FIELD, tenantId)); // Replace 'tenant_id_field' with actual field name
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the comment valid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope, removed.

@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env January 28, 2025 17:39 — with GitHub Actions Inactive
Signed-off-by: Dhrubo Saha <[email protected]>
@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env January 28, 2025 17:46 — with GitHub Actions Inactive
@Getter
public class MLSearchActionRequest extends SearchRequest {
SearchRequest searchRequest;
String tenantId;
Copy link
Collaborator

Choose a reason for hiding this comment

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

A new MLSearchActionRequest class was added to wrap the original SearchRequest and include a tenantId field.So I want to understand does it impact other functionality using SearchRequest?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can you please give me an example which functionality are you referring to?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the order matters, when did the SearchRequest converts to MLSearchActionRequest? I am worry about the tools and search pipelines that are using the search requests. if the transform is after them, it should be fine, but if that's before tools and search pipelines, does it impact them?
for example

private SearchRequest getSearchRequest(String index, String query) throws IOException {

return new MLSearchActionRequest(input);
}
} catch (IOException e) {
throw new UncheckedIOException("failed to parse ActionRequest into MLSearchActionRequest", e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this exception handling, I think IllegalArgumentException is more proper in this case

The method is expecting an ActionRequest that can be converted to MLSearchActionRequest.
If the conversion fails, it's likely because the input ActionRequest is not of the expected type or format.
This is more of a logical/argument error than an I/O error.

I think if using IllegalArgumentException, it provides clearer feedback to the caller about what went wrong.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is literally the same method we use for all other request classes. Example

@dhrubo-os dhrubo-os merged commit 1422c7c into opensearch-project:main Jan 28, 2025
7 of 8 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.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-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-3433-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 1422c7c6940143db4b92fba6fbb08a7acd10641b
# Push it to GitHub
git push --set-upstream origin backport/backport-3433-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

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

dhrubo-os added a commit to dhrubo-os/ml-commons that referenced this pull request Jan 28, 2025
…r] (opensearch-project#3433)

* applying multi-tenancy in search

Signed-off-by: Dhrubo Saha <[email protected]>

* addressed comments

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
dhrubo-os added a commit to dhrubo-os/ml-commons that referenced this pull request Jan 28, 2025
…r] (opensearch-project#3433)

* applying multi-tenancy in search

Signed-off-by: Dhrubo Saha <[email protected]>

* addressed comments

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
dhrubo-os added a commit to dhrubo-os/ml-commons that referenced this pull request Jan 29, 2025
…r] (opensearch-project#3433)

* applying multi-tenancy in search

Signed-off-by: Dhrubo Saha <[email protected]>

* addressed comments

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
dhrubo-os added a commit to dhrubo-os/ml-commons that referenced this pull request Jan 30, 2025
…r] (opensearch-project#3433)

* applying multi-tenancy in search

Signed-off-by: Dhrubo Saha <[email protected]>

* addressed comments

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
dhrubo-os added a commit that referenced this pull request Jan 30, 2025
…agent, connector] (#3433) (#3443)

* applying multi-tenancy in search [model, model group, agent, connector] (#3433)

* applying multi-tenancy in search

Signed-off-by: Dhrubo Saha <[email protected]>

* addressed comments

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>

* changing MLSearchActionRequest to an instance subclass of SearchActionRequest

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jan 30, 2025
…agent, connector] (#3433) (#3443)

* applying multi-tenancy in search [model, model group, agent, connector] (#3433)

* applying multi-tenancy in search

Signed-off-by: Dhrubo Saha <[email protected]>

* addressed comments

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>

* changing MLSearchActionRequest to an instance subclass of SearchActionRequest

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
(cherry picked from commit 34a7fb6)
dhrubo-os added a commit that referenced this pull request Jan 30, 2025
…agent, connector] (#3433) (#3443) (#3469)

* applying multi-tenancy in search [model, model group, agent, connector] (#3433)

* applying multi-tenancy in search

Signed-off-by: Dhrubo Saha <[email protected]>

* addressed comments

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>

* changing MLSearchActionRequest to an instance subclass of SearchActionRequest

Signed-off-by: Dhrubo Saha <[email protected]>

---------

Signed-off-by: Dhrubo Saha <[email protected]>
(cherry picked from commit 34a7fb6)

Co-authored-by: Dhrubo Saha <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants