From a4d8bae6275c0837b314ed6a1b2f6b17c9ba6c69 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 18 Jan 2022 09:10:47 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- GITALY_SERVER_VERSION | 2 +- .../mirrors/_authentication_method.html.haml | 2 +- .../mirrors/_mirror_repos_form.html.haml | 2 +- .../bulk_expire_project_artifacts.yml | 2 +- doc/api/job_artifacts.md | 7 +- lib/gitlab/metrics/exporter/base_exporter.rb | 5 +- .../metrics/exporter/gc_request_middleware.rb | 19 ++++++ metrics_server/dependencies.rb | 1 + metrics_server/metrics_server.rb | 2 +- .../1_manage/user_access_termination_spec.rb | 6 +- .../exporter/gc_request_middleware_spec.rb | 21 ++++++ spec/metrics_server/metrics_server_spec.rb | 4 +- spec/models/project_spec.rb | 68 +++++++------------ 13 files changed, 82 insertions(+), 59 deletions(-) create mode 100644 lib/gitlab/metrics/exporter/gc_request_middleware.rb create mode 100644 spec/lib/gitlab/metrics/exporter/gc_request_middleware_spec.rb diff --git a/GITALY_SERVER_VERSION b/GITALY_SERVER_VERSION index 1e1faedc414..2ca34134182 100644 --- a/GITALY_SERVER_VERSION +++ b/GITALY_SERVER_VERSION @@ -1 +1 @@ -7ce0d18ad44686865aa0dbf5f1b47d9cc05988be +b119c19734ba589a079381e8390952e37994149f diff --git a/app/views/projects/mirrors/_authentication_method.html.haml b/app/views/projects/mirrors/_authentication_method.html.haml index 5f31ec4087e..e9e3645d7f2 100644 --- a/app/views/projects/mirrors/_authentication_method.html.haml +++ b/app/views/projects/mirrors/_authentication_method.html.haml @@ -6,7 +6,7 @@ .select-wrapper = f.select :auth_method, options_for_select(auth_options, mirror.auth_method), - {}, { class: "form-control gl-form-input select-control js-mirror-auth-type qa-authentication-method" } + {}, { class: "form-control gl-form-select select-control js-mirror-auth-type qa-authentication-method" } = sprite_icon('chevron-down', css_class: "gl-icon gl-absolute gl-top-3 gl-right-3 gl-text-gray-200") = f.hidden_field :auth_method, value: "password", class: "js-hidden-mirror-auth-type" diff --git a/app/views/projects/mirrors/_mirror_repos_form.html.haml b/app/views/projects/mirrors/_mirror_repos_form.html.haml index dca01ebbe90..34b7c75debf 100644 --- a/app/views/projects/mirrors/_mirror_repos_form.html.haml +++ b/app/views/projects/mirrors/_mirror_repos_form.html.haml @@ -1,7 +1,7 @@ .form-group = label_tag :mirror_direction, _('Mirror direction'), class: 'label-light' .select-wrapper - = select_tag :mirror_direction, options_for_select([[_('Push'), 'push']]), class: 'form-control gl-form-input select-control js-mirror-direction qa-mirror-direction', disabled: true + = select_tag :mirror_direction, options_for_select([[_('Push'), 'push']]), class: 'form-control gl-form-select select-control js-mirror-direction qa-mirror-direction', disabled: true = sprite_icon('chevron-down', css_class: "gl-icon gl-absolute gl-top-3 gl-right-3 gl-text-gray-200") = render partial: "projects/mirrors/mirror_repos_push", locals: { f: f } diff --git a/config/feature_flags/development/bulk_expire_project_artifacts.yml b/config/feature_flags/development/bulk_expire_project_artifacts.yml index c00cc749a79..609f87847fa 100644 --- a/config/feature_flags/development/bulk_expire_project_artifacts.yml +++ b/config/feature_flags/development/bulk_expire_project_artifacts.yml @@ -5,4 +5,4 @@ rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/347405 milestone: '14.6' type: development group: group::testing -default_enabled: false +default_enabled: true diff --git a/doc/api/job_artifacts.md b/doc/api/job_artifacts.md index ef00c050a3a..a874379506f 100644 --- a/doc/api/job_artifacts.md +++ b/doc/api/job_artifacts.md @@ -287,12 +287,11 @@ If the artifacts were deleted successfully, a response with status `204 No Conte ## Delete project artifacts -> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/223793) in GitLab 14.7 [with a flag](../administration/feature_flags.md) named `bulk_expire_project_artifacts`. Disabled by default on GitLab self-managed. Enabled on GitLab.com. +> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/223793) in GitLab 14.7 [with a flag](../administration/feature_flags.md) named `bulk_expire_project_artifacts`. Enabled by default on GitLab self-managed. Enabled on GitLab.com. FLAG: -On self-managed GitLab, by default this feature is not available. To make it -available, ask an administrator to [enable the `bulk_expire_project_artifacts` flag](../administration/feature_flags.md). -On GitLab.com, this feature is available. +On self-managed GitLab, by default this feature is available. To hide the feature, ask an administrator to +[disable the `bulk_expire_project_artifacts` flag](../administration/feature_flags.md). On GitLab.com, this feature is available. [Expire artifacts of a project that can be deleted](https://gitlab.com/gitlab-org/gitlab/-/issues/223793) but that don't have an expiry time. diff --git a/lib/gitlab/metrics/exporter/base_exporter.rb b/lib/gitlab/metrics/exporter/base_exporter.rb index 66041badf01..190d3d3fd2f 100644 --- a/lib/gitlab/metrics/exporter/base_exporter.rb +++ b/lib/gitlab/metrics/exporter/base_exporter.rb @@ -11,10 +11,11 @@ module Gitlab attr_accessor :readiness_checks - def initialize(settings, log_enabled:, log_file:, **options) + def initialize(settings, log_enabled:, log_file:, gc_requests: false, **options) super(**options) @settings = settings + @gc_requests = gc_requests # log_enabled does not exist for all exporters log_sink = log_enabled ? File.join(Rails.root, 'log', log_file) : File::NULL @@ -71,11 +72,13 @@ module Gitlab readiness = readiness_probe liveness = liveness_probe pid = thread_name + gc_requests = @gc_requests Rack::Builder.app do use Rack::Deflater use Gitlab::Metrics::Exporter::MetricsMiddleware, pid use Gitlab::Metrics::Exporter::HealthChecksMiddleware, readiness, liveness + use Gitlab::Metrics::Exporter::GcRequestMiddleware if gc_requests use ::Prometheus::Client::Rack::Exporter if ::Gitlab::Metrics.metrics_folder_present? run -> (env) { [404, {}, ['']] } end diff --git a/lib/gitlab/metrics/exporter/gc_request_middleware.rb b/lib/gitlab/metrics/exporter/gc_request_middleware.rb new file mode 100644 index 00000000000..3806b0e2bd1 --- /dev/null +++ b/lib/gitlab/metrics/exporter/gc_request_middleware.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +module Gitlab + module Metrics + module Exporter + class GcRequestMiddleware + def initialize(app) + @app = app + end + + def call(env) + @app.call(env).tap do + GC.start + end + end + end + end + end +end diff --git a/metrics_server/dependencies.rb b/metrics_server/dependencies.rb index 36d61a63359..5615cef42ce 100644 --- a/metrics_server/dependencies.rb +++ b/metrics_server/dependencies.rb @@ -26,6 +26,7 @@ require_relative '../lib/gitlab/metrics/exporter/base_exporter' require_relative '../lib/gitlab/metrics/exporter/sidekiq_exporter' require_relative '../lib/gitlab/metrics/exporter/metrics_middleware' require_relative '../lib/gitlab/metrics/exporter/health_checks_middleware' +require_relative '../lib/gitlab/metrics/exporter/gc_request_middleware' require_relative '../lib/gitlab/health_checks/probes/collection' require_relative '../lib/gitlab/health_checks/probes/status' require_relative '../lib/gitlab/process_management' diff --git a/metrics_server/metrics_server.rb b/metrics_server/metrics_server.rb index 33b31326d2a..122a4e4fc1e 100644 --- a/metrics_server/metrics_server.rb +++ b/metrics_server/metrics_server.rb @@ -54,7 +54,7 @@ class MetricsServer # rubocop:disable Gitlab/NamespacedClass exporter_class = "Gitlab::Metrics::Exporter::#{@target.camelize}Exporter".constantize settings = Settings.new(Settings.monitoring[name]) - server = exporter_class.instance(settings, synchronous: true) + server = exporter_class.instance(settings, gc_requests: true, synchronous: true) server.start end diff --git a/qa/qa/specs/features/api/1_manage/user_access_termination_spec.rb b/qa/qa/specs/features/api/1_manage/user_access_termination_spec.rb index e47e5d22e5e..6a31d173440 100644 --- a/qa/qa/specs/features/api/1_manage/user_access_termination_spec.rb +++ b/qa/qa/specs/features/api/1_manage/user_access_termination_spec.rb @@ -37,7 +37,7 @@ module QA push.file_name = 'test.txt' push.file_content = "# This is a test project named #{@project.name}" push.commit_message = 'Add test.txt' - push.branch_name = 'new_branch' + push.branch_name = "new_branch_#{SecureRandom.hex(8)}" push.user = @user end end.to raise_error(QA::Support::Run::CommandError, /You are not allowed to push code to this project/) @@ -48,7 +48,7 @@ module QA Resource::File.fabricate_via_api! do |file| file.api_client = @user_api_client file.project = @project - file.branch = 'new_branch' + file.branch = "new_branch_#{SecureRandom.hex(8)}" file.commit_message = 'Add new file' file.name = 'test.txt' file.content = "New file" @@ -61,7 +61,7 @@ module QA Resource::Repository::Commit.fabricate_via_api! do |commit| commit.api_client = @user_api_client commit.project = @project - commit.branch = 'new_branch' + commit.branch = "new_branch_#{SecureRandom.hex(8)}" commit.start_branch = @project.default_branch commit.commit_message = 'Add new file' commit.add_files([ diff --git a/spec/lib/gitlab/metrics/exporter/gc_request_middleware_spec.rb b/spec/lib/gitlab/metrics/exporter/gc_request_middleware_spec.rb new file mode 100644 index 00000000000..0c70a5de701 --- /dev/null +++ b/spec/lib/gitlab/metrics/exporter/gc_request_middleware_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +RSpec.describe Gitlab::Metrics::Exporter::GcRequestMiddleware do + let(:app) { double(:app) } + let(:env) { {} } + + subject(:middleware) { described_class.new(app) } + + describe '#call' do + it 'runs a major GC after the next middleware is called' do + expect(app).to receive(:call).with(env).ordered.and_return([200, {}, []]) + expect(GC).to receive(:start).ordered + + response = middleware.call(env) + + expect(response).to eq([200, {}, []]) + end + end +end diff --git a/spec/metrics_server/metrics_server_spec.rb b/spec/metrics_server/metrics_server_spec.rb index 1120fab2de3..fc18df9b5cd 100644 --- a/spec/metrics_server/metrics_server_spec.rb +++ b/spec/metrics_server/metrics_server_spec.rb @@ -70,7 +70,9 @@ RSpec.describe MetricsServer do # rubocop:disable RSpec/FilePath before do stub_const('Gitlab::Metrics::Exporter::FakeExporter', exporter_class) - expect(exporter_class).to receive(:instance).with(settings['fake_exporter'], synchronous: true).and_return(exporter_double) + expect(exporter_class).to receive(:instance).with( + settings['fake_exporter'], gc_requests: true, synchronous: true + ).and_return(exporter_double) expect(Settings).to receive(:monitoring).and_return(settings) allow(Gitlab::Metrics::Samplers::RubySampler).to receive(:initialize_instance).and_return(ruby_sampler_double) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 7781285f4f8..f88d741c96e 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -4581,11 +4581,25 @@ RSpec.describe Project, factory_default: :keep do include ProjectHelpers let_it_be(:group) { create(:group) } + let_it_be_with_reload(:project) { create(:project, namespace: group) } - let!(:project) { create(:project, project_level, namespace: group ) } let(:user) { create_user_from_membership(project, membership) } - context 'reporter level access' do + subject { described_class.filter_by_feature_visibility(feature, user) } + + shared_examples 'filter respects visibility' do + it 'respects visibility' do + enable_admin_mode!(user) if admin_mode + project.update!(visibility_level: Gitlab::VisibilityLevel.level_value(project_level.to_s)) + update_feature_access_level(project, feature_access_level) + + expected_objects = expected_count == 1 ? [project] : [] + + expect(subject).to eq(expected_objects) + end + end + + context 'with reporter level access' do let(:feature) { MergeRequest } where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do @@ -4593,20 +4607,11 @@ RSpec.describe Project, factory_default: :keep do end with_them do - it "respects visibility" do - enable_admin_mode!(user) if admin_mode - update_feature_access_level(project, feature_access_level) - - expected_objects = expected_count == 1 ? [project] : [] - - expect( - described_class.filter_by_feature_visibility(feature, user) - ).to eq(expected_objects) - end + it_behaves_like 'filter respects visibility' end end - context 'issues' do + context 'with feature issues' do let(:feature) { Issue } where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do @@ -4614,20 +4619,11 @@ RSpec.describe Project, factory_default: :keep do end with_them do - it "respects visibility" do - enable_admin_mode!(user) if admin_mode - update_feature_access_level(project, feature_access_level) - - expected_objects = expected_count == 1 ? [project] : [] - - expect( - described_class.filter_by_feature_visibility(feature, user) - ).to eq(expected_objects) - end + it_behaves_like 'filter respects visibility' end end - context 'wiki' do + context 'with feature wiki' do let(:feature) { :wiki } where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do @@ -4635,20 +4631,11 @@ RSpec.describe Project, factory_default: :keep do end with_them do - it "respects visibility" do - enable_admin_mode!(user) if admin_mode - update_feature_access_level(project, feature_access_level) - - expected_objects = expected_count == 1 ? [project] : [] - - expect( - described_class.filter_by_feature_visibility(feature, user) - ).to eq(expected_objects) - end + it_behaves_like 'filter respects visibility' end end - context 'code' do + context 'with feature code' do let(:feature) { :repository } where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do @@ -4656,16 +4643,7 @@ RSpec.describe Project, factory_default: :keep do end with_them do - it "respects visibility" do - enable_admin_mode!(user) if admin_mode - update_feature_access_level(project, feature_access_level) - - expected_objects = expected_count == 1 ? [project] : [] - - expect( - described_class.filter_by_feature_visibility(feature, user) - ).to eq(expected_objects) - end + it_behaves_like 'filter respects visibility' end end end