diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /lib/tasks | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'lib/tasks')
-rw-r--r-- | lib/tasks/contracts/merge_requests.rake | 23 | ||||
-rw-r--r-- | lib/tasks/contracts/pipeline_schedules.rake | 32 | ||||
-rw-r--r-- | lib/tasks/contracts/pipelines.rake | 37 | ||||
-rw-r--r-- | lib/tasks/dev.rake | 15 | ||||
-rw-r--r-- | lib/tasks/gems.rake | 2 | ||||
-rw-r--r-- | lib/tasks/gitlab/backup.rake | 6 | ||||
-rw-r--r-- | lib/tasks/gitlab/db.rake | 2 | ||||
-rw-r--r-- | lib/tasks/gitlab/db/lock_writes.rake | 111 | ||||
-rw-r--r-- | lib/tasks/gitlab/gitaly.rake | 2 | ||||
-rw-r--r-- | lib/tasks/gitlab/info.rake | 2 | ||||
-rw-r--r-- | lib/tasks/gitlab/praefect.rake | 6 | ||||
-rw-r--r-- | lib/tasks/gitlab/shell.rake | 2 | ||||
-rw-r--r-- | lib/tasks/gitlab/tw/codeowners.rake | 10 | ||||
-rw-r--r-- | lib/tasks/gitlab/web_hook.rake | 11 | ||||
-rw-r--r-- | lib/tasks/rubocop.rake | 3 |
15 files changed, 125 insertions, 139 deletions
diff --git a/lib/tasks/contracts/merge_requests.rake b/lib/tasks/contracts/merge_requests.rake index 05ed9c30495..2ee7ec07a96 100644 --- a/lib/tasks/contracts/merge_requests.rake +++ b/lib/tasks/contracts/merge_requests.rake @@ -4,38 +4,36 @@ return if Rails.env.production? require 'pact/tasks/verification_task' -contracts = File.expand_path('../../../spec/contracts', __dir__) -provider = File.expand_path('provider', contracts) +contracts = File.expand_path('../../../spec/contracts/contracts/project/merge_request', __dir__) +provider = File.expand_path('../../../spec/contracts/provider', __dir__) -# rubocop:disable Rails/RakeEnvironment namespace :contracts do namespace :merge_requests do Pact::VerificationTask.new(:diffs_batch) do |pact| pact.uri( - "#{contracts}/contracts/project/merge_request/show/mergerequest#show-merge_request_diffs_batch_endpoint.json", - pact_helper: "#{provider}/pact_helpers/project/merge_request/diffs_batch_helper.rb" + "#{contracts}/show/mergerequest#show-merge_request_diffs_batch_endpoint.json", + pact_helper: "#{provider}/pact_helpers/project/merge_request/show/diffs_batch_helper.rb" ) end Pact::VerificationTask.new(:diffs_metadata) do |pact| pact.uri( - "#{contracts}/contracts/project/merge_request/show/" \ - "mergerequest#show-merge_request_diffs_metadata_endpoint.json", - pact_helper: "#{provider}/pact_helpers/project/merge_request/diffs_metadata_helper.rb" + "#{contracts}/show/mergerequest#show-merge_request_diffs_metadata_endpoint.json", + pact_helper: "#{provider}/pact_helpers/project/merge_request/show/diffs_metadata_helper.rb" ) end Pact::VerificationTask.new(:discussions) do |pact| pact.uri( - "#{contracts}/contracts/project/merge_request/show/mergerequest#show-merge_request_discussions_endpoint.json", - pact_helper: "#{provider}/pact_helpers/project/merge_request/discussions_helper.rb" + "#{contracts}/show/mergerequest#show-merge_request_discussions_endpoint.json", + pact_helper: "#{provider}/pact_helpers/project/merge_request/show/discussions_helper.rb" ) end desc 'Run all merge request contract tests' - task 'test:merge_requests', :contract_mr do |_t, arg| + task 'test:merge_requests', :contract_merge_requests do |_t, arg| errors = %w[diffs_batch diffs_metadata discussions].each_with_object([]) do |task, err| - Rake::Task["contracts:mr:pact:verify:#{task}"].execute + Rake::Task["contracts:merge_requests:pact:verify:#{task}"].execute rescue StandardError, SystemExit err << "contracts:merge_requests:pact:verify:#{task}" end @@ -44,4 +42,3 @@ namespace :contracts do end end end -# rubocop:enable Rails/RakeEnvironment diff --git a/lib/tasks/contracts/pipeline_schedules.rake b/lib/tasks/contracts/pipeline_schedules.rake new file mode 100644 index 00000000000..75080d41ebe --- /dev/null +++ b/lib/tasks/contracts/pipeline_schedules.rake @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +return if Rails.env.production? + +require 'pact/tasks/verification_task' + +contracts = File.expand_path('../../../spec/contracts/contracts/project/pipeline_schedule', __dir__) +provider = File.expand_path('../../../spec/contracts/provider', __dir__) + +namespace :contracts do + namespace :pipeline_schedules do + Pact::VerificationTask.new(:update_pipeline_schedule) do |pact| + pact.uri( + "#{contracts}/edit/pipelineschedules#edit-put_edit_a_pipeline_schedule.json", + pact_helper: "#{provider}/pact_helpers/project/pipeline_schedule/update_pipeline_schedule_helper.rb" + ) + end + + desc 'Run all pipeline schedule contract tests' + task 'test:pipeline_schedules', :contract_pipeline_schedules do |_t, arg| + errors = %w[ + update_pipeline_schedule + ].each_with_object([]) do |task, err| + Rake::Task["contracts:pipeline_schedules:pact:verify:#{task}"].execute + rescue StandardError, SystemExit + err << "contracts:pipeline_schedule:pact:verify:#{task}" + end + + raise StandardError, "Errors in tasks #{errors.join(', ')}" unless errors.empty? + end + end +end diff --git a/lib/tasks/contracts/pipelines.rake b/lib/tasks/contracts/pipelines.rake index c018645722e..3163791460f 100644 --- a/lib/tasks/contracts/pipelines.rake +++ b/lib/tasks/contracts/pipelines.rake @@ -4,29 +4,47 @@ return if Rails.env.production? require 'pact/tasks/verification_task' -contracts = File.expand_path('../../../spec/contracts', __dir__) -provider = File.expand_path('provider', contracts) +contracts = File.expand_path('../../../spec/contracts/contracts/project/pipeline', __dir__) +provider = File.expand_path('../../../spec/contracts/provider', __dir__) -# rubocop:disable Rails/RakeEnvironment namespace :contracts do namespace :pipelines do + Pact::VerificationTask.new(:create_a_new_pipeline) do |pact| + pact.uri( + "#{contracts}/new/pipelines#new-post_create_a_new_pipeline.json", + pact_helper: "#{provider}/pact_helpers/project/pipeline/index/create_a_new_pipeline_helper.rb" + ) + end + Pact::VerificationTask.new(:get_list_project_pipelines) do |pact| pact.uri( - "#{contracts}/contracts/project/pipeline/index/pipelines#index-get_list_project_pipelines.json", - pact_helper: "#{provider}/pact_helpers/project/pipeline/get_list_project_pipelines_helper.rb" + "#{contracts}/index/pipelines#index-get_list_project_pipelines.json", + pact_helper: "#{provider}/pact_helpers/project/pipeline/index/get_list_project_pipelines_helper.rb" ) end Pact::VerificationTask.new(:get_pipeline_header_data) do |pact| pact.uri( - "#{contracts}/contracts/project/pipeline/show/pipelines#show-get_pipeline_header_data.json", - pact_helper: "#{provider}/pact_helpers/project/pipeline/get_pipeline_header_data_helper.rb" + "#{contracts}/show/pipelines#show-get_pipeline_header_data.json", + pact_helper: "#{provider}/pact_helpers/project/pipeline/show/get_pipeline_header_data_helper.rb" + ) + end + + Pact::VerificationTask.new(:delete_pipeline) do |pact| + pact.uri( + "#{contracts}/show/pipelines#show-delete_pipeline.json", + pact_helper: "#{provider}/pact_helpers/project/pipeline/show/delete_pipeline_helper.rb" ) end desc 'Run all pipeline contract tests' - task 'test:pipelines', :contract_mr do |_t, arg| - errors = %w[get_list_project_pipelines get_pipeline_header_data].each_with_object([]) do |task, err| + task 'test:pipelines', :contract_pipelines do |_t, arg| + errors = %w[ + create_a_new_pipeline + get_list_project_pipelines + get_pipeline_header_data + delete_pipeline + ].each_with_object([]) do |task, err| Rake::Task["contracts:pipelines:pact:verify:#{task}"].execute rescue StandardError, SystemExit err << "contracts:pipelines:pact:verify:#{task}" @@ -36,4 +54,3 @@ namespace :contracts do end end end -# rubocop:enable Rails/RakeEnvironment diff --git a/lib/tasks/dev.rake b/lib/tasks/dev.rake index 48bf49ff284..129f4c0ff0e 100644 --- a/lib/tasks/dev.rake +++ b/lib/tasks/dev.rake @@ -27,6 +27,21 @@ namespace :dev do Rails.application.eager_load! end + desc "GitLab | Dev | Load specific fixture" + task 'fixtures:load', [:fixture_name] => :environment do |_, args| + fixture_name = args.fixture_name + + if fixture_name.nil? + puts "No fixture name was provided" + next + end + + ENV['FIXTURE_PATH'] = 'db/fixtures/development/' + ENV['FILTER'] = args.fixture_name + + Rake::Task['db:seed_fu'].invoke + end + # If there are any clients connected to the DB, PostgreSQL won't let # you drop the database. It's possible that Sidekiq, Puma, or # some other client will be hanging onto a connection, preventing diff --git a/lib/tasks/gems.rake b/lib/tasks/gems.rake index c6be6d9eead..fc70048ea6d 100644 --- a/lib/tasks/gems.rake +++ b/lib/tasks/gems.rake @@ -4,7 +4,6 @@ namespace :gems do # :nocov: namespace :error_tracking_open_api do desc 'Generate OpenAPI client for Error Tracking' - # rubocop:disable Rails/RakeEnvironment task :generate do |task| # Configuration api_url = 'https://gitlab.com/gitlab-org/opstrace/opstrace/-/raw/main/go/pkg/errortracking/swagger.yaml' @@ -28,7 +27,6 @@ namespace :gems do post_process(gem_dir: gem_dir, gem_name: gem_name, task: task) end - # rubocop:enable Rails/RakeEnvironment def root_directory File.expand_path('../../vendor/gems', __dir__) 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 diff --git a/lib/tasks/rubocop.rake b/lib/tasks/rubocop.rake index 28c370e5ca6..e993035aa65 100644 --- a/lib/tasks/rubocop.rake +++ b/lib/tasks/rubocop.rake @@ -1,5 +1,4 @@ # frozen_string_literal: true -# rubocop:disable Rails/RakeEnvironment unless Rails.env.production? require 'rubocop/rake_task' @@ -63,5 +62,3 @@ unless Rails.env.production? end end end - -# rubocop:enable Rails/RakeEnvironment |