Load the metrics of the ML run page page by page

What does this MR do and why?

The Performance tab of an ML run shows every metric of the run, 50 metrics per page with the 100 newest values of each, when the ml_candidate_metrics_pagination feature flag is enabled. Today the page embeds only the 1,000 newest metric rows of a run, so on large runs the metrics logged earlier are missing. The table keeps today's layout, one row per metric and one column per logged step, for the loaded page.

Design notes
  • Stacked on !272105 (merged), which adds Query.mlCandidate, MlCandidate.latestMetrics and MlCandidateLatestMetric.history, and the ml_candidate_metrics_pagination flag (gitlab_com_derisk, rollout issue https://gitlab.com/gitlab-org/gitlab/-/work_items/640966). This MR reuses that flag. It targets the backend branch, so merge it after !272105 (merged).
  • app/assets/javascripts/ml/experiment_tracking/routes/candidates/show/candidate_detail.vue: with the flag enabled, the tab runs get_candidate_latest_metrics.query.graphql (latestMetrics(first: 50) with history(first: 100)) and pages with GlKeysetPagination. The API pages forward only, so the component keeps a stack of after cursors for Previous. The rows go through the same table code as the embedded list, so the table looks the same. The query carries @gl_introduced(version: "19.7.0") on mlCandidate.
  • app/controllers/projects/ml/candidates_controller.rb pushes the flag to the page with the project as the actor. Ml::CandidateDetailsPresenter skips the embedded metrics and metricsTruncated while the flag is enabled, so the page no longer reads the 1,000 newest rows. The truncation alert shows only with the flag disabled.
  • With the flag disabled, the page keeps today's embedded view and alert. MAX_EMBEDDED_METRICS, the embedded list and the alert go in the flag removal MR.
  • Not in this MR: a "load more" control for one metric's older values through metrics(name:, after:). history is a list without a cursor, so the first request of such a control would repeat the 100 values already shown. It needs its own design and would push this MR over the size budget.

References

Screenshots or screen recordings

A run with 55 metrics and 4 steps each:

Flag disabled (today) Flag enabled, page 1 Flag enabled, page 2
before after-page1 after-page2

How to set up and validate locally

  1. Check out this branch and log 55 metrics to a run in the Rails console:

    c = Ml::Candidate.last
    55.times { |i| 4.times { |s| Ml::CandidateMetric.create!(candidate: c, name: format('metric_%02d', i + 1), step: s, value: s) } }
    Feature.enable(:ml_candidate_metrics_pagination, c.project)
    Gitlab::Routing.url_helpers.project_ml_candidate_path(c.project, c.iid)
  2. Open the path from step 1 on http://gdk.test:3000 and select the Performance tab.

    Expect: metric_01 to metric_50, columns Step 0 to Step 3, and the Next button.

  3. Select Next.

    Expect: metric_51 to metric_55. Previous returns to the first page.

  4. Run Feature.disable(:ml_candidate_metrics_pagination, c.project) and reload the page.

    Expect: all 55 metrics in one table, as on master.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports

Loading
Loading