Skip to content

Initial GraphQL mappings for Model registry

What does this MR do and why?

Adds the initial support for GraphQL in Model registry

How to set up and validate locally

  1. on rails console create a few models and model versions, don't enable feature flag yet

    p = Project.find_by(id: 20) # or whatever project you want to use for testing
    model = Ml::FindOrCreateModelService.new(p, "model_1").execute
    
    3.times { |i| Ml::FindOrCreateModelVersionService.new(p, { model_name: "model_1", version: "1.2.#{i}" }).execute }
  2. Navigate to http://localhost:3000/-/graphql-explorer

  3. Type the following query:

    {
      mlModel(id: "gid://gitlab/Ml::Model/<id>") {
        versions {
          count
          nodes {
            id
       	   version
            _links {
              showPath
            }
          }
       }
    }
  4. Result should be null. Enable the feature flag:

    Feature.enable("model_registry")
  5. Repeat the query, you should see data now

Database

(local explains, since I have more data locally)

SELECT "ml_models".* FROM "ml_models" WHERE "ml_models"."id" = 24
Index Scan using ml_models_pkey on ml_models  (cost=0.28..2.30 rows=1 width=40) (actual time=0.165..0.166 rows=1 loops=1)
  Index Cond: (id = 24)
SELECT COUNT(*) FROM "ml_model_versions" WHERE "ml_model_versions"."model_id" = 24
Aggregate  (cost=1.34..1.35 rows=1 width=8) (actual time=0.332..0.333 rows=1 loops=1)
  ->  Index Only Scan using unique_ml_model_versions_on_model_id_and_id on ml_model_versions  (cost=0.28..1.33 rows=3 width=0) (actual time=0.324..0.325 rows=3 loops=1)
        Index Cond: (model_id = 24)
SELECT
    "ml_model_versions".*
FROM
    "ml_model_versions"
WHERE
    "ml_model_versions"."model_id" = 24
ORDER BY
    "ml_model_versions"."id" DESC
LIMIT 101
Limit  (cost=0.28..3.21 rows=3 width=88) (actual time=0.020..0.023 rows=3 loops=1)
  ->  Index Scan using unique_ml_model_versions_on_model_id_and_id on ml_model_versions  (cost=0.28..3.21 rows=3 width=88) (actual time=0.019..0.021 rows=3 loops=1)
        Index Cond: (model_id = 24)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #428900 (closed)

Edited by Jonas Larsen

Merge request reports