[ML] Trained Models: Prevents download of models already present in other spaces and shows warning#220238
Conversation
…d display an appropriate warning
| '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.', |
There was a problem hiding this comment.
I have two suggestions: a shorter one and a more user-friendly.
The shorter one:
| '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:
| '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.
There was a problem hiding this comment.
Not that bad. I edited my suggestion and made it even a bit shorter.
There was a problem hiding this comment.
Yeah, I think that's good.
|
Pinging @elastic/ml-ui (:ml) |
| import type { NameOverrides } from './get_model_state'; | ||
| import { getModelStateColor } from './get_model_state'; | ||
| import { useMlKibana } from '../contexts/kibana'; | ||
| import { usePermissionCheck } from '../capabilities/check_capabilities'; |
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
Haven't been able to reproduce this on main.
| ): Promise<TrainedModelUIItem[]> { | ||
| const { trainedModelsSpaces } = checksFactory(this._client, mlSavedObjectService); | ||
|
|
||
| const rawModels = await this._client.asInternalUser.ml.getTrainedModels({ |
There was a problem hiding this comment.
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.
x-pack/platform/plugins/shared/ml/server/models/model_management/models_provider.ts
Outdated
Show resolved
Hide resolved
peteharverson
left a comment
There was a problem hiding this comment.
Tested latest changes and LGTM
| ): Promise<TrainedModelUIItem[]> { | ||
| const { trainedModelsSpaces } = checksFactory(this._client, mlSavedObjectService); | ||
|
|
||
| const rawModels = await this._client.asCurrentUser.ml.getTrainedModels({ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
good point, it is definitely worth moving it into includeModelDownloads
done in 96babd0
There was a problem hiding this comment.
Updated to use Promise.all for rawModels and forDownload models.
860fb19
⏳ Build in-progress, with failures
Failed CI StepsTest Failures
History
cc @rbrtj |
|
Starting backport for target branches: 8.19 |
…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  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:  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)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…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\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\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\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\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\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\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>
…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  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:  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.
…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  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:  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.



Resolves #206834
Before:
This PR prevents models from being downloaded if they already exist in a different space
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:
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.