diff --git a/lib/api/entities/ml/mlflow/run.rb b/lib/api/entities/ml/mlflow/run.rb index 10e2434521d8cd12bf958b05d587b4d533dd5791..7d8ff8546beacdfd58ee09545ba88914f68faf7c 100644 --- a/lib/api/entities/ml/mlflow/run.rb +++ b/lib/api/entities/ml/mlflow/run.rb @@ -7,7 +7,7 @@ module Mlflow class Run < Grape::Entity expose :itself, using: RunInfo, as: :info expose :data do - expose :metrics, using: Metric + expose :latest_metrics, as: :metrics, using: Metric expose :params, using: KeyValue expose :metadata, as: :tags, using: KeyValue end diff --git a/spec/lib/api/entities/ml/mlflow/get_run_spec.rb b/spec/lib/api/entities/ml/mlflow/get_run_spec.rb index 513ecdeee3c6bf735196b723a7108b8e3bde48c4..a9e89b520f6af348514577dbe18d430d1268ff70 100644 --- a/spec/lib/api/entities/ml/mlflow/get_run_spec.rb +++ b/spec/lib/api/entities/ml/mlflow/get_run_spec.rb @@ -3,7 +3,8 @@ require 'spec_helper' RSpec.describe API::Entities::Ml::Mlflow::GetRun, feature_category: :mlops do - let_it_be(:candidate) { build(:ml_candidates, :with_metrics_and_params) } + let_it_be(:candidate) { create(:ml_candidates, :with_metrics_and_params) } + let_it_be(:metrics) { candidate.latest_metrics } subject { described_class.new(candidate).as_json } @@ -16,12 +17,12 @@ end it 'presents the metrics' do - expect(subject.dig(:run, :data, :metrics).size).to eq(candidate.metrics.size) + expect(subject.dig(:run, :data, :metrics).size).to eq(metrics.size) end it 'presents metrics correctly' do presented_metric = subject.dig(:run, :data, :metrics)[0] - metric = candidate.metrics[0] + metric = metrics[0] expect(presented_metric[:key]).to eq(metric.name) expect(presented_metric[:value]).to eq(metric.value) @@ -43,7 +44,7 @@ context 'when candidate has no metrics' do before do - allow(candidate).to receive(:metrics).and_return([]) + allow(candidate).to receive(:latest_metrics).and_return([]) end it 'returns empty data' do diff --git a/spec/lib/api/entities/ml/mlflow/run_spec.rb b/spec/lib/api/entities/ml/mlflow/run_spec.rb index 58148212a7b6fccbc215b7979625d31e1bdcc971..7fc5e0ba0665ffa9e366e1693f4db064b26e15fa 100644 --- a/spec/lib/api/entities/ml/mlflow/run_spec.rb +++ b/spec/lib/api/entities/ml/mlflow/run_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe API::Entities::Ml::Mlflow::Run do - let_it_be(:candidate) { build(:ml_candidates, :with_metrics_and_params) } + let_it_be(:candidate) { create(:ml_candidates, :with_metrics_and_params) } subject { described_class.new(candidate).as_json } @@ -12,12 +12,12 @@ end it 'presents the metrics' do - expect(subject.dig(:data, :metrics).size).to eq(candidate.metrics.size) + expect(subject.dig(:data, :metrics).size).to eq(candidate.latest_metrics.size) end it 'presents metrics correctly' do presented_metric = subject.dig(:data, :metrics)[0] - metric = candidate.metrics[0] + metric = candidate.latest_metrics[0] expect(presented_metric[:key]).to eq(metric.name) expect(presented_metric[:value]).to eq(metric.value) @@ -39,7 +39,7 @@ context 'when candidate has no metrics' do before do - allow(candidate).to receive(:metrics).and_return([]) + allow(candidate).to receive(:latest_metrics).and_return([]) end it 'returns empty data' do diff --git a/spec/lib/api/entities/ml/mlflow/search_runs_spec.rb b/spec/lib/api/entities/ml/mlflow/search_runs_spec.rb index 6ed59d454fa56b4c75e927c0c25af8efc5d0f013..7821b775b82663b10d61a6a5357025b7bb00a5a7 100644 --- a/spec/lib/api/entities/ml/mlflow/search_runs_spec.rb +++ b/spec/lib/api/entities/ml/mlflow/search_runs_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper' RSpec.describe API::Entities::Ml::Mlflow::SearchRuns, feature_category: :mlops do - let_it_be(:candidates) { [build_stubbed(:ml_candidates, :with_metrics_and_params), build_stubbed(:ml_candidates)] } - + let_it_be(:candidates) { [create(:ml_candidates, :with_metrics_and_params), create(:ml_candidates)] } + let_it_be(:metrics) { candidates[0].latest_metrics } let(:next_page_token) { 'abcdef' } subject { described_class.new({ candidates: candidates, next_page_token: next_page_token }).as_json } @@ -16,11 +16,11 @@ end it 'presents metrics', :aggregate_failures do - expect(subject.dig(:runs, 0, :data, :metrics).size).to eq(candidates[0].metrics.size) + expect(subject.dig(:runs, 0, :data, :metrics).size).to eq(metrics.size) expect(subject.dig(:runs, 1, :data, :metrics).size).to eq(0) presented_metric = subject.dig(:runs, 0, :data, :metrics, 0, :key) - metric = candidates[0].metrics[0].name + metric = metrics[0].name expect(presented_metric).to eq(metric) end