Commit d738b594 authored by Allison Browne's avatar Allison Browne

Cancel pipelines before deleting

Remove feature flag cancel_pipelines_prior_to_destroy
which will cancel pipelines and accumulate minutes
on delete

Changelog: added
parent 1ddc8297
......@@ -7,7 +7,7 @@ module Ci
Ci::ExpirePipelineCacheService.new.execute(pipeline, delete: true)
pipeline.cancel_running if pipeline.cancelable? && ::Feature.enabled?(:cancel_pipelines_prior_to_destroy, pipeline.project, default_enabled: :yaml)
pipeline.cancel_running if pipeline.cancelable?
pipeline.reset.destroy!
......
---
name: cancel_pipelines_prior_to_destroy
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65586
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/335338
milestone: '14.1'
type: development
group: group::continuous integration
default_enabled: false
......@@ -52,9 +52,7 @@ module EE
state_machine :status do
after_transition any => [:success, :failed, :canceled] do |build|
build.run_after_commit do
if ::Feature.enabled?(:cancel_pipelines_prior_to_destroy, build.project, default_enabled: :yaml)
::Ci::Minutes::UpdateBuildMinutesService.new(build.project, nil).execute(build)
end
::Ci::Minutes::UpdateBuildMinutesService.new(build.project, nil).execute(build)
end
end
end
......
......@@ -21,11 +21,7 @@ module Ci
private
def update_minutes(consumption)
if ::Feature.enabled?(:cancel_pipelines_prior_to_destroy, project, default_enabled: :yaml)
::Ci::Minutes::UpdateProjectAndNamespaceUsageWorker.perform_async(consumption, project.id, namespace.id)
else
::Ci::Minutes::UpdateProjectAndNamespaceUsageService.new(project.id, namespace.id).execute(consumption)
end
::Ci::Minutes::UpdateProjectAndNamespaceUsageWorker.perform_async(consumption, project.id, namespace.id)
end
def compare_with_live_consumption(build, consumption)
......
......@@ -9,10 +9,6 @@ module EE
# and enqueueing duplicate jobs.
super
unless ::Feature.enabled?(:cancel_pipelines_prior_to_destroy, build.project, default_enabled: :yaml)
::Ci::Minutes::UpdateBuildMinutesService.new(build.project, nil).execute(build)
end
unless build.project.requirements.empty?
RequirementsManagement::ProcessRequirementsReportsWorker.perform_async(build.id)
end
......
......@@ -92,33 +92,19 @@ RSpec.describe Ci::Build do
it_behaves_like 'depends on runner presence and type'
end
shared_context 'updates minutes' do
context 'updates pipeline minutes' do
let(:job) { create(:ci_build, :running, pipeline: pipeline) }
context 'updates pipeline minutes' do
let(:job) { create(:ci_build, :running, pipeline: pipeline) }
%w(success drop cancel).each do |event|
it "for event #{event}" do
expect(Ci::Minutes::UpdateBuildMinutesService)
.to receive(:new).and_call_original
%w(success drop cancel).each do |event|
it "for event #{event}" do
expect(Ci::Minutes::UpdateBuildMinutesService)
.to receive(:new).and_call_original
job.public_send(event)
end
job.public_send(event)
end
end
end
context 'when cancel_pipelines_prior_to_destroy is enabled' do
include_context 'updates minutes'
end
context 'when cancel_pipelines_prior_to_destroy is disabled', :sidekiq_inline do
before do
stub_feature_flags(cancel_pipelines_prior_to_destroy: false)
end
include_context 'updates minutes'
end
describe '#variables' do
subject { job.variables }
......
......@@ -18,7 +18,7 @@ RSpec.describe Ci::Minutes::UpdateBuildMinutesService do
subject { described_class.new(project, nil).execute(build) }
shared_examples 'executes service' do
describe '#execute', :sidekiq_inline do
shared_examples 'new tracking matches legacy tracking' do
it 'stores the same information in both legacy and new tracking' do
subject
......@@ -253,18 +253,4 @@ RSpec.describe Ci::Minutes::UpdateBuildMinutesService do
it_behaves_like 'does nothing'
end
end
describe '#execute' do
context 'when cancel_pipelines_prior_to_destroy enabled', :sidekiq_inline do
include_examples 'executes service'
end
context 'when cancel_pipelines_prior_to_destroy disabled' do
before do
stub_feature_flags(cancel_pipelines_prior_to_destroy: false)
end
include_examples 'executes service'
end
end
end
......@@ -27,29 +27,6 @@ RSpec.describe Ci::BuildFinishedWorker do
allow_any_instance_of(EE::Project).to receive(:shared_runners_minutes_limit_enabled?).and_return(true) # rubocop:disable RSpec/AnyInstanceOf
end
context 'when cancel_pipelines_prior_to_destroy is disabled' do
before do
stub_feature_flags(cancel_pipelines_prior_to_destroy: false)
end
it 'updates the project stats' do
expect { subject }.to change { project_stats.reload.shared_runners_seconds }
end
it 'updates the namespace stats' do
expect { subject }.to change { namespace_stats.reload.shared_runners_seconds }
end
it 'notifies the owners of Groups' do
namespace.update_attribute(:shared_runners_minutes_limit, 2000)
namespace_stats.update_attribute(:shared_runners_seconds, 2100 * 60)
expect(CiMinutesUsageMailer).to receive(:notify).once.with(namespace, [namespace.owner.email]).and_return(spy)
subject
end
end
it 'tracks secure scans' do
expect(::Security::TrackSecureScansWorker).to receive(:perform_async)
......
......@@ -437,44 +437,28 @@ RSpec.describe 'Pipeline', :js do
end
end
shared_context 'delete pipeline' do
context 'deleting pipeline' do
context 'when user can not delete' do
before do
visit_pipeline
end
it { expect(page).not_to have_button('Delete') }
end
context 'when deleting' do
before do
group.add_owner(user)
visit_pipeline
click_button 'Delete'
click_button 'Delete pipeline'
end
it 'redirects to pipeline overview page', :sidekiq_inline do
expect(page).to have_content('The pipeline has been deleted')
expect(current_path).to eq(project_pipelines_path(project))
end
end
context 'when user can not delete' do
before do
visit_pipeline
end
end
context 'when cancel_pipelines_prior_to_destroy is enabled' do
include_context 'delete pipeline'
it { expect(page).not_to have_button('Delete') }
end
context 'when cancel_pipelines_prior_to_destroy is disabled' do
context 'when deleting' do
before do
stub_feature_flags(cancel_pipelines_prior_to_destroy: false)
group.add_owner(user)
visit_pipeline
click_button 'Delete'
click_button 'Delete pipeline'
end
include_context 'delete pipeline'
it 'redirects to pipeline overview page', :sidekiq_inline do
expect(page).to have_content('The pipeline has been deleted')
expect(current_path).to eq(project_pipelines_path(project))
end
end
context 'when pipeline ref does not exist in repository anymore' do
......
......@@ -78,18 +78,6 @@ RSpec.describe ::Ci::DestroyPipelineService do
subject
end
context 'when cancel_pipelines_prior_to_destroy is disabled' do
before do
stub_feature_flags(cancel_pipelines_prior_to_destroy: false)
end
it "doesn't cancel the pipeline" do
expect(pipeline).not_to receive(:cancel_running)
subject
end
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