Commit 7c37d8c5 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'mo-update-ci-minutes-query' into 'master'

Fetch pending builds with denormalized ci minutes

See merge request gitlab-org/gitlab!66962
parents a87c8e2f 98e1eca7
......@@ -57,6 +57,10 @@ module Ci
false
end
def use_denormalized_minutes_data?
false
end
private
def running_builds_for_shared_runners
......
......@@ -40,6 +40,10 @@ module Ci
::Feature.enabled?(:ci_queueing_denormalize_shared_runners_information, runner, type: :development, default_enabled: :yaml)
end
def use_denormalized_minutes_data?
::Feature.enabled?(:ci_queueing_denormalize_ci_minutes_information, runner, type: :development, default_enabled: :yaml)
end
private
def builds_available_for_shared_runners
......@@ -83,3 +87,5 @@ module Ci
end
end
end
Ci::Queue::PendingBuildsStrategy.prepend_mod_with('Ci::Queue::PendingBuildsStrategy')
---
name: ci_queueing_denormalize_ci_minutes_information
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/66962
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/338290
milestone: '14.2'
type: development
group: 'group::pipeline execution'
default_enabled: false
......@@ -5,6 +5,10 @@ module EE
module PendingBuild
extend ActiveSupport::Concern
prepended do
scope :with_ci_minutes_available, -> { where(minutes_exceeded: false) }
end
class_methods do
extend ::Gitlab::Utils::Override
......
......@@ -19,6 +19,14 @@ module EE
# rubocop: disable CodeReuse/ActiveRecord
def enforce_minutes_based_on_cost_factors(relation)
if strategy.use_denormalized_minutes_data?
strategy.enforce_minutes_quota(relation)
else
enforce_minutes_using_legacy_data(relation)
end
end
def enforce_minutes_using_legacy_data(relation)
if strategy.use_denormalized_shared_runners_data?
# If shared runners information is denormalized then the query does not include the join
# with `projects` anymore, so we need to add it until we use denormalized ci minutes
......
# frozen_string_literal: true
module EE
module Ci
module Queue
module PendingBuildsStrategy
extend ActiveSupport::Concern
def enforce_minutes_quota(relation)
relation.with_ci_minutes_available
end
end
end
end
end
......@@ -8,6 +8,28 @@ RSpec.describe Ci::PendingBuild do
let(:build) { create(:ci_build, :created, pipeline: pipeline, project: project) }
describe 'scopes' do
describe '.with_ci_minutes_available' do
subject(:pending_builds) { described_class.with_ci_minutes_available }
context 'when pending builds does not have ci minutes available' do
let!(:pending_build) { create(:ci_pending_build, minutes_exceeded: true) }
it 'returns an empty collection of pending builds' do
expect(pending_builds).to be_empty
end
end
context 'when pending builds have ci minutes available' do
let!(:pending_build) { create(:ci_pending_build, minutes_exceeded: false) }
it 'returns matching pending builds' do
expect(pending_builds).to contain_exactly(pending_build)
end
end
end
end
describe '.upsert_from_build!' do
shared_examples 'ci minutes not available' do
it 'sets minutes_exceeded to true' do
......
......@@ -41,12 +41,30 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
is_expected.to be_kind_of(Ci::Build)
end
context 'with ci_queueing_denormalize_ci_minutes_information enabled' do
before do
stub_feature_flags(ci_queueing_denormalize_ci_minutes_information: true)
end
it { is_expected.to be_kind_of(Ci::Build) }
end
context 'with ci_queueing_denormalize_ci_minutes_information disabled' do
before do
stub_feature_flags(ci_queueing_denormalize_ci_minutes_information: false)
end
it { is_expected.to be_kind_of(Ci::Build) }
end
end
shared_examples 'does not return a build' do |runners_minutes_used|
before do
project.namespace.create_namespace_statistics(
shared_runners_seconds: runners_minutes_used * 60)
pending_build.reload
pending_build.create_queuing_entry!
end
context 'with traversal_ids enabled' do
......@@ -71,6 +89,22 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
is_expected.to be_kind_of(Ci::Build)
end
context 'with ci_queueing_denormalize_ci_minutes_information enabled' do
before do
stub_feature_flags(ci_queueing_denormalize_ci_minutes_information: true)
end
it { is_expected.to be_nil }
end
context 'with ci_queueing_denormalize_ci_minutes_information disabled' do
before do
stub_feature_flags(ci_queueing_denormalize_ci_minutes_information: false)
end
it { is_expected.to be_nil }
end
end
context 'when limit set at global level' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment