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

multi-tenancy + sdk client related changes in agents #3432

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dhrubo-os
Copy link
Collaborator

Description

[multi-tenancy + sdk client related changes in agents]

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_agent branch 2 times, most recently from 6b2ef3d to 68ecd9a Compare January 24, 2025 22:04
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_agent branch from 68ecd9a to b3bd8b4 Compare January 24, 2025 22:09
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_agent branch 2 times, most recently from 6eb19a3 to 3d9f58d Compare January 24, 2025 22:55
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_agent branch from 3d9f58d to eade048 Compare January 24, 2025 23:21
@dhrubo-os dhrubo-os force-pushed the multi_tenancy_agent branch from eade048 to 0feb3b4 Compare January 25, 2025 01:11
Comment on lines +109 to +111
@Override
public void onMultiTenancyEnabledChanged(boolean isEnabled) {
this.isMultiTenancyEnabled = isEnabled;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I remember this setting is static as

public static final Setting<Boolean> ML_COMMONS_MULTI_TENANCY_ENABLED = Setting
, are we expecting it can be changed dynamically?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So I developed this piece of code when we are thinking to change tenancy dynamically. But for now, we are keeping it as a static settings. But still piece of code applied, it doesn't harm. If we in the long run want to turn it to dynamic settings we won't need to do anything from our end.

Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure that as a static setting it will never trigger this method at all. And you have to actually register listeners to get these notifications and I don't see that done. So it's half implemented. I agree it's harmless here but I'd rather see none or all.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Right but you need to add a settings update consumer in the class where you want it to update. See https://github.com/search?q=repo%3Aopensearch-project%2Fml-commons%20addsettingsupdateconsumer&type=code

But I never see us register multitenancy (we did at one time on the feature branch but I think I removed it):

public MLFeatureEnabledSetting(ClusterService clusterService, Settings settings) {
isRemoteInferenceEnabled = ML_COMMONS_REMOTE_INFERENCE_ENABLED.get(settings);
isAgentFrameworkEnabled = ML_COMMONS_AGENT_FRAMEWORK_ENABLED.get(settings);
isLocalModelEnabled = ML_COMMONS_LOCAL_MODEL_ENABLED.get(settings);
isConnectorPrivateIpEnabled = new AtomicBoolean(ML_COMMONS_CONNECTOR_PRIVATE_IP_ENABLED.get(settings));
isControllerEnabled = ML_COMMONS_CONTROLLER_ENABLED.get(settings);
isBatchIngestionEnabled = ML_COMMONS_OFFLINE_BATCH_INGESTION_ENABLED.get(settings);
isBatchInferenceEnabled = ML_COMMONS_OFFLINE_BATCH_INFERENCE_ENABLED.get(settings);
isMultiTenancyEnabled = ML_COMMONS_MULTI_TENANCY_ENABLED.get(settings);
clusterService
.getClusterSettings()
.addSettingsUpdateConsumer(ML_COMMONS_REMOTE_INFERENCE_ENABLED, it -> isRemoteInferenceEnabled = it);
clusterService
.getClusterSettings()
.addSettingsUpdateConsumer(ML_COMMONS_AGENT_FRAMEWORK_ENABLED, it -> isAgentFrameworkEnabled = it);
clusterService.getClusterSettings().addSettingsUpdateConsumer(ML_COMMONS_LOCAL_MODEL_ENABLED, it -> isLocalModelEnabled = it);
clusterService
.getClusterSettings()
.addSettingsUpdateConsumer(ML_COMMONS_CONNECTOR_PRIVATE_IP_ENABLED, it -> isConnectorPrivateIpEnabled.set(it));
clusterService.getClusterSettings().addSettingsUpdateConsumer(ML_COMMONS_CONTROLLER_ENABLED, it -> isControllerEnabled = it);
clusterService
.getClusterSettings()
.addSettingsUpdateConsumer(ML_COMMONS_OFFLINE_BATCH_INGESTION_ENABLED, it -> isBatchIngestionEnabled = it);
clusterService
.getClusterSettings()
.addSettingsUpdateConsumer(ML_COMMONS_OFFLINE_BATCH_INFERENCE_ENABLED, it -> isBatchInferenceEnabled = it);
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we just need to add it back here, that's all. So for now I'll keep the code as it is.

@jngz-es
Copy link
Collaborator

jngz-es commented Jan 25, 2025

I have a high level question. It turns out we are to add a tenant id in MLToolSpec that means for every tool we will check the permission according to tenant id? From my point of view, we don't have any tools related APIs like create/delete, as we don't think of a tool as a resource. On the contrary, we consider the agent to be the resource for that we have create/delete APIs. So I am wondering if it is enough that we only have resource control on agents per tenant id.

@dhrubo-os
Copy link
Collaborator Author

I have a high level question. It turns out we are to add a tenant id in MLToolSpec that means for every tool we will check the permission according to tenant id? From my point of view, we don't have any tools related APIs like create/delete, as we don't think of a tool as a resource. On the contrary, we consider the agent to be the resource for that we have create/delete APIs. So I am wondering if it is enough that we only have resource control on agents per tenant id.

That a very good question. I agree with that. But the problem is, tool can make prediction to the model. But that model needs to be tenant specific. So which is why we are forwarding this tenant id everywhere. This way when tool wants to perform any operation we can check if this tool has enough permission to perform the operation.

Copy link
Member

@dbwiddis dbwiddis left a comment

Choose a reason for hiding this comment

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

LGTM. A lot more complicated than I thought!

Comment on lines +109 to +111
@Override
public void onMultiTenancyEnabledChanged(boolean isEnabled) {
this.isMultiTenancyEnabled = isEnabled;
Copy link
Member

Choose a reason for hiding this comment

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

Pretty sure that as a static setting it will never trigger this method at all. And you have to actually register listeners to get these notifications and I don't see that done. So it's half implemented. I agree it's harmless here but I'd rather see none or all.

@dhrubo-os dhrubo-os temporarily deployed to ml-commons-cicd-env January 25, 2025 08:02 — with GitHub Actions Inactive
Copy link

codecov bot commented Jan 25, 2025

Codecov Report

Attention: Patch coverage is 69.69697% with 110 lines in your changes missing coverage. Please review.

Project coverage is 80.22%. Comparing base (f28bb74) to head (be09e92).
Report is 173 commits behind head on main.

Files with missing lines Patch % Lines
...ch/ml/engine/algorithms/agent/MLAgentExecutor.java 78.12% 13 Missing and 8 partials ⚠️
...h/ml/action/agents/DeleteAgentTransportAction.java 72.22% 14 Missing and 6 partials ⚠️
...orithms/agent/MLConversationalFlowAgentRunner.java 0.00% 12 Missing ⚠️
...arch/ml/action/agents/GetAgentTransportAction.java 80.48% 5 Missing and 3 partials ⚠️
...ava/org/opensearch/ml/common/agent/MLToolSpec.java 53.33% 3 Missing and 4 partials ⚠️
.../ml/engine/algorithms/agent/MLFlowAgentRunner.java 60.00% 4 Missing and 2 partials ⚠️
...n/java/org/opensearch/ml/common/agent/MLAgent.java 61.53% 3 Missing and 2 partials ⚠️
...ml/action/agents/TransportRegisterAgentAction.java 82.60% 3 Missing and 1 partial ⚠️
...rg/opensearch/ml/client/MachineLearningClient.java 0.00% 3 Missing ⚠️
...nsearch/ml/common/connector/AbstractConnector.java 0.00% 0 Missing and 3 partials ⚠️
... and 15 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3432      +/-   ##
============================================
- Coverage     81.31%   80.22%   -1.10%     
- Complexity     6094     6699     +605     
============================================
  Files           573      599      +26     
  Lines         25268    29298    +4030     
  Branches       2666     3258     +592     
============================================
+ Hits          20547    23504    +2957     
- Misses         3601     4377     +776     
- Partials       1120     1417     +297     
Flag Coverage Δ
ml-commons 80.22% <69.69%> (-1.10%) ⬇️

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

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

@dhrubo-os dhrubo-os deployed to ml-commons-cicd-env January 25, 2025 09:00 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants