Commit bdef4c11 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'feature/gb/register-job-service-without-db-cross-joins' into 'master'

Disallow database cross-joins in RegisterJobService

See merge request gitlab-org/gitlab!71545
parents 2697d4ae c41bc571
......@@ -103,7 +103,6 @@ module Ci
# rubocop: disable CodeReuse/ActiveRecord
def each_build(params, &blk)
::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/339429') do
queue = ::Ci::Queue::BuildQueueService.new(runner)
builds = begin
......@@ -139,7 +138,6 @@ module Ci
build_ids.each { |build_id| yield Ci::Build.find(build_id) }
end
end
# rubocop: enable CodeReuse/ActiveRecord
def retrieve_queue(queue_query_proc)
......
......@@ -55,6 +55,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
stub_feature_flags(ci_queueing_denormalize_ci_minutes_information: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
it { is_expected.to be_kind_of(Ci::Build) }
end
end
......@@ -103,6 +109,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
stub_feature_flags(ci_queueing_denormalize_ci_minutes_information: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
it { is_expected.to be_nil }
end
end
......@@ -307,6 +319,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
stub_feature_flags(ci_pending_builds_queue_source: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
include_examples 'namespace minutes quota'
end
......@@ -328,6 +346,12 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
stub_feature_flags(ci_queueing_denormalize_shared_runners_information: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
include_examples 'namespace minutes quota'
end
end
......
......@@ -124,7 +124,10 @@ module Gitlab
strong_memoize(:runner_project) do
next unless runner&.project_type?
projects = runner.projects.take(2) # rubocop: disable CodeReuse/ActiveRecord
projects = ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/342147') do
runner.projects.take(2) # rubocop: disable CodeReuse/ActiveRecord
end
projects.first if projects.one?
end
end
......
......@@ -87,19 +87,25 @@ module Ci
end
context 'for specific runner' do
context 'with FF disabled' do
context 'with tables decoupling disabled' do
before do
stub_feature_flags(
ci_pending_builds_project_runners_decoupling: false,
ci_queueing_builds_enabled_checks: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
it 'does not pick a build' do
expect(execute(specific_runner)).to be_nil
end
end
context 'with FF enabled' do
context 'with tables decoupling enabled' do
before do
stub_feature_flags(
ci_pending_builds_project_runners_decoupling: true,
......@@ -266,17 +272,23 @@ module Ci
context 'and uses project runner' do
let(:build) { execute(specific_runner) }
context 'with FF disabled' do
context 'with tables decoupling disabled' do
before do
stub_feature_flags(
ci_pending_builds_project_runners_decoupling: false,
ci_queueing_builds_enabled_checks: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
it { expect(build).to be_nil }
end
context 'with FF enabled' do
context 'with tables decoupling enabled' do
before do
stub_feature_flags(
ci_pending_builds_project_runners_decoupling: true,
......@@ -791,6 +803,12 @@ module Ci
stub_feature_flags(ci_queueing_denormalize_shared_runners_information: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
include_examples 'handles runner assignment'
end
......@@ -807,6 +825,12 @@ module Ci
stub_feature_flags(ci_queueing_denormalize_tags_information: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
include_examples 'handles runner assignment'
end
......@@ -815,6 +839,12 @@ module Ci
stub_feature_flags(ci_queueing_denormalize_namespace_traversal_ids: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
include_examples 'handles runner assignment'
end
end
......@@ -824,6 +854,12 @@ module Ci
stub_feature_flags(ci_pending_builds_queue_source: false)
end
around do |example|
allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/332952') do
example.run
end
end
include_examples 'handles runner assignment'
end
end
......
......@@ -81,7 +81,6 @@
- "./spec/presenters/ci/build_runner_presenter_spec.rb"
- "./spec/presenters/ci/pipeline_presenter_spec.rb"
- "./spec/presenters/packages/detail/package_presenter_spec.rb"
- "./spec/requests/api/ci/runner/jobs_request_post_spec.rb"
- "./spec/requests/api/ci/runner/runners_post_spec.rb"
- "./spec/requests/api/ci/runners_spec.rb"
- "./spec/requests/api/commit_statuses_spec.rb"
......@@ -105,7 +104,6 @@
- "./spec/services/ci/job_artifacts/destroy_all_expired_service_spec.rb"
- "./spec/services/ci/job_artifacts/destroy_associations_service_spec.rb"
- "./spec/services/ci/job_artifacts/destroy_batch_service_spec.rb"
- "./spec/services/ci/register_job_service_spec.rb"
- "./spec/services/deployments/older_deployments_drop_service_spec.rb"
- "./spec/services/environments/stop_service_spec.rb"
- "./spec/services/merge_requests/add_todo_when_build_fails_service_spec.rb"
......
......@@ -64,6 +64,10 @@ module Database
ensure
ActiveSupport::Notifications.unsubscribe(subscriber) if subscriber
end
def allow_cross_joins_across_databases(url:, &block)
::Gitlab::Database.allow_cross_joins_across_databases(url: url, &block)
end
end
module GitlabDatabaseMixin
......
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