From 1b30559a2012b5cfc4fc4c8bde31e6eb76f2da05 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Sun, 19 Nov 2023 21:10:52 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../concerns/update_repository_storage_methods.rb | 3 ++ ...dd_error_to_project_repository_storage_moves.rb | 20 +++++++++++++ ..._add_error_to_group_repository_storage_moves.rb | 20 +++++++++++++ ...dd_error_to_snippet_repository_storage_moves.rb | 20 +++++++++++++ db/schema_migrations/20231112213727 | 1 + db/schema_migrations/20231112214803 | 1 + db/schema_migrations/20231112223008 | 1 + db/structure.sql | 6 ++++ lib/api/entities/basic_repository_storage_move.rb | 1 + .../v4/project_repository_storage_move.json | 33 +++++++++++++++++----- .../v4/snippet_repository_storage_move.json | 33 +++++++++++++++++----- .../update_repository_storage_service_spec.rb | 6 +++- .../update_repository_storage_service_spec.rb | 5 +++- 13 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 db/migrate/20231112213727_add_error_to_project_repository_storage_moves.rb create mode 100644 db/migrate/20231112214803_add_error_to_group_repository_storage_moves.rb create mode 100644 db/migrate/20231112223008_add_error_to_snippet_repository_storage_moves.rb create mode 100644 db/schema_migrations/20231112213727 create mode 100644 db/schema_migrations/20231112214803 create mode 100644 db/schema_migrations/20231112223008 diff --git a/app/services/concerns/update_repository_storage_methods.rb b/app/services/concerns/update_repository_storage_methods.rb index aff36d6943e..8ed87fdb048 100644 --- a/app/services/concerns/update_repository_storage_methods.rb +++ b/app/services/concerns/update_repository_storage_methods.rb @@ -3,6 +3,8 @@ module UpdateRepositoryStorageMethods include Gitlab::Utils::StrongMemoize + MAX_ERROR_LENGTH = 256 + Error = Class.new(StandardError) attr_reader :repository_storage_move @@ -44,6 +46,7 @@ module UpdateRepositoryStorageMethods ServiceResponse.success rescue StandardError => e + repository_storage_move.update_column(:error_message, e.message.truncate(MAX_ERROR_LENGTH)) repository_storage_move.do_fail! Gitlab::ErrorTracking.track_and_raise_exception(e, container_klass: container.class.to_s, container_path: container.full_path) diff --git a/db/migrate/20231112213727_add_error_to_project_repository_storage_moves.rb b/db/migrate/20231112213727_add_error_to_project_repository_storage_moves.rb new file mode 100644 index 00000000000..d1a9da567f2 --- /dev/null +++ b/db/migrate/20231112213727_add_error_to_project_repository_storage_moves.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddErrorToProjectRepositoryStorageMoves < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '16.7' + + def up + with_lock_retries do + add_column :project_repository_storage_moves, :error_message, :text, if_not_exists: true + end + + add_text_limit :project_repository_storage_moves, :error_message, 256 + end + + def down + with_lock_retries do + remove_column :project_repository_storage_moves, :error_message, if_exists: true + end + end +end diff --git a/db/migrate/20231112214803_add_error_to_group_repository_storage_moves.rb b/db/migrate/20231112214803_add_error_to_group_repository_storage_moves.rb new file mode 100644 index 00000000000..7ff1bf6e30c --- /dev/null +++ b/db/migrate/20231112214803_add_error_to_group_repository_storage_moves.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddErrorToGroupRepositoryStorageMoves < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '16.7' + + def up + with_lock_retries do + add_column :group_repository_storage_moves, :error_message, :text, if_not_exists: true + end + + add_text_limit :group_repository_storage_moves, :error_message, 256 + end + + def down + with_lock_retries do + remove_column :group_repository_storage_moves, :error_message, if_exists: true + end + end +end diff --git a/db/migrate/20231112223008_add_error_to_snippet_repository_storage_moves.rb b/db/migrate/20231112223008_add_error_to_snippet_repository_storage_moves.rb new file mode 100644 index 00000000000..384b652ca56 --- /dev/null +++ b/db/migrate/20231112223008_add_error_to_snippet_repository_storage_moves.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class AddErrorToSnippetRepositoryStorageMoves < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + milestone '16.7' + + def up + with_lock_retries do + add_column :snippet_repository_storage_moves, :error_message, :text, if_not_exists: true + end + + add_text_limit :snippet_repository_storage_moves, :error_message, 256 + end + + def down + with_lock_retries do + remove_column :snippet_repository_storage_moves, :error_message, if_exists: true + end + end +end diff --git a/db/schema_migrations/20231112213727 b/db/schema_migrations/20231112213727 new file mode 100644 index 00000000000..a92c4c1416d --- /dev/null +++ b/db/schema_migrations/20231112213727 @@ -0,0 +1 @@ +9e9b1aa72cdee936d054dfd657636d54c505fa9355ebf41c8dcdfd695dc2530b \ No newline at end of file diff --git a/db/schema_migrations/20231112214803 b/db/schema_migrations/20231112214803 new file mode 100644 index 00000000000..9876f17af07 --- /dev/null +++ b/db/schema_migrations/20231112214803 @@ -0,0 +1 @@ +2a7d37a61d4fc2a0b4a96acbf58508b5d38119540005f546e7d9f247eac3829f \ No newline at end of file diff --git a/db/schema_migrations/20231112223008 b/db/schema_migrations/20231112223008 new file mode 100644 index 00000000000..d0fd803aebe --- /dev/null +++ b/db/schema_migrations/20231112223008 @@ -0,0 +1 @@ +fdd72dc39f9815db8a9c23a6fe5329f8708da91607709a2d822771c7ced8eba5 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index efd6fbfae1c..c56525ef09e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -17336,6 +17336,8 @@ CREATE TABLE group_repository_storage_moves ( state smallint DEFAULT 1 NOT NULL, source_storage_name text NOT NULL, destination_storage_name text NOT NULL, + error_message text, + CONSTRAINT check_266d0cf596 CHECK ((char_length(error_message) <= 256)), CONSTRAINT group_repository_storage_moves_destination_storage_name CHECK ((char_length(destination_storage_name) <= 255)), CONSTRAINT group_repository_storage_moves_source_storage_name CHECK ((char_length(source_storage_name) <= 255)) ); @@ -22019,6 +22021,8 @@ CREATE TABLE project_repository_storage_moves ( state smallint DEFAULT 1 NOT NULL, source_storage_name text NOT NULL, destination_storage_name text NOT NULL, + error_message text, + CONSTRAINT check_85854380db CHECK ((char_length(error_message) <= 256)), CONSTRAINT project_repository_storage_moves_destination_storage_name CHECK ((char_length(destination_storage_name) <= 255)), CONSTRAINT project_repository_storage_moves_source_storage_name CHECK ((char_length(source_storage_name) <= 255)) ); @@ -23535,6 +23539,8 @@ CREATE TABLE snippet_repository_storage_moves ( state smallint DEFAULT 1 NOT NULL, source_storage_name text NOT NULL, destination_storage_name text NOT NULL, + error_message text, + CONSTRAINT check_a42ab83060 CHECK ((char_length(error_message) <= 256)), CONSTRAINT snippet_repository_storage_moves_destination_storage_name CHECK ((char_length(destination_storage_name) <= 255)), CONSTRAINT snippet_repository_storage_moves_source_storage_name CHECK ((char_length(source_storage_name) <= 255)) ); diff --git a/lib/api/entities/basic_repository_storage_move.rb b/lib/api/entities/basic_repository_storage_move.rb index 83b4f428a56..9124b8b428f 100644 --- a/lib/api/entities/basic_repository_storage_move.rb +++ b/lib/api/entities/basic_repository_storage_move.rb @@ -8,6 +8,7 @@ module API expose :human_state_name, as: :state, documentation: { type: 'string', example: 'scheduled' } expose :source_storage_name, documentation: { type: 'string', example: 'default' } expose :destination_storage_name, documentation: { type: 'string', example: 'storage1' } + expose :error_message, documentation: { type: 'string', example: 'Failed to move repository' } end end end diff --git a/spec/fixtures/api/schemas/public_api/v4/project_repository_storage_move.json b/spec/fixtures/api/schemas/public_api/v4/project_repository_storage_move.json index cfaa1c28bb7..21f466bc418 100644 --- a/spec/fixtures/api/schemas/public_api/v4/project_repository_storage_move.json +++ b/spec/fixtures/api/schemas/public_api/v4/project_repository_storage_move.json @@ -8,13 +8,32 @@ "destination_storage_name", "project" ], - "properties" : { - "id": { "type": "integer" }, - "created_at": { "type": "string", "format": "date-time" }, - "state": { "type": "string" }, - "source_storage_name": { "type": "string" }, - "destination_storage_name": { "type": "string" }, - "project": { "type": "object" } + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "state": { + "type": "string" + }, + "source_storage_name": { + "type": "string" + }, + "destination_storage_name": { + "type": "string" + }, + "error_message": { + "type": [ + "string", + "null" + ] + }, + "project": { + "type": "object" + } }, "additionalProperties": false } diff --git a/spec/fixtures/api/schemas/public_api/v4/snippet_repository_storage_move.json b/spec/fixtures/api/schemas/public_api/v4/snippet_repository_storage_move.json index b0633a6ff2d..65494e27f5c 100644 --- a/spec/fixtures/api/schemas/public_api/v4/snippet_repository_storage_move.json +++ b/spec/fixtures/api/schemas/public_api/v4/snippet_repository_storage_move.json @@ -8,13 +8,32 @@ "destination_storage_name", "snippet" ], - "properties" : { - "id": { "type": "integer" }, - "created_at": { "type": "string", "format": "date-time" }, - "state": { "type": "string" }, - "source_storage_name": { "type": "string" }, - "destination_storage_name": { "type": "string" }, - "snippet": { "type": "object" } + "properties": { + "id": { + "type": "integer" + }, + "created_at": { + "type": "string", + "format": "date-time" + }, + "state": { + "type": "string" + }, + "source_storage_name": { + "type": "string" + }, + "destination_storage_name": { + "type": "string" + }, + "error_message": { + "type": [ + "string", + "null" + ] + }, + "snippet": { + "type": "object" + } }, "additionalProperties": false } diff --git a/spec/services/projects/update_repository_storage_service_spec.rb b/spec/services/projects/update_repository_storage_service_spec.rb index b81fc8bf633..cc54748bbb8 100644 --- a/spec/services/projects/update_repository_storage_service_spec.rb +++ b/spec/services/projects/update_repository_storage_service_spec.rb @@ -76,6 +76,8 @@ RSpec.describe Projects::UpdateRepositoryStorageService, feature_category: :sour expect(project).not_to be_repository_read_only expect(project.repository_storage).to eq('test_second_storage') expect(project.project_repository.shard_name).to eq('test_second_storage') + expect(repository_storage_move.reload).to be_finished + expect(repository_storage_move.error_message).to be_nil end end @@ -100,6 +102,7 @@ RSpec.describe Projects::UpdateRepositoryStorageService, feature_category: :sour expect(project).not_to be_repository_read_only expect(repository_storage_move.reload).to be_failed + expect(repository_storage_move.error_message).to eq('Boom') end end @@ -126,7 +129,7 @@ RSpec.describe Projects::UpdateRepositoryStorageService, feature_category: :sour expect(project_repository_double).to receive(:replicate) .with(project.repository.raw) - .and_raise(Gitlab::Git::CommandError) + .and_raise(Gitlab::Git::CommandError, 'Boom') expect(project_repository_double).to receive(:remove) expect do @@ -136,6 +139,7 @@ RSpec.describe Projects::UpdateRepositoryStorageService, feature_category: :sour expect(project).not_to be_repository_read_only expect(project.repository_storage).to eq('default') expect(repository_storage_move).to be_failed + expect(repository_storage_move.error_message).to eq('Boom') end end diff --git a/spec/services/snippets/update_repository_storage_service_spec.rb b/spec/services/snippets/update_repository_storage_service_spec.rb index 66847a43335..84e687329cc 100644 --- a/spec/services/snippets/update_repository_storage_service_spec.rb +++ b/spec/services/snippets/update_repository_storage_service_spec.rb @@ -43,6 +43,8 @@ RSpec.describe Snippets::UpdateRepositoryStorageService, feature_category: :sour expect(snippet).not_to be_repository_read_only expect(snippet.repository_storage).to eq(destination) expect(snippet.snippet_repository.shard_name).to eq(destination) + expect(repository_storage_move.reload).to be_finished + expect(repository_storage_move.error_message).to be_nil end end @@ -66,7 +68,7 @@ RSpec.describe Snippets::UpdateRepositoryStorageService, feature_category: :sour it 'unmarks the repository as read-only without updating the repository storage' do expect(snippet_repository_double).to receive(:replicate) .with(snippet.repository.raw) - .and_raise(Gitlab::Git::CommandError) + .and_raise(Gitlab::Git::CommandError, 'Boom') expect(snippet_repository_double).to receive(:remove) expect do @@ -76,6 +78,7 @@ RSpec.describe Snippets::UpdateRepositoryStorageService, feature_category: :sour expect(snippet).not_to be_repository_read_only expect(snippet.repository_storage).to eq('default') expect(repository_storage_move).to be_failed + expect(repository_storage_move.error_message).to eq('Boom') end end -- cgit v1.2.3