Skip to content

[ML] Trained Models: Prevents download of models already present in other spaces and shows warning#220238

Merged
rbrtj merged 10 commits intoelastic:mainfrom
rbrtj:ml-trained-models-improve-messaging-on-download
May 9, 2025
Merged

[ML] Trained Models: Prevents download of models already present in other spaces and shows warning#220238
rbrtj merged 10 commits intoelastic:mainfrom
rbrtj:ml-trained-models-improve-messaging-on-download

Conversation

@rbrtj
Copy link
Contributor

@rbrtj rbrtj commented May 6, 2025

Resolves #206834
Before:

If a trained model like ELSER has already been downloaded but is not available in the current space, the download action is available but results in the following error
image

This PR prevents models from being downloaded if they already exist in a different space

  • If the model is downloaded in a different space and the user has write permissions for the current space:
image
  • If the model is downloaded in a different space but the user lacks write permissions for the current space:
image

Note:
It adds an additional request to ES, but within a trace, it is just one extra span, so the performance impact is not significant:
image

I tried adding functional tests for this, but it only applies to hosted models, which are too large to download durning the testing phase, thus I don't see a convenient way to test it.

@rbrtj rbrtj changed the title Prevent downloading models already downloaded in a different space an… May 7, 2025
'xpack.ml.trainedModels.modelsList.modelState.downloadedInDifferentSpaceTooltip.cannotDeploy',
{
defaultMessage:
'The model is downloaded in a different space. Assign it to the current space see more details.',
Copy link
Contributor

@szabosteve szabosteve May 8, 2025

Choose a reason for hiding this comment

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

I have two suggestions: a shorter one and a more user-friendly.

The shorter one:

Suggested change
'The model is downloaded in a different space. Assign it to the current space see more details.',
'The model is downloaded in a different space. Assign it to the current space to review model details.',

The more helpful:

Suggested change
'The model is downloaded in a different space. Assign it to the current space see more details.',
'The model is downloaded in a different space. If you have permission, assign it to the current space to review model details, or contact your administrator.',

The second one would be better. But it depends on how terrible it looks in the warning bubble.

Copy link
Contributor Author

@rbrtj rbrtj May 8, 2025

Choose a reason for hiding this comment

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

Not that bad, but it takes some space 🤔

image
Copy link
Contributor

Choose a reason for hiding this comment

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

Not that bad. I edited my suggestion and made it even a bit shorter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated:

image
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think that's good.

@rbrtj rbrtj marked this pull request as ready for review May 8, 2025 08:51
@rbrtj rbrtj requested a review from a team as a code owner May 8, 2025 08:51
@rbrtj rbrtj self-assigned this May 8, 2025
@rbrtj rbrtj added release_note:enhancement :ml Feature:3rd Party Models ML 3rd party models Team:ML Team label for ML (also use :ml) t// backport:version Backport to applied version labels v9.1.0 v8.19.0 labels May 8, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@rbrtj rbrtj requested a review from szabosteve May 8, 2025 09:01
import type { NameOverrides } from './get_model_state';
import { getModelStateColor } from './get_model_state';
import { useMlKibana } from '../contexts/kibana';
import { usePermissionCheck } from '../capabilities/check_capabilities';
Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't tested if this happens on main too but hit this error if:

  • From Default space, deploy the e5 model.
  • In default space, stop the deployment
  • Then from the default, or from a different space, try and run 'Start deployment'
Screenshot 2025-05-08 at 11 19 25
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haven't tested if this happens on main too

Probably not, as the capabilities check throws an error here, let me investigate - maybe I misused the capabilities check 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't been able to reproduce this on main.

Copy link
Contributor

Choose a reason for hiding this comment

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

Tested against 0981f16 and all looks good now.

): Promise<TrainedModelUIItem[]> {
const { trainedModelsSpaces } = checksFactory(this._client, mlSavedObjectService);

const rawModels = await this._client.asInternalUser.ml.getTrainedModels({
Copy link
Member

Choose a reason for hiding this comment

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

I think we should be using asCurrentUser here.
By using internal user, we might incorrectly flag a model as being downloaded to a different space, when really the user does not have permission to get the models at all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Done in 55c4d06

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested latest changes and LGTM

): Promise<TrainedModelUIItem[]> {
const { trainedModelsSpaces } = checksFactory(this._client, mlSavedObjectService);

const rawModels = await this._client.asCurrentUser.ml.getTrainedModels({
Copy link
Member

@jgowdyelastic jgowdyelastic May 8, 2025

Choose a reason for hiding this comment

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

I wonder whether this should be moved inside includeModelDownloads as that is the only place it is used and it is already an async function

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, it is definitely worth moving it into includeModelDownloads
done in 96babd0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use Promise.all for rawModels and forDownload models.
860fb19

@rbrtj rbrtj requested a review from jgowdyelastic May 9, 2025 08:27
Copy link
Member

@jgowdyelastic jgowdyelastic left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #97 / Cloud Security Posture Cloud Posture Rules Page - Table Headers Rules Page - Enable Rules and Disabled Rules Filter Toggle Should only display Enabled rules when Enabled Rules filter is ON
  • [job] [logs] FTR Configs #97 / Cloud Security Posture Vulnerabilities Page - DataTable "before all" hook in "Vulnerabilities Page - DataTable"

History

cc @rbrtj

@rbrtj rbrtj merged commit c97f2c7 into elastic:main May 9, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/14938348953

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request May 9, 2025
…her Spaces with Warning (elastic#220238)

Resolves elastic#206834
Before:
> If a trained model like ELSER has already been downloaded but is not
available in the current space, the download action is available but
results in the following error

![image](https://github.com/user-attachments/assets/e69516e5-749e-4500-b645-099975453f1e)

This PR prevents models from being downloaded if they already exist in a
different space
* If the model is downloaded in a different space and the user has write
permissions for the current space:
<img width="1228" alt="image"
src="https://github.com/user-attachments/assets/db146bbb-a295-471e-b0a1-f1a8c0949739"
/>

* If the model is downloaded in a different space but the user lacks
write permissions for the current space:
<img width="1479" alt="image"
src="https://github.com/user-attachments/assets/dcf195c1-7314-4b0b-af9d-1fbbaffcbb89"
/>

Note:
It adds an additional request to ES, but within a trace, it is just one
extra span, so the performance impact is not significant:

![image](https://github.com/user-attachments/assets/8be08344-eb91-4cdb-a5b1-a4838f5219b6)

I tried adding functional tests for this, but it only applies to hosted
models, which are too large to download durning the testing phase, thus
I don't see a convenient way to test it.

(cherry picked from commit c97f2c7)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request May 9, 2025
…t in Other Spaces with Warning (#220238) (#220723)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[ML] Trained Models: Prevent Download of Models Already Present in
Other Spaces with Warning
(#220238)](#220238)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-05-09T21:53:16Z","message":"[ML]
Trained Models: Prevent Download of Models Already Present in Other
Spaces with Warning (#220238)\n\nResolves
https://github.com/elastic/kibana/issues/206834\nBefore: \n> If a
trained model like ELSER has already been downloaded but is
not\navailable in the current space, the download action is available
but\nresults in the following
error\n\n![image](https://github.com/user-attachments/assets/e69516e5-749e-4500-b645-099975453f1e)\n\nThis
PR prevents models from being downloaded if they already exist in
a\ndifferent space\n* If the model is downloaded in a different space
and the user has write\npermissions for the current space:\n<img
width=\"1228\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/db146bbb-a295-471e-b0a1-f1a8c0949739\"\n/>\n\n*
If the model is downloaded in a different space but the user
lacks\nwrite permissions for the current space:\n<img width=\"1479\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/dcf195c1-7314-4b0b-af9d-1fbbaffcbb89\"\n/>\n\nNote:\nIt
adds an additional request to ES, but within a trace, it is just
one\nextra span, so the performance impact is not
significant:\n\n![image](https://github.com/user-attachments/assets/8be08344-eb91-4cdb-a5b1-a4838f5219b6)\n\nI
tried adding functional tests for this, but it only applies to
hosted\nmodels, which are too large to download durning the testing
phase, thus\nI don't see a convenient way to test
it.","sha":"c97f2c704d1598641f8cb9b911bf6b77e8a102cb","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement",":ml","Feature:3rd
Party
Models","Team:ML","backport:version","v9.1.0","v8.19.0"],"title":"[ML]
Trained Models: Prevent Download of Models Already Present in Other
Spaces with
Warning","number":220238,"url":"https://github.com/elastic/kibana/pull/220238","mergeCommit":{"message":"[ML]
Trained Models: Prevent Download of Models Already Present in Other
Spaces with Warning (#220238)\n\nResolves
https://github.com/elastic/kibana/issues/206834\nBefore: \n> If a
trained model like ELSER has already been downloaded but is
not\navailable in the current space, the download action is available
but\nresults in the following
error\n\n![image](https://github.com/user-attachments/assets/e69516e5-749e-4500-b645-099975453f1e)\n\nThis
PR prevents models from being downloaded if they already exist in
a\ndifferent space\n* If the model is downloaded in a different space
and the user has write\npermissions for the current space:\n<img
width=\"1228\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/db146bbb-a295-471e-b0a1-f1a8c0949739\"\n/>\n\n*
If the model is downloaded in a different space but the user
lacks\nwrite permissions for the current space:\n<img width=\"1479\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/dcf195c1-7314-4b0b-af9d-1fbbaffcbb89\"\n/>\n\nNote:\nIt
adds an additional request to ES, but within a trace, it is just
one\nextra span, so the performance impact is not
significant:\n\n![image](https://github.com/user-attachments/assets/8be08344-eb91-4cdb-a5b1-a4838f5219b6)\n\nI
tried adding functional tests for this, but it only applies to
hosted\nmodels, which are too large to download durning the testing
phase, thus\nI don't see a convenient way to test
it.","sha":"c97f2c704d1598641f8cb9b911bf6b77e8a102cb"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220238","number":220238,"mergeCommit":{"message":"[ML]
Trained Models: Prevent Download of Models Already Present in Other
Spaces with Warning (#220238)\n\nResolves
https://github.com/elastic/kibana/issues/206834\nBefore: \n> If a
trained model like ELSER has already been downloaded but is
not\navailable in the current space, the download action is available
but\nresults in the following
error\n\n![image](https://github.com/user-attachments/assets/e69516e5-749e-4500-b645-099975453f1e)\n\nThis
PR prevents models from being downloaded if they already exist in
a\ndifferent space\n* If the model is downloaded in a different space
and the user has write\npermissions for the current space:\n<img
width=\"1228\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/db146bbb-a295-471e-b0a1-f1a8c0949739\"\n/>\n\n*
If the model is downloaded in a different space but the user
lacks\nwrite permissions for the current space:\n<img width=\"1479\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/dcf195c1-7314-4b0b-af9d-1fbbaffcbb89\"\n/>\n\nNote:\nIt
adds an additional request to ES, but within a trace, it is just
one\nextra span, so the performance impact is not
significant:\n\n![image](https://github.com/user-attachments/assets/8be08344-eb91-4cdb-a5b1-a4838f5219b6)\n\nI
tried adding functional tests for this, but it only applies to
hosted\nmodels, which are too large to download durning the testing
phase, thus\nI don't see a convenient way to test
it.","sha":"c97f2c704d1598641f8cb9b911bf6b77e8a102cb"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com>
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
…her Spaces with Warning (elastic#220238)

Resolves elastic#206834
Before: 
> If a trained model like ELSER has already been downloaded but is not
available in the current space, the download action is available but
results in the following error

![image](https://github.com/user-attachments/assets/e69516e5-749e-4500-b645-099975453f1e)

This PR prevents models from being downloaded if they already exist in a
different space
* If the model is downloaded in a different space and the user has write
permissions for the current space:
<img width="1228" alt="image"
src="https://github.com/user-attachments/assets/db146bbb-a295-471e-b0a1-f1a8c0949739"
/>

* If the model is downloaded in a different space but the user lacks
write permissions for the current space:
<img width="1479" alt="image"
src="https://github.com/user-attachments/assets/dcf195c1-7314-4b0b-af9d-1fbbaffcbb89"
/>

Note:
It adds an additional request to ES, but within a trace, it is just one
extra span, so the performance impact is not significant:

![image](https://github.com/user-attachments/assets/8be08344-eb91-4cdb-a5b1-a4838f5219b6)

I tried adding functional tests for this, but it only applies to hosted
models, which are too large to download durning the testing phase, thus
I don't see a convenient way to test it.
qn895 pushed a commit to qn895/kibana that referenced this pull request Jun 3, 2025
…her Spaces with Warning (elastic#220238)

Resolves elastic#206834
Before: 
> If a trained model like ELSER has already been downloaded but is not
available in the current space, the download action is available but
results in the following error

![image](https://github.com/user-attachments/assets/e69516e5-749e-4500-b645-099975453f1e)

This PR prevents models from being downloaded if they already exist in a
different space
* If the model is downloaded in a different space and the user has write
permissions for the current space:
<img width="1228" alt="image"
src="https://github.com/user-attachments/assets/db146bbb-a295-471e-b0a1-f1a8c0949739"
/>

* If the model is downloaded in a different space but the user lacks
write permissions for the current space:
<img width="1479" alt="image"
src="https://github.com/user-attachments/assets/dcf195c1-7314-4b0b-af9d-1fbbaffcbb89"
/>

Note:
It adds an additional request to ES, but within a trace, it is just one
extra span, so the performance impact is not significant:

![image](https://github.com/user-attachments/assets/8be08344-eb91-4cdb-a5b1-a4838f5219b6)

I tried adding functional tests for this, but it only applies to hosted
models, which are too large to download durning the testing phase, thus
I don't see a convenient way to test it.
@nastasha-solomon nastasha-solomon changed the title [ML] Trained Models: Prevent Download of Models Already Present in Other Spaces with Warning Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels Feature:3rd Party Models ML 3rd party models :ml release_note:enhancement Team:ML Team label for ML (also use :ml) t// v8.19.0 v9.1.0

6 participants