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>2021-09-08 18:09:10 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-08 18:09:10 +0300
commita74cb0526c088bf5868f5aba1aec949800c1d641 (patch)
treee30827d0d46a9b2f35fc86bb9deaa8876b362ba7 /lib/gitlab
parente2f984e14e1fd34e5105669c4306388019e6b5b6 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab')
-rw-r--r--lib/gitlab/ci/pipeline/chain/command.rb2
-rw-r--r--lib/gitlab/ci/pipeline/chain/config/content/external_project.rb20
-rw-r--r--lib/gitlab/database/migration.rb17
-rw-r--r--lib/gitlab/database/migrations/lock_retry_mixin.rb43
4 files changed, 79 insertions, 3 deletions
diff --git a/lib/gitlab/ci/pipeline/chain/command.rb b/lib/gitlab/ci/pipeline/chain/command.rb
index 9584272a530..c9bc4ec411d 100644
--- a/lib/gitlab/ci/pipeline/chain/command.rb
+++ b/lib/gitlab/ci/pipeline/chain/command.rb
@@ -88,7 +88,7 @@ module Gitlab
end
def observe_step_duration(step_class, duration)
- if Feature.enabled?(:ci_pipeline_creation_step_duration_tracking, default_enabled: :yaml)
+ if Feature.enabled?(:ci_pipeline_creation_step_duration_tracking, type: :ops, default_enabled: :yaml)
metrics.pipeline_creation_step_duration_histogram
.observe({ step: step_class.name }, duration.seconds)
end
diff --git a/lib/gitlab/ci/pipeline/chain/config/content/external_project.rb b/lib/gitlab/ci/pipeline/chain/config/content/external_project.rb
index 8a19e433483..092e7d43371 100644
--- a/lib/gitlab/ci/pipeline/chain/config/content/external_project.rb
+++ b/lib/gitlab/ci/pipeline/chain/config/content/external_project.rb
@@ -11,8 +11,12 @@ module Gitlab
strong_memoize(:content) do
next unless external_project_path?
- path_file, path_project = ci_config_path.split('@', 2)
- YAML.dump('include' => [{ 'project' => path_project, 'file' => path_file }])
+ path_file, path_project, ref = extract_location_tokens
+
+ config_location = { 'project' => path_project, 'file' => path_file }
+ config_location['ref'] = ref if ref.present?
+
+ YAML.dump('include' => [config_location])
end
end
@@ -26,6 +30,18 @@ module Gitlab
def external_project_path?
ci_config_path =~ /\A.+(yml|yaml)@.+\z/
end
+
+ # Example: path/to/.gitlab-ci.yml@another-group/another-project:refname
+ def extract_location_tokens
+ path_file, path_project = ci_config_path.split('@', 2)
+
+ if path_project.include? ":"
+ project, ref = path_project.split(':', 2)
+ [path_file, project, ref]
+ else
+ [path_file, path_project]
+ end
+ end
end
end
end
diff --git a/lib/gitlab/database/migration.rb b/lib/gitlab/database/migration.rb
index 8990460ccf0..b2248b0f4eb 100644
--- a/lib/gitlab/database/migration.rb
+++ b/lib/gitlab/database/migration.rb
@@ -3,6 +3,22 @@
module Gitlab
module Database
class Migration
+ module LockRetriesConcern
+ extend ActiveSupport::Concern
+
+ class_methods do
+ def enable_lock_retries!
+ @enable_lock_retries = true # rubocop:disable Gitlab/ModuleWithInstanceVariables
+ end
+
+ def enable_lock_retries?
+ @enable_lock_retries
+ end
+ end
+
+ delegate :enable_lock_retries?, to: :class
+ end
+
# This implements a simple versioning scheme for migration helpers.
#
# We need to be able to version helpers, so we can change their behavior without
@@ -19,6 +35,7 @@ module Gitlab
# However, this hasn't been strictly formalized yet.
MIGRATION_CLASSES = {
1.0 => Class.new(ActiveRecord::Migration[6.1]) do
+ include LockRetriesConcern
include Gitlab::Database::MigrationHelpers::V2
end
}.freeze
diff --git a/lib/gitlab/database/migrations/lock_retry_mixin.rb b/lib/gitlab/database/migrations/lock_retry_mixin.rb
new file mode 100644
index 00000000000..fff0f35e33c
--- /dev/null
+++ b/lib/gitlab/database/migrations/lock_retry_mixin.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Database
+ module Migrations
+ module LockRetryMixin
+ module ActiveRecordMigrationProxyLockRetries
+ def migration_class
+ migration.class
+ end
+
+ def enable_lock_retries?
+ # regular AR migrations don't have this,
+ # only ones inheriting from Gitlab::Database::Migration have
+ return false unless migration.respond_to?(:enable_lock_retries?)
+
+ migration.enable_lock_retries?
+ end
+ end
+
+ module ActiveRecordMigratorLockRetries
+ # We patch the original method to start a transaction
+ # using the WithLockRetries methodology for the whole migration.
+ def ddl_transaction(migration, &block)
+ if use_transaction?(migration) && migration.enable_lock_retries?
+ Gitlab::Database::WithLockRetries.new(
+ klass: migration.migration_class,
+ logger: Gitlab::BackgroundMigration::Logger
+ ).run(raise_on_exhaustion: false, &block)
+ else
+ super
+ end
+ end
+ end
+
+ def self.patch!
+ ActiveRecord::MigrationProxy.prepend(ActiveRecordMigrationProxyLockRetries)
+ ActiveRecord::Migrator.prepend(ActiveRecordMigratorLockRetries)
+ end
+ end
+ end
+ end
+end