Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-09-07 18:44:55 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-09-07 18:44:55 +0300
commit280be6314fd87fd5bae773159a8922a265992cf1 (patch)
treeab9ca2037118f463bfe5aa4d06f3e65f761bf91e
parentf0a2a6e328ab823ae6ba9eda7b4198b6ef7954c7 (diff)
Add latest changes from gitlab-org/gitlab@16-2-stable-ee
-rw-r--r--app/services/ci/create_downstream_pipeline_service.rb3
-rw-r--r--app/workers/all_queues.yml9
-rw-r--r--app/workers/ci/initialize_pipelines_iid_sequence_worker.rb19
-rw-r--r--config/sidekiq_queues.yml2
-rw-r--r--lib/gitlab/event_store.rb1
-rw-r--r--spec/services/ci/create_downstream_pipeline_service_spec.rb18
-rw-r--r--spec/workers/ci/initialize_pipelines_iid_sequence_worker_spec.rb38
7 files changed, 90 insertions, 0 deletions
diff --git a/app/services/ci/create_downstream_pipeline_service.rb b/app/services/ci/create_downstream_pipeline_service.rb
index b281f942a14..e38f5c98814 100644
--- a/app/services/ci/create_downstream_pipeline_service.rb
+++ b/app/services/ci/create_downstream_pipeline_service.rb
@@ -42,6 +42,9 @@ module Ci
log_downstream_pipeline_creation(downstream_pipeline)
update_bridge_status!(@bridge, downstream_pipeline)
+ rescue StandardError => e
+ @bridge.reset.drop!(:data_integrity_failure)
+ raise e
end
private
diff --git a/app/workers/all_queues.yml b/app/workers/all_queues.yml
index 6f6fd9ddb65..64c9f00a6aa 100644
--- a/app/workers/all_queues.yml
+++ b/app/workers/all_queues.yml
@@ -2496,6 +2496,15 @@
:weight: 1
:idempotent: true
:tags: []
+- :name: ci_initialize_pipelines_iid_sequence
+ :worker_name: Ci::InitializePipelinesIidSequenceWorker
+ :feature_category: :continuous_integration
+ :has_external_dependencies: false
+ :urgency: :low
+ :resource_boundary: :unknown
+ :weight: 1
+ :idempotent: true
+ :tags: []
- :name: ci_job_artifacts_expire_project_build_artifacts
:worker_name: Ci::JobArtifacts::ExpireProjectBuildArtifactsWorker
:feature_category: :build_artifacts
diff --git a/app/workers/ci/initialize_pipelines_iid_sequence_worker.rb b/app/workers/ci/initialize_pipelines_iid_sequence_worker.rb
new file mode 100644
index 00000000000..95b58814e08
--- /dev/null
+++ b/app/workers/ci/initialize_pipelines_iid_sequence_worker.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Ci
+ class InitializePipelinesIidSequenceWorker
+ include Gitlab::EventStore::Subscriber
+
+ data_consistency :always
+ feature_category :continuous_integration
+ idempotent!
+
+ def handle_event(event)
+ Project.find_by_id(event.data[:project_id]).try do |project|
+ next if project.internal_ids.ci_pipelines.any?
+
+ ::Ci::Pipeline.track_project_iid!(project, 0)
+ end
+ end
+ end
+end
diff --git a/config/sidekiq_queues.yml b/config/sidekiq_queues.yml
index 7f05b8af7bf..61b0ab75267 100644
--- a/config/sidekiq_queues.yml
+++ b/config/sidekiq_queues.yml
@@ -123,6 +123,8 @@
- 1
- - ci_delete_objects
- 1
+- - ci_initialize_pipelines_iid_sequence
+ - 1
- - ci_job_artifacts_expire_project_build_artifacts
- 1
- - ci_llm_generate_config
diff --git a/lib/gitlab/event_store.rb b/lib/gitlab/event_store.rb
index ce71ee594f2..474aac8073e 100644
--- a/lib/gitlab/event_store.rb
+++ b/lib/gitlab/event_store.rb
@@ -64,6 +64,7 @@ module Gitlab
store.subscribe ::Ml::ExperimentTracking::AssociateMlCandidateToPackageWorker,
to: ::Packages::PackageCreatedEvent,
if: -> (event) { ::Ml::ExperimentTracking::AssociateMlCandidateToPackageWorker.handles_event?(event) }
+ store.subscribe ::Ci::InitializePipelinesIidSequenceWorker, to: ::Projects::ProjectCreatedEvent
end
private_class_method :configure!
end
diff --git a/spec/services/ci/create_downstream_pipeline_service_spec.rb b/spec/services/ci/create_downstream_pipeline_service_spec.rb
index 6da6ec3379a..152f408c9f8 100644
--- a/spec/services/ci/create_downstream_pipeline_service_spec.rb
+++ b/spec/services/ci/create_downstream_pipeline_service_spec.rb
@@ -894,4 +894,22 @@ RSpec.describe Ci::CreateDownstreamPipelineService, '#execute', feature_category
end
end
end
+
+ context 'when downstream pipeline creation fails with unexpected errors', :aggregate_failures do
+ before do
+ downstream_project.add_developer(user)
+
+ allow(::Ci::CreatePipelineService).to receive(:new)
+ .and_raise(RuntimeError, 'undefined failure')
+ end
+
+ it 'drops the bridge without creating a pipeline' do
+ expect { subject }
+ .to raise_error(RuntimeError, /undefined failure/)
+ .and change { Ci::Pipeline.count }.by(0)
+
+ expect(bridge.reload).to be_failed
+ expect(bridge.failure_reason).to eq('data_integrity_failure')
+ end
+ end
end
diff --git a/spec/workers/ci/initialize_pipelines_iid_sequence_worker_spec.rb b/spec/workers/ci/initialize_pipelines_iid_sequence_worker_spec.rb
new file mode 100644
index 00000000000..fcf57e21ac9
--- /dev/null
+++ b/spec/workers/ci/initialize_pipelines_iid_sequence_worker_spec.rb
@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::InitializePipelinesIidSequenceWorker, feature_category: :continuous_integration do
+ let_it_be_with_refind(:project) { create(:project) }
+
+ let(:project_created_event) do
+ Projects::ProjectCreatedEvent.new(
+ data: {
+ project_id: project.id,
+ namespace_id: project.namespace_id,
+ root_namespace_id: project.root_namespace.id
+ })
+ end
+
+ it_behaves_like 'subscribes to event' do
+ let(:event) { project_created_event }
+ end
+
+ it 'creates an internal_ids sequence for ci_pipelines' do
+ consume_event(subscriber: described_class, event: project_created_event)
+
+ expect(project.internal_ids.ci_pipelines).to be_any
+ expect(project.internal_ids.ci_pipelines).to all be_persisted
+ end
+
+ context 'when the internal_ids sequence is already initialized' do
+ before do
+ create_list(:ci_pipeline, 2, project: project)
+ end
+
+ it 'does not reset the sequence' do
+ expect { consume_event(subscriber: described_class, event: project_created_event) }
+ .not_to change { project.internal_ids.ci_pipelines.pluck(:last_value) }
+ end
+ end
+end