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:
Diffstat (limited to 'lib/tasks/gitlab')
-rw-r--r--lib/tasks/gitlab/backup.rake6
-rw-r--r--lib/tasks/gitlab/db.rake2
-rw-r--r--lib/tasks/gitlab/db/lock_writes.rake111
-rw-r--r--lib/tasks/gitlab/gitaly.rake2
-rw-r--r--lib/tasks/gitlab/info.rake2
-rw-r--r--lib/tasks/gitlab/praefect.rake6
-rw-r--r--lib/tasks/gitlab/shell.rake2
-rw-r--r--lib/tasks/gitlab/tw/codeowners.rake10
-rw-r--r--lib/tasks/gitlab/web_hook.rake11
9 files changed, 41 insertions, 111 deletions
diff --git a/lib/tasks/gitlab/backup.rake b/lib/tasks/gitlab/backup.rake
index 78cb7d72d4f..ff43a36d930 100644
--- a/lib/tasks/gitlab/backup.rake
+++ b/lib/tasks/gitlab/backup.rake
@@ -32,11 +32,13 @@ namespace :gitlab do
namespace :db do
task create: :gitlab_environment do
- Backup::Manager.new(progress).run_create_task('db')
+ Backup::Manager.new(progress).run_create_task('main_db')
+ Backup::Manager.new(progress).run_create_task('ci_db')
end
task restore: :gitlab_environment do
- Backup::Manager.new(progress).run_restore_task('db')
+ Backup::Manager.new(progress).run_restore_task('main_db')
+ Backup::Manager.new(progress).run_restore_task('ci_db')
end
end
diff --git a/lib/tasks/gitlab/db.rake b/lib/tasks/gitlab/db.rake
index 5ed54bb6921..30e0e3e72ff 100644
--- a/lib/tasks/gitlab/db.rake
+++ b/lib/tasks/gitlab/db.rake
@@ -294,7 +294,7 @@ namespace :gitlab do
# gc = Gitlab::CurrentSettings.current_application_settings
seed_projects = [Gitlab::CurrentSettings.current_application_settings.self_monitoring_project]
- if (Project.count - seed_projects.count {|x| !x.nil? }).eql?(0)
+ if (Project.count - seed_projects.count { |x| !x.nil? }).eql?(0)
puts "No user created projects. Database not active"
exit 1
end
diff --git a/lib/tasks/gitlab/db/lock_writes.rake b/lib/tasks/gitlab/db/lock_writes.rake
index 3a083036781..eb6d257cac5 100644
--- a/lib/tasks/gitlab/db/lock_writes.rake
+++ b/lib/tasks/gitlab/db/lock_writes.rake
@@ -2,22 +2,25 @@
namespace :gitlab do
namespace :db do
- TRIGGER_FUNCTION_NAME = 'gitlab_schema_prevent_write'
-
desc "GitLab | DB | Install prevent write triggers on all databases"
task lock_writes: [:environment, 'gitlab:db:validate_config'] do
- Gitlab::Database::EachDatabase.each_database_connection do |connection, database_name|
- create_write_trigger_function(connection)
-
+ Gitlab::Database::EachDatabase.each_database_connection(include_shared: false) do |connection, database_name|
schemas_for_connection = Gitlab::Database.gitlab_schemas_for_connection(connection)
Gitlab::Database::GitlabSchema.tables_to_schema.each do |table_name, schema_name|
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834
next if schema_name == :gitlab_geo
+ lock_writes_manager = Gitlab::Database::LockWritesManager.new(
+ table_name: table_name,
+ connection: connection,
+ database_name: database_name,
+ logger: Logger.new($stdout)
+ )
+
if schemas_for_connection.include?(schema_name.to_sym)
- drop_write_trigger(database_name, connection, table_name)
+ lock_writes_manager.unlock_writes
else
- create_write_trigger(database_name, connection, table_name)
+ lock_writes_manager.lock_writes
end
end
end
@@ -30,96 +33,16 @@ namespace :gitlab do
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834
next if schema_name == :gitlab_geo
- drop_write_trigger(database_name, connection, table_name)
- end
- drop_write_trigger_function(connection)
- end
- end
-
- def create_write_trigger_function(connection)
- sql = <<-SQL
- CREATE OR REPLACE FUNCTION #{TRIGGER_FUNCTION_NAME}()
- RETURNS TRIGGER AS
- $$
- BEGIN
- RAISE EXCEPTION 'Table: "%" is write protected within this Gitlab database.', TG_TABLE_NAME
- USING ERRCODE = 'modifying_sql_data_not_permitted',
- HINT = 'Make sure you are using the right database connection';
- END
- $$ LANGUAGE PLPGSQL
- SQL
-
- connection.execute(sql)
- end
-
- def drop_write_trigger_function(connection)
- sql = <<-SQL
- DROP FUNCTION IF EXISTS #{TRIGGER_FUNCTION_NAME}()
- SQL
-
- connection.execute(sql)
- end
-
- def create_write_trigger(database_name, connection, table_name)
- puts "#{database_name}: '#{table_name}'... Lock Writes".color(:yellow)
- sql = <<-SQL
- DROP TRIGGER IF EXISTS #{write_trigger_name(table_name)} ON #{table_name};
- CREATE TRIGGER #{write_trigger_name(table_name)}
- BEFORE INSERT OR UPDATE OR DELETE OR TRUNCATE
- ON #{table_name}
- FOR EACH STATEMENT EXECUTE FUNCTION #{TRIGGER_FUNCTION_NAME}();
- SQL
-
- with_retries(connection) do
- connection.execute(sql)
- end
- end
-
- def drop_write_trigger(database_name, connection, table_name)
- puts "#{database_name}: '#{table_name}'... Allow Writes".color(:green)
- sql = <<-SQL
- DROP TRIGGER IF EXISTS #{write_trigger_name(table_name)} ON #{table_name}
- SQL
-
- with_retries(connection) do
- connection.execute(sql)
- end
- end
+ lock_writes_manager = Gitlab::Database::LockWritesManager.new(
+ table_name: table_name,
+ connection: connection,
+ database_name: database_name,
+ logger: Logger.new($stdout)
+ )
- def with_retries(connection, &block)
- with_statement_timeout_retries do
- with_lock_retries(connection) do
- yield
+ lock_writes_manager.unlock_writes
end
end
end
-
- def with_statement_timeout_retries(times = 5)
- current_iteration = 1
- begin
- yield
- rescue ActiveRecord::QueryCanceled => err
- puts "Retrying after #{err.message}"
-
- if current_iteration <= times
- current_iteration += 1
- retry
- else
- raise err
- end
- end
- end
-
- def with_lock_retries(connection, &block)
- Gitlab::Database::WithLockRetries.new(
- klass: "gitlab:db:lock_writes",
- logger: Gitlab::AppLogger,
- connection: connection
- ).run(&block)
- end
-
- def write_trigger_name(table_name)
- "gitlab_schema_write_trigger_for_#{table_name}"
- end
end
end
diff --git a/lib/tasks/gitlab/gitaly.rake b/lib/tasks/gitlab/gitaly.rake
index 18c68615637..960d0e51a47 100644
--- a/lib/tasks/gitlab/gitaly.rake
+++ b/lib/tasks/gitlab/gitaly.rake
@@ -34,7 +34,7 @@ Usage: rake "gitlab:gitaly:install[/installation/dir,/storage/path]")
env["BUNDLE_DEPLOYMENT"] = 'false'
end
- output, status = Gitlab::Popen.popen([make_cmd, 'all', 'git'], nil, env)
+ output, status = Gitlab::Popen.popen([make_cmd, 'clean-build', 'all', 'git'], nil, env)
raise "Gitaly failed to compile: #{output}" unless status&.zero?
end
end
diff --git a/lib/tasks/gitlab/info.rake b/lib/tasks/gitlab/info.rake
index 6f42bf8c946..161c7dd38ac 100644
--- a/lib/tasks/gitlab/info.rake
+++ b/lib/tasks/gitlab/info.rake
@@ -19,7 +19,7 @@ namespace :gitlab do
# check for system defined proxies
if Gitlab.ee?
- proxies = Gitlab::Proxy.detect_proxy.map {|k, v| "#{k}: #{v}"}.join("\n\t\t")
+ proxies = Gitlab::Proxy.detect_proxy.map { |k, v| "#{k}: #{v}" }.join("\n\t\t")
end
# check Go version
diff --git a/lib/tasks/gitlab/praefect.rake b/lib/tasks/gitlab/praefect.rake
index 28b70f8986e..6874a55e08a 100644
--- a/lib/tasks/gitlab/praefect.rake
+++ b/lib/tasks/gitlab/praefect.rake
@@ -3,7 +3,9 @@
namespace :gitlab do
namespace :praefect do
def int?(string)
- true if Integer(string) rescue false
+ true if Integer(string)
+ rescue StandardError
+ false
end
def print_checksums(header, row)
@@ -43,7 +45,7 @@ namespace :gitlab do
header.concat(sorted_replicas.map { |r| r.repository.storage_name })
row = [project.name] << replicas_resp.primary.checksum
- row.concat(sorted_replicas.map {|r| r.checksum})
+ row.concat(sorted_replicas.map { |r| r.checksum })
rescue StandardError
puts 'Something went wrong when getting replicas.'
next
diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake
index 8627a326247..cf9876366aa 100644
--- a/lib/tasks/gitlab/shell.rake
+++ b/lib/tasks/gitlab/shell.rake
@@ -27,7 +27,7 @@ namespace :gitlab do
}.stringify_keys
# Generate config.yml based on existing gitlab settings
- File.open("config.yml", "w+") {|f| f.puts config.to_yaml }
+ File.open("config.yml", "w+") { |f| f.puts config.to_yaml }
[
%w(bin/install) + repository_storage_paths_args,
diff --git a/lib/tasks/gitlab/tw/codeowners.rake b/lib/tasks/gitlab/tw/codeowners.rake
index 40d88ea8a5b..f6c518784a9 100644
--- a/lib/tasks/gitlab/tw/codeowners.rake
+++ b/lib/tasks/gitlab/tw/codeowners.rake
@@ -46,12 +46,12 @@ namespace :tw do
CodeOwnerRule.new('Fuzz Testing', '@rdickenson'),
CodeOwnerRule.new('Geo', '@axil'),
CodeOwnerRule.new('Gitaly', '@eread'),
- CodeOwnerRule.new('Global Search', '@sselhorn'),
+ CodeOwnerRule.new('Global Search', '@ashrafkhamis'),
CodeOwnerRule.new('Import', '@eread'),
CodeOwnerRule.new('Infrastructure', '@sselhorn'),
- CodeOwnerRule.new('Integrations', '@kpaizee'),
+ CodeOwnerRule.new('Integrations', '@ashrafkhamis'),
CodeOwnerRule.new('Knowledge', '@aqualls'),
- CodeOwnerRule.new('Memory', '@sselhorn'),
+ CodeOwnerRule.new('Application Performance', '@sselhorn'),
CodeOwnerRule.new('Monitor', '@msedlakjakubowski'),
CodeOwnerRule.new('Observability', 'msedlakjakubowski'),
CodeOwnerRule.new('Optimize', '@fneill'),
@@ -69,7 +69,7 @@ namespace :tw do
CodeOwnerRule.new('Release', '@rdickenson'),
CodeOwnerRule.new('Respond', '@msedlakjakubowski'),
CodeOwnerRule.new('Runner', '@sselhorn'),
- CodeOwnerRule.new('Sharding', '@sselhorn'),
+ CodeOwnerRule.new('Pods', '@sselhorn'),
CodeOwnerRule.new('Source Code', '@aqualls'),
CodeOwnerRule.new('Static Analysis', '@rdickenson'),
CodeOwnerRule.new('Style Guide', '@sselhorn'),
@@ -128,7 +128,7 @@ namespace :tw do
if errors.present?
puts "-----"
puts "ERRORS - the following files are missing the correct metadata:"
- errors.map { |file| puts file.gsub(Dir.pwd, ".")}
+ errors.map { |file| puts file.gsub(Dir.pwd, ".") }
end
end
end
diff --git a/lib/tasks/gitlab/web_hook.rake b/lib/tasks/gitlab/web_hook.rake
index fc17c7d0177..9aa0f07de5f 100644
--- a/lib/tasks/gitlab/web_hook.rake
+++ b/lib/tasks/gitlab/web_hook.rake
@@ -22,11 +22,13 @@ namespace :gitlab do
end
end
- desc "GitLab | Webhook | Remove a webhook from the projects"
- task rm: :environment do
+ desc "GitLab | Webhook | Remove a webhook from a namespace"
+ task rm: :environment do |task|
web_hook_url = ENV['URL']
namespace_path = ENV['NAMESPACE']
+ raise ArgumentError, 'URL is required' unless web_hook_url
+
web_hooks = find_web_hooks(namespace_path)
puts "Removing webhooks with the url '#{web_hook_url}' ... "
@@ -36,11 +38,12 @@ namespace :gitlab do
# we could consider storing a hash of the URL alongside the encrypted
# value to speed up searches
count = 0
+ service = WebHooks::AdminDestroyService.new(rake_task: task)
+
web_hooks.find_each do |hook|
next unless hook.url == web_hook_url
- user = hook.parent.owners.first
- result = WebHooks::DestroyService.new(user).execute(hook)
+ result = service.execute(hook)
raise "Unable to destroy Web hook" unless result[:status] == :success