Commit f5579124 authored by Thong Kuah's avatar Thong Kuah

Merge branch 'philipcunningham-cleanup-feature-flag-dast-cross-database-350051' into 'master'

Remove dast_sharded_cloned_ci_builds feature flag

See merge request gitlab-org/gitlab!80133
parents dcbd79af dc522c88
# frozen_string_literal: true
module Ci
class CopyCrossDatabaseAssociationsService
def execute(old_build, new_build)
ServiceResponse.success
end
end
end
Ci::CopyCrossDatabaseAssociationsService.prepend_mod_with('Ci::CopyCrossDatabaseAssociationsService')
...@@ -40,6 +40,8 @@ module Ci ...@@ -40,6 +40,8 @@ module Ci
new_build = clone_build(build) new_build = clone_build(build)
new_build.run_after_commit do new_build.run_after_commit do
::Ci::CopyCrossDatabaseAssociationsService.new.execute(build, new_build)
::Deployments::CreateForBuildService.new.execute(new_build) ::Deployments::CreateForBuildService.new.execute(new_build)
::MergeRequests::AddTodoWhenBuildFailsService ::MergeRequests::AddTodoWhenBuildFailsService
...@@ -70,9 +72,7 @@ module Ci ...@@ -70,9 +72,7 @@ module Ci
def check_assignable_runners!(build); end def check_assignable_runners!(build); end
def clone_build(build) def clone_build(build)
project.builds.new(build_attributes(build)).tap do |new_build| project.builds.new(build_attributes(build))
yield(new_build) if block_given?
end
end end
def build_attributes(build) def build_attributes(build)
......
---
name: dast_sharded_cloned_ci_builds
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78164
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/351980
milestone: '14.8'
type: development
group: group::dynamic analysis
default_enabled: true
# frozen_string_literal: true
module EE
module Ci
module CopyCrossDatabaseAssociationsService
extend ::Gitlab::Utils::Override
override :execute
def execute(old_build, new_build)
response = AppSec::Dast::Builds::AssociateService.new(
ci_build_id: new_build.id,
dast_site_profile_id: old_build.dast_site_profile&.id,
dast_scanner_profile_id: old_build.dast_scanner_profile&.id
).execute
response.tap do
new_build.reset.drop! if response.error?
end
end
end
end
end
...@@ -16,31 +16,12 @@ module EE ...@@ -16,31 +16,12 @@ module EE
override :extra_accessors override :extra_accessors
def extra_accessors def extra_accessors
return %i[secrets].freeze if ::Feature.enabled?(:dast_sharded_cloned_ci_builds, default_enabled: :yaml) %i[secrets].freeze
%i[dast_site_profile dast_scanner_profile secrets].freeze
end end
end end
private private
override :clone_build
def clone_build(build)
super do |new_build|
if ::Feature.enabled?(:dast_sharded_cloned_ci_builds, default_enabled: :yaml)
new_build.run_after_commit do
response = AppSec::Dast::Builds::AssociateService.new(
ci_build_id: new_build.id,
dast_site_profile_id: build.dast_site_profile&.id,
dast_scanner_profile_id: build.dast_scanner_profile&.id
).execute
new_build.reset.drop! if response.error?
end
end
end
end
override :check_access! override :check_access!
def check_access!(build) def check_access!(build)
super super
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::CopyCrossDatabaseAssociationsService do
let_it_be(:project) { create(:project) }
let_it_be(:dast_site_profile) { create(:dast_site_profile, project: project) }
let_it_be(:dast_scanner_profile) { create(:dast_scanner_profile, project: project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:old_build) do
create(:ci_build, pipeline: pipeline).tap do |build|
build.update!(dast_site_profile: dast_site_profile, dast_scanner_profile: dast_scanner_profile)
end
end
let(:new_build) { create(:ci_build, pipeline: pipeline) }
describe '#execute' do
subject(:execute) { described_class.new.execute(old_build, new_build) }
context 'failure' do
before do
allow_next_instance_of(AppSec::Dast::Builds::AssociateService) do |instance|
allow(instance).to receive(:execute).and_return(ServiceResponse.error(message: 'oops'))
end
end
it 'returns an error response' do
expect(execute).to have_attributes(status: :error)
end
it 'drops the build' do
execute
expect(new_build.reload).to be_failed
end
end
context 'success' do
it 'returns a success response' do
expect(execute).to be_success
end
it 'clones the profile associations', :aggregate_failures do
execute
expect(new_build.dast_site_profile).to eq(dast_site_profile)
expect(new_build.dast_scanner_profile).to eq(dast_scanner_profile)
expect(new_build).not_to be_failed
end
end
end
end
...@@ -32,37 +32,16 @@ RSpec.describe Ci::RetryBuildService do ...@@ -32,37 +32,16 @@ RSpec.describe Ci::RetryBuildService do
build.update!(dast_site_profile: dast_site_profile, dast_scanner_profile: dast_scanner_profile) build.update!(dast_site_profile: dast_site_profile, dast_scanner_profile: dast_scanner_profile)
end end
context 'failure' do it 'clones the profile associations', :aggregate_failures do
it 'drops the build' do expect_next_instance_of(Ci::CopyCrossDatabaseAssociationsService) do |service|
allow_next_instance_of(AppSec::Dast::Builds::AssociateService) do |instance| expect(service).to receive(:execute).with(build, Ci::Build).and_call_original
allow(instance).to receive(:execute).and_return(ServiceResponse.error(message: 'oops'))
end
expect(new_build.reload).to be_failed
end end
end
context 'success' do new_build.reload
it 'clones the profile associations', :aggregate_failures do
new_build.reload
expect(new_build.dast_site_profile).to eq(dast_site_profile)
expect(new_build.dast_scanner_profile).to eq(dast_scanner_profile)
expect(new_build).not_to be_failed
end
end
context 'when dast_sharded_cloned_ci_builds is disabled' do expect(new_build.dast_site_profile).to eq(dast_site_profile)
before do expect(new_build.dast_scanner_profile).to eq(dast_scanner_profile)
stub_feature_flags(dast_sharded_cloned_ci_builds: false) expect(new_build).not_to be_failed
end
it 'clones the profile associations', :aggregate_failures do
::Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification.allow_cross_database_modification_within_transaction(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/350051') do
expect(new_build.dast_site_profile).to eq(dast_site_profile)
expect(new_build.dast_scanner_profile).to eq(dast_scanner_profile)
end
end
end end
end end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::CopyCrossDatabaseAssociationsService do
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:old_build) { create(:ci_build, pipeline: pipeline) }
let_it_be(:new_build) { create(:ci_build, pipeline: pipeline) }
subject(:execute) { described_class.new.execute(old_build, new_build) }
describe '#execute' do
it 'returns a success response' do
expect(execute).to be_success
end
end
end
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