Skip to content
Snippets Groups Projects
Verified Commit 0130a312 authored by Marius Bobin's avatar Marius Bobin :two: Committed by GitLab
Browse files

Use p_ci_build_tags for jobs queuing

parent ccf61ca0
No related branches found
No related tags found
2 merge requests!170053Security patch upgrade alert: Only expose to admins 17-4,!166727Use p_ci_build_tags for jobs queuing
......@@ -103,6 +103,11 @@ class Build < Ci::Processable
partition_foreign_key: :partition_id,
inverse_of: :build
has_many :simple_tags,
class_name: 'Ci::Tag',
through: :tag_links,
source: :tag
Ci::JobArtifact.file_types.each_key do |key|
has_one :"job_artifacts_#{key}", ->(build) { in_partition(build).with_file_types([key]) },
class_name: 'Ci::JobArtifact',
......@@ -403,7 +408,7 @@ def supported_keyset_orderings
def self.build_matchers(project)
unique_params = [
:protected,
Arel.sql("(#{arel_tag_names_array.to_sql})")
Arel.sql("(#{arel_tag_names_array(project: project).to_sql})")
]
group(*unique_params).pluck('array_agg(id)', *unique_params).map do |values|
......@@ -420,6 +425,24 @@ def self.ids_in_merge_request(merge_request_id)
in_merge_request(merge_request_id).pluck(:id)
end
def self.arel_tag_names_array(context = :tags, project: nil)
return super(context) if Feature.disabled?(:use_new_queue_tags, project)
::Ci::BuildTag
.joins(:tag)
.where(::Ci::BuildTag.arel_table[:build_id].eq(arel_table[:id]))
.where(::Ci::BuildTag.arel_table[:partition_id].eq(arel_table[:partition_id]))
.select('COALESCE(array_agg(tags.name ORDER BY name), ARRAY[]::text[])')
end
def tags_ids_relation
if Feature.enabled?(:use_new_queue_tags, project)
simple_tags
else
tags
end
end
# A Ci::Bridge may transition to `canceling` as a result of strategy: :depend
# but only a Ci::Build will transition to `canceling`` via `.cancel`
def supports_canceling?
......
......@@ -19,8 +19,12 @@ def arel_tag_names_array(context = :tags)
end
def tags_ids
tags.limit(MAX_TAGS_IDS).order('id ASC').pluck(:id).tap do |ids|
tags_ids_relation.limit(MAX_TAGS_IDS).order('id ASC').pluck(:id).tap do |ids|
raise TooManyTagsError if ids.size >= MAX_TAGS_IDS
end
end
def tags_ids_relation
tags
end
end
---
name: use_new_queue_tags
feature_issue_url: https://gitlab.com/groups/gitlab-org/-/epics/14167
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/166727
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/492356
milestone: '17.5'
group: group::ci platform
type: gitlab_com_derisk
default_enabled: false
......@@ -464,6 +464,7 @@ builds:
- tag_links
- tag_taggings
- tags
- simple_tags
- security_scans
- dast_site_profiles_build
- dast_site_profile
......
......@@ -47,6 +47,7 @@
it { is_expected.to have_many(:report_results).with_foreign_key(:build_id) }
it { is_expected.to have_many(:pages_deployments).with_foreign_key(:ci_build_id) }
it { is_expected.to have_many(:tag_links).with_foreign_key(:build_id).class_name('Ci::BuildTag').inverse_of(:build) }
it { is_expected.to have_many(:simple_tags).class_name('Ci::Tag').through(:tag_links).source(:tag) }
it { is_expected.to have_one(:runner_manager).through(:runner_manager_build) }
it { is_expected.to have_one(:runner_session).with_foreign_key(:build_id) }
......@@ -5567,6 +5568,14 @@ def run_job_without_exception
it { expect(matchers).to all be_protected }
end
context 'with use_new_queue_tags disabled' do
before do
stub_feature_flags(use_new_queue_tags: false)
end
it { expect(matchers.map(&:tag_list)).to match_array([[], %w[tag1 tag2]]) }
end
end
end
......@@ -6113,4 +6122,22 @@ def run_job_without_exception
expect(build.source).to eq('scan_execution_policy')
end
end
describe '#tags_ids_relation' do
let(:tag_list) { %w[ruby postgres docker] }
before do
build.update!(tag_list: tag_list)
end
it { expect(build.tags_ids_relation.pluck(:name)).to match_array(tag_list) }
context 'with use_new_queue_tags disabled' do
before do
stub_feature_flags(use_new_queue_tags: false)
end
it { expect(build.tags_ids_relation.pluck(:name)).to match_array(tag_list) }
end
end
end
......@@ -89,7 +89,7 @@
let(:ignore_accessors) do
%i[type namespace lock_version target_url base_tags trace_sections
commit_id deployment erased_by_id project_id project_mirror
runner_id tag_taggings taggings tags tag_links trigger_request_id
runner_id tag_taggings taggings tags tag_links simple_tags trigger_request_id
user_id auto_canceled_by_id retried failure_reason
sourced_pipelines sourced_pipeline artifacts_file_store artifacts_metadata_store
metadata runner_manager_build runner_manager runner_session trace_chunks
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment