Maps additional properties for Ml graphql types
What does this MR do and why?
As we move all requests and data fetching within Model registry to graphql, additional data is necessary to migrate the model display page. While some of the page already uses graphql (version and candidate list), fetching the model itself is done when fetching the page. This adds mapping for the remaining properties needed, and so that we are able to fetch the same information from https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/helpers/projects/ml/model_registry_helper.rb#L19:
{
'projectPath' => project.full_path,
'indexModelsPath' => "/#{project.full_path}/-/ml/models",
'canWriteModelRegistry' => true,
'mlflowTrackingUrl' => "http://localhost/api/v4/projects/#{project.id}/ml/mlflow/",
'model' => {
'id' => model.id,
'name' => model.name,
'path' => "/#{project.full_path}/-/ml/models/#{model.id}",
'description' => 'A description',
'latestVersion' => {
'version' => model.latest_version.version,
'description' => model.latest_version.description,
'path' => "/#{project.full_path}/-/ml/models/#{model.id}/versions/#{model.latest_version.id}",
'projectPath' => "/#{project.full_path}",
'packageId' => model.latest_version.package_id,
'candidate' => {
'info' => {
'iid' => candidate.iid,
'eid' => candidate.eid,
'pathToArtifact' => nil,
'experimentName' => candidate.experiment.name,
'pathToExperiment' => "/#{project.full_path}/-/ml/experiments/#{experiment.iid}",
'status' => 'running',
'path' => "/#{project.full_path}/-/ml/candidates/#{candidate.iid}",
'ciJob' => nil
},
'metrics' => [],
'params' => [],
'metadata' => []
}
},
'versionCount' => 1,
'candidateCount' => 2
}
}
note providing the same structure is not necessary, only the same data.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
Example below:
-
In rails console enable the experiment fully
Feature.enable(:model_registry)
-
Create a model and model_version:
p = Project.find_by(id: 1) model = Ml::FindOrCreateModelService.new(p, "gitlab_amazing_model").execute model_version = Ml::FindOrCreateModelVersionService.new(p, { model_name: "gitlab_amazing_model", version: "1.0.0" }).execute model_version.candidate.update!(ci_build_id: Ci::Build.first.id)
-
Open
http://localhost:3000/-/graphql-explorer
and run the following query:query { mlModel(id: "gid://gitlab/Ml::Model/1") { id description name versionCount candidateCount latestVersion { id version candidate { id name iid eid status _links { showPath artifactPath } ciJob { id webPath name pipeline { id mergeRequest { id title webUrl } user { id avatarUrl webUrl username name } } } } _links { showPath } } } }
-
Result should be similar to below:
{ "data": { "mlModel": { "id": "gid://gitlab/Ml::Model/355", "description": null, "name": "gitlab_amazing_model", "versionCount": 1, "candidateCount": 0, "latestVersion": { "id": "gid://gitlab/Ml::ModelVersion/5002", "version": "1.0.0", "candidate": { "id": "gid://gitlab/Ml::Candidate/5016", "name": "crane-manatee-waterbuffalo-545", "iid": 1, "eid": "36ebccde-88c5-450c-9837-a11b454fa92e", "status": "running", "_links": { "showPath": "/toolbox/gitlab-smoke-tests/-/ml/candidates/1", "artifactPath": "/toolbox/gitlab-smoke-tests/-/packages/5029" }, "ciJob": { "id": "gid://gitlab/Ci::Build/1", "webPath": "/gitlab-org/gitlab-test/-/jobs/1", "name": "build:linux", "pipeline": { "id": "gid://gitlab/Ci::Pipeline/1", "mergeRequest": null, "user": null } } }, "_links": { "showPath": "/toolbox/gitlab-smoke-tests/-/ml/models/355/versions/5002" } } } } }