Commit f3ffbc72 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@13-12-stable-ee

parent e99202ec
...@@ -271,8 +271,12 @@ class Namespace < ApplicationRecord ...@@ -271,8 +271,12 @@ class Namespace < ApplicationRecord
# Includes projects from this namespace and projects from all subgroups # Includes projects from this namespace and projects from all subgroups
# that belongs to this namespace # that belongs to this namespace
def all_projects def all_projects
namespace = user? ? self : self_and_descendants if Feature.enabled?(:recursive_approach_for_all_projects, default_enabled: :yaml)
Project.where(namespace: namespace) namespace = user? ? self : self_and_descendants
Project.where(namespace: namespace)
else
Project.inside_path(full_path)
end
end end
# Includes pipelines from this namespace and pipelines from all subgroups # Includes pipelines from this namespace and pipelines from all subgroups
......
---
name: recursive_approach_for_all_projects
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/64632
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/334817
milestone: '14.1'
type: development
group: group::fulfillment
default_enabled: true
...@@ -8,7 +8,7 @@ module Gitlab ...@@ -8,7 +8,7 @@ module Gitlab
end end
def migrate_to_remote_storage def migrate_to_remote_storage
logger.info('Starting transfer to remote storage') logger.info('Starting transfer to object storage')
migrate(items_with_files_stored_locally, ObjectStorage::Store::REMOTE) migrate(items_with_files_stored_locally, ObjectStorage::Store::REMOTE)
end end
...@@ -38,11 +38,11 @@ module Gitlab ...@@ -38,11 +38,11 @@ module Gitlab
end end
def log_success(item, store) def log_success(item, store)
logger.info("Transferred #{item.class.name} ID #{item.id} of type #{item.file_type} with size #{item.size} to #{storage_label(store)} storage") logger.info("Transferred #{item.class.name} ID #{item.id} with size #{item.size} to #{storage_label(store)} storage")
end end
def log_error(err, item) def log_error(err, item)
logger.warn("Failed to transfer #{item.class.name} of type #{item.file_type} and ID #{item.id} with error: #{err.message}") logger.warn("Failed to transfer #{item.class.name} ID #{item.id} with error: #{err.message}")
end end
def storage_label(store) def storage_label(store)
......
# frozen_string_literal: true
require 'spec_helper'
require 'support/shared_examples/lib/gitlab/local_and_remote_storage_migration_shared_examples'
RSpec.describe Gitlab::LocalAndRemoteStorageMigration::ArtifactMigrater do
before do
stub_artifacts_object_storage(enabled: true)
end
let!(:item) { create(:ci_job_artifact, :archive, file_store: start_store) }
it_behaves_like 'local and remote storage migration'
end
# frozen_string_literal: true
require 'spec_helper'
require 'support/shared_examples/lib/gitlab/local_and_remote_storage_migration_shared_examples'
RSpec.describe Gitlab::LocalAndRemoteStorageMigration::PagesDeploymentMigrater do
before do
stub_pages_object_storage(::Pages::DeploymentUploader, enabled: true)
end
let!(:item) { create(:pages_deployment, file_store: start_store) }
it_behaves_like 'local and remote storage migration'
end
...@@ -1010,7 +1010,7 @@ RSpec.describe Namespace do ...@@ -1010,7 +1010,7 @@ RSpec.describe Namespace do
end end
end end
describe '#all_projects' do shared_examples '#all_projects' do
context 'when namespace is a group' do context 'when namespace is a group' do
let(:namespace) { create(:group) } let(:namespace) { create(:group) }
let(:child) { create(:group, parent: namespace) } let(:child) { create(:group, parent: namespace) }
...@@ -1019,12 +1019,6 @@ RSpec.describe Namespace do ...@@ -1019,12 +1019,6 @@ RSpec.describe Namespace do
it { expect(namespace.all_projects.to_a).to match_array([project2, project1]) } it { expect(namespace.all_projects.to_a).to match_array([project2, project1]) }
it { expect(child.all_projects.to_a).to match_array([project2]) } it { expect(child.all_projects.to_a).to match_array([project2]) }
it 'queries for the namespace and its descendants' do
expect(Project).to receive(:where).with(namespace: [namespace, child])
namespace.all_projects
end
end end
context 'when namespace is a user namespace' do context 'when namespace is a user namespace' do
...@@ -1033,12 +1027,20 @@ RSpec.describe Namespace do ...@@ -1033,12 +1027,20 @@ RSpec.describe Namespace do
let_it_be(:project) { create(:project, namespace: user_namespace) } let_it_be(:project) { create(:project, namespace: user_namespace) }
it { expect(user_namespace.all_projects.to_a).to match_array([project]) } it { expect(user_namespace.all_projects.to_a).to match_array([project]) }
end
end
it 'only queries for the namespace itself' do describe '#all_projects' do
expect(Project).to receive(:where).with(namespace: user_namespace) context 'when recursive approach is enabled' do
include_examples '#all_projects'
end
user_namespace.all_projects context 'when recursive approach is disabled' do
before do
stub_feature_flags(recursive_approach_for_all_projects: false)
end end
include_examples '#all_projects'
end end
end end
......
# frozen_string_literal: true
RSpec.shared_examples 'local and remote storage migration' do
let(:logger) { Logger.new("/dev/null") }
let(:migrater) { described_class.new(logger) }
using RSpec::Parameterized::TableSyntax
where(:start_store, :end_store, :method) do
ObjectStorage::Store::LOCAL | ObjectStorage::Store::REMOTE | :migrate_to_remote_storage
ObjectStorage::Store::REMOTE | ObjectStorage::Store::REMOTE | :migrate_to_remote_storage # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
ObjectStorage::Store::REMOTE | ObjectStorage::Store::LOCAL | :migrate_to_local_storage
ObjectStorage::Store::LOCAL | ObjectStorage::Store::LOCAL | :migrate_to_local_storage # rubocop:disable Lint/BinaryOperatorWithIdenticalOperands
end
with_them do
let(:storage_name) { end_store == ObjectStorage::Store::REMOTE ? 'object' : 'local' }
it 'successfully migrates' do
expect(logger).to receive(:info).with("Starting transfer to #{storage_name} storage")
if start_store != end_store
expect(logger).to receive(:info).with("Transferred #{item.class.name} ID #{item.id} with size #{item.size} to #{storage_name} storage")
end
expect(item.file_store).to eq(start_store)
migrater.send(method)
expect(item.reload.file_store).to eq(end_store)
end
end
context 'when migration fails' do
let(:start_store) { ObjectStorage::Store::LOCAL }
it 'prints error' do
expect_next_instance_of(item.file.class) do |file|
expect(file).to receive(:migrate!).and_raise("error message")
end
expect(logger).to receive(:info).with("Starting transfer to object storage")
expect(logger).to receive(:warn).with("Failed to transfer #{item.class.name} ID #{item.id} with error: error message")
expect(item.file_store).to eq(start_store)
migrater.migrate_to_remote_storage
expect(item.reload.file_store).to eq(start_store)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment