Commit 2d823995 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'create-puma-rugged-suboptimal-config-checker' into 'master'

Add banner section in admin area for  Puma-Rugged notices

See merge request gitlab-org/gitlab!21403
parents 3dcccdce 8db1d533
import initAdmin from './admin'; import initAdmin from './admin';
import initAdminStatisticsPanel from '../../admin/statistics_panel/index'; import initAdminStatisticsPanel from '../../admin/statistics_panel/index';
import initVueAlerts from '../../vue_alerts';
document.addEventListener('DOMContentLoaded', initVueAlerts);
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const statisticsPanelContainer = document.getElementById('js-admin-statistics-container'); const statisticsPanelContainer = document.getElementById('js-admin-statistics-container');
......
...@@ -12,6 +12,7 @@ class Admin::DashboardController < Admin::ApplicationController ...@@ -12,6 +12,7 @@ class Admin::DashboardController < Admin::ApplicationController
@projects = Project.order_id_desc.without_deleted.with_route.limit(10) @projects = Project.order_id_desc.without_deleted.with_route.limit(10)
@users = User.order_id_desc.limit(10) @users = User.order_id_desc.limit(10)
@groups = Group.order_id_desc.with_route.limit(10) @groups = Group.order_id_desc.with_route.limit(10)
@notices = Gitlab::ConfigChecker::PumaRuggedChecker.check
end end
# rubocop: enable CodeReuse/ActiveRecord # rubocop: enable CodeReuse/ActiveRecord
......
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
- if show_license_breakdown? - if show_license_breakdown?
= render_if_exists 'admin/licenses/breakdown', license: @license = render_if_exists 'admin/licenses/breakdown', license: @license
- if @notices
- @notices.each do |notice|
.js-vue-alert{ 'v-cloak': true, data: { variant: notice[:type],
dismissible: true.to_s } }
= notice[:message].html_safe
.admin-dashboard.prepend-top-default .admin-dashboard.prepend-top-default
.row .row
.col-sm-4 .col-sm-4
......
---
title: 'Show notices in Admin area when detected any of these cases: Puma, multi-threaded
Puma, multi-threaded Puma + Rugged'
merge_request: 21403
author:
type: added
# frozen_string_literal: true
module Gitlab
module ConfigChecker
module PumaRuggedChecker
extend self
extend Gitlab::Git::RuggedImpl::UseRugged
def check
return [] unless Gitlab::Runtime.puma?
notices = []
link_start = '<a href="https://docs.gitlab.com/ee/administration/operations/puma.html">'
link_end = '</a>'
notices << {
type: 'info',
message: _('You are running Puma, which is currently experimental. '\
'More information is available in our '\
'%{link_start}documentation%{link_end}.') % { link_start: link_start, link_end: link_end }
}
if running_puma_with_multiple_threads?
link_start = '<a href="https://docs.gitlab.com/ee/administration/operations/puma.html">'
link_end = '</a>'
notices << {
type: 'info',
message: _('Puma is running with a thread count above 1. '\
'Information on deprecated GitLab features in this configuration is available in the '\
'%{link_start}documentation%{link_end}.') % { link_start: link_start, link_end: link_end }
}
end
if running_puma_with_multiple_threads? && rugged_enabled_through_feature_flag?
link_start = '<a href="https://docs.gitlab.com/ee/administration/operations/puma.html#performance-caveat-when-using-puma-with-rugged">'
link_end = '</a>'
notices << {
type: 'warning',
message: _('Puma is running with a thread count above 1 and the rugged '\
'service is enabled. This may decrease performance in some environments. '\
'See our %{link_start}documentation%{link_end} '\
'for details of this issue.') % { link_start: link_start, link_end: link_end }
}
end
notices
end
end
end
end
...@@ -15,12 +15,6 @@ module Gitlab ...@@ -15,12 +15,6 @@ module Gitlab
Gitlab::GitalyClient.can_use_disk?(repo.storage) Gitlab::GitalyClient.can_use_disk?(repo.storage)
end end
def running_puma_with_multiple_threads?
return false unless Gitlab::Runtime.puma?
::Puma.respond_to?(:cli_config) && ::Puma.cli_config.options[:max_threads] > 1
end
def execute_rugged_call(method_name, *args) def execute_rugged_call(method_name, *args)
Gitlab::GitalyClient::StorageSettings.allow_disk_access do Gitlab::GitalyClient::StorageSettings.allow_disk_access do
start = Gitlab::Metrics::System.monotonic_time start = Gitlab::Metrics::System.monotonic_time
...@@ -43,6 +37,22 @@ module Gitlab ...@@ -43,6 +37,22 @@ module Gitlab
result result
end end
end end
def running_puma_with_multiple_threads?
return false unless Gitlab::Runtime.puma?
::Puma.respond_to?(:cli_config) && ::Puma.cli_config.options[:max_threads] > 1
end
def rugged_feature_keys
Gitlab::Git::RuggedImpl::Repository::FEATURE_FLAGS
end
def rugged_enabled_through_feature_flag?
rugged_feature_keys.any? do |feature_key|
Feature.enabled?(feature_key)
end
end
end end
end end
end end
......
...@@ -15659,6 +15659,12 @@ msgstr "" ...@@ -15659,6 +15659,12 @@ msgstr ""
msgid "Pull" msgid "Pull"
msgstr "" msgstr ""
msgid "Puma is running with a thread count above 1 and the rugged service is enabled. This may decrease performance in some environments. See our %{link_start}documentation%{link_end} for details of this issue."
msgstr ""
msgid "Puma is running with a thread count above 1. Information on deprecated GitLab features in this configuration is available in the %{link_start}documentation%{link_end}."
msgstr ""
msgid "Purchase more minutes" msgid "Purchase more minutes"
msgstr "" msgstr ""
...@@ -22173,6 +22179,9 @@ msgstr "" ...@@ -22173,6 +22179,9 @@ msgstr ""
msgid "You are receiving this message because you are a GitLab administrator for %{url}." msgid "You are receiving this message because you are a GitLab administrator for %{url}."
msgstr "" msgstr ""
msgid "You are running Puma, which is currently experimental. More information is available in our %{link_start}documentation%{link_end}."
msgstr ""
msgid "You can %{linkStart}view the blob%{linkEnd} instead." msgid "You can %{linkStart}view the blob%{linkEnd} instead."
msgstr "" msgstr ""
......
...@@ -15,6 +15,9 @@ ALLOWED = [ ...@@ -15,6 +15,9 @@ ALLOWED = [
'lib/gitlab/git/rugged_impl/', 'lib/gitlab/git/rugged_impl/',
'lib/gitlab/gitaly_client/storage_settings.rb', 'lib/gitlab/gitaly_client/storage_settings.rb',
# Needed to detect Rugged enabled: https://gitlab.com/gitlab-org/gitlab/issues/35371
'lib/gitlab/config_checker/puma_rugged_checker.rb',
# Needed for logging # Needed for logging
'config/initializers/peek.rb', 'config/initializers/peek.rb',
'config/initializers/lograge.rb', 'config/initializers/lograge.rb',
...@@ -27,7 +30,8 @@ ALLOWED = [ ...@@ -27,7 +30,8 @@ ALLOWED = [
rugged_lines = IO.popen(%w[git grep -i -n rugged -- app config lib], &:read).lines rugged_lines = IO.popen(%w[git grep -i -n rugged -- app config lib], &:read).lines
rugged_lines = rugged_lines.select { |l| /^[^:]*\.rb:/ =~ l } rugged_lines = rugged_lines.select { |l| /^[^:]*\.rb:/ =~ l }
rugged_lines = rugged_lines.reject { |l| l.start_with?(*ALLOWED) } rugged_lines = rugged_lines.reject { |l| l.start_with?(*ALLOWED) }
rugged_lines = rugged_lines.reject { |l| /(include|prepend) Gitlab::Git::RuggedImpl/ =~ l} rugged_lines = rugged_lines.reject { |l| /(include|prepend) Gitlab::Git::RuggedImpl/ =~ l }
rugged_lines = rugged_lines.reject { |l| l.include?('Gitlab::ConfigChecker::PumaRuggedChecker.check') }
rugged_lines = rugged_lines.reject do |line| rugged_lines = rugged_lines.reject do |line|
code, _comment = line.split('# ', 2) code, _comment = line.split('# ', 2)
code !~ /rugged/i code !~ /rugged/i
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::ConfigChecker::PumaRuggedChecker do
describe '#check' do
subject { described_class.check }
context 'application is not puma' do
before do
allow(Gitlab::Runtime).to receive(:puma?).and_return(false)
end
it { is_expected.to be_empty }
end
context 'application is puma' do
let(:notice_running_puma) do
{
type: 'info',
message: 'You are running Puma, which is currently experimental. '\
'More information is available in our '\
'<a href="https://docs.gitlab.com/ee/administration/operations/puma.html">documentation</a>.'
}
end
let(:notice_multi_threaded_puma) do
{
type: 'info',
message: 'Puma is running with a thread count above 1. '\
'Information on deprecated GitLab features in this configuration is available in the '\
'<a href="https://docs.gitlab.com/ee/administration/operations/puma.html">documentation</a>.'\
}
end
let(:notice_multi_threaded_puma_with_rugged) do
{
type: 'warning',
message: 'Puma is running with a thread count above 1 and the rugged '\
'service is enabled. This may decrease performance in some environments. '\
'See our <a href="https://docs.gitlab.com/ee/administration/operations/puma.html#performance-caveat-when-using-puma-with-rugged">documentation</a> '\
'for details of this issue.'
}
end
before do
allow(Gitlab::Runtime).to receive(:puma?).and_return(true)
allow(described_class).to receive(:running_puma_with_multiple_threads?).and_return(multithreaded_puma)
allow(described_class).to receive(:rugged_enabled_through_feature_flag?).and_return(rugged_enabled)
end
context 'not multithreaded_puma and rugged API enabled' do
let(:multithreaded_puma) { false }
let(:rugged_enabled) { true }
it 'report running puma notice' do
is_expected.to contain_exactly(notice_running_puma)
end
end
context 'not multithreaded_puma and rugged API is not enabled' do
let(:multithreaded_puma) { false }
let(:rugged_enabled) { false }
it 'report running puma notice' do
is_expected.to contain_exactly(notice_running_puma)
end
end
context 'multithreaded_puma and rugged API is not enabled' do
let(:multithreaded_puma) { true }
let(:rugged_enabled) { false }
it 'report running puma notice and multi-thread puma notice' do
is_expected.to contain_exactly(notice_running_puma, notice_multi_threaded_puma)
end
end
context 'multithreaded_puma and rugged API is enabled' do
let(:multithreaded_puma) { true }
let(:rugged_enabled) { true }
it 'report puma/multi_threaded_puma/multi_threaded_puma_with_rugged notices' do
is_expected.to contain_exactly(notice_running_puma, notice_multi_threaded_puma, notice_multi_threaded_puma_with_rugged)
end
end
end
end
end
...@@ -152,6 +152,43 @@ describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do ...@@ -152,6 +152,43 @@ describe Gitlab::Git::RuggedImpl::UseRugged, :seed_helper do
end end
end end
describe '#rugged_enabled_through_feature_flag?' do
subject { wrapper.send(:rugged_enabled_through_feature_flag?) }
before do
allow(Feature).to receive(:enabled?).with(:feature_key_1).and_return(true)
allow(Feature).to receive(:enabled?).with(:feature_key_2).and_return(true)
allow(Feature).to receive(:enabled?).with(:feature_key_3).and_return(false)
allow(Feature).to receive(:enabled?).with(:feature_key_4).and_return(false)
stub_const('Gitlab::Git::RuggedImpl::Repository::FEATURE_FLAGS', feature_keys)
end
context 'no feature keys given' do
let(:feature_keys) { [] }
it { is_expected.to be_falsey }
end
context 'all features are enabled' do
let(:feature_keys) { [:feature_key_1, :feature_key_2] }
it { is_expected.to be_truthy}
end
context 'all features are not enabled' do
let(:feature_keys) { [:feature_key_3, :feature_key_4] }
it { is_expected.to be_falsey }
end
context 'some feature is enabled' do
let(:feature_keys) { [:feature_key_4, :feature_key_2] }
it { is_expected.to be_truthy }
end
end
def create_temporary_gitaly_metadata_file def create_temporary_gitaly_metadata_file
tmp = Tempfile.new('.gitaly-metadata') tmp = Tempfile.new('.gitaly-metadata')
gitaly_metadata = { gitaly_metadata = {
......
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