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