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 ...@@ -7,7 +7,7 @@ module Ci
Ci::ExpirePipelineCacheService.new.execute(pipeline, delete: true) 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! 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,13 +52,11 @@ module EE ...@@ -52,13 +52,11 @@ module EE
state_machine :status do state_machine :status do
after_transition any => [:success, :failed, :canceled] do |build| after_transition any => [:success, :failed, :canceled] do |build|
build.run_after_commit do 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) ::Ci::Minutes::UpdateBuildMinutesService.new(build.project, nil).execute(build)
end end
end end
end end
end end
end
override :variables override :variables
def variables def variables
......
...@@ -21,11 +21,7 @@ module Ci ...@@ -21,11 +21,7 @@ module Ci
private private
def update_minutes(consumption) 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) ::Ci::Minutes::UpdateProjectAndNamespaceUsageWorker.perform_async(consumption, project.id, namespace.id)
else
::Ci::Minutes::UpdateProjectAndNamespaceUsageService.new(project.id, namespace.id).execute(consumption)
end
end end
def compare_with_live_consumption(build, consumption) def compare_with_live_consumption(build, consumption)
......
...@@ -9,10 +9,6 @@ module EE ...@@ -9,10 +9,6 @@ module EE
# and enqueueing duplicate jobs. # and enqueueing duplicate jobs.
super 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? unless build.project.requirements.empty?
RequirementsManagement::ProcessRequirementsReportsWorker.perform_async(build.id) RequirementsManagement::ProcessRequirementsReportsWorker.perform_async(build.id)
end end
......
...@@ -92,7 +92,6 @@ RSpec.describe Ci::Build do ...@@ -92,7 +92,6 @@ RSpec.describe Ci::Build do
it_behaves_like 'depends on runner presence and type' it_behaves_like 'depends on runner presence and type'
end end
shared_context 'updates minutes' do
context 'updates pipeline minutes' do context 'updates pipeline minutes' do
let(:job) { create(:ci_build, :running, pipeline: pipeline) } let(:job) { create(:ci_build, :running, pipeline: pipeline) }
...@@ -105,19 +104,6 @@ RSpec.describe Ci::Build do ...@@ -105,19 +104,6 @@ RSpec.describe Ci::Build do
end end
end end
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 describe '#variables' do
subject { job.variables } subject { job.variables }
......
...@@ -18,7 +18,7 @@ RSpec.describe Ci::Minutes::UpdateBuildMinutesService do ...@@ -18,7 +18,7 @@ RSpec.describe Ci::Minutes::UpdateBuildMinutesService do
subject { described_class.new(project, nil).execute(build) } 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 shared_examples 'new tracking matches legacy tracking' do
it 'stores the same information in both legacy and new tracking' do it 'stores the same information in both legacy and new tracking' do
subject subject
...@@ -253,18 +253,4 @@ RSpec.describe Ci::Minutes::UpdateBuildMinutesService do ...@@ -253,18 +253,4 @@ RSpec.describe Ci::Minutes::UpdateBuildMinutesService do
it_behaves_like 'does nothing' it_behaves_like 'does nothing'
end end
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 end
...@@ -27,29 +27,6 @@ RSpec.describe Ci::BuildFinishedWorker do ...@@ -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 allow_any_instance_of(EE::Project).to receive(:shared_runners_minutes_limit_enabled?).and_return(true) # rubocop:disable RSpec/AnyInstanceOf
end 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 it 'tracks secure scans' do
expect(::Security::TrackSecureScansWorker).to receive(:perform_async) expect(::Security::TrackSecureScansWorker).to receive(:perform_async)
......
...@@ -437,8 +437,6 @@ RSpec.describe 'Pipeline', :js do ...@@ -437,8 +437,6 @@ RSpec.describe 'Pipeline', :js do
end end
end end
shared_context 'delete pipeline' do
context 'deleting pipeline' do
context 'when user can not delete' do context 'when user can not delete' do
before do before do
visit_pipeline visit_pipeline
...@@ -462,20 +460,6 @@ RSpec.describe 'Pipeline', :js do ...@@ -462,20 +460,6 @@ RSpec.describe 'Pipeline', :js do
expect(current_path).to eq(project_pipelines_path(project)) expect(current_path).to eq(project_pipelines_path(project))
end end
end end
end
end
context 'when cancel_pipelines_prior_to_destroy is enabled' do
include_context 'delete pipeline'
end
context 'when cancel_pipelines_prior_to_destroy is disabled' do
before do
stub_feature_flags(cancel_pipelines_prior_to_destroy: false)
end
include_context 'delete pipeline'
end
context 'when pipeline ref does not exist in repository anymore' do context 'when pipeline ref does not exist in repository anymore' do
let(:pipeline) do let(:pipeline) do
......
...@@ -78,18 +78,6 @@ RSpec.describe ::Ci::DestroyPipelineService do ...@@ -78,18 +78,6 @@ RSpec.describe ::Ci::DestroyPipelineService do
subject subject
end 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
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