Skip to content
Snippets Groups Projects
Commit 077c2d90 authored by DJ Mountney's avatar DJ Mountney
Browse files

Merge branch 'add-img-resizing-configs' into 'master'

Add Image Resizer config defaults

See merge request gitlab-org/omnibus-gitlab!4639
parents 1505cd44 9ae65d18
No related branches found
No related tags found
No related merge requests found
---
title: Add Image Resizer config defaults
merge_request: 4639
author:
type: other
Loading
Loading
@@ -841,6 +841,16 @@ external_url 'GENERATED_EXTERNAL_URL'
# 'SSL_CERT_DIR' => "/opt/gitlab/embedded/ssl/certs/"
# }
 
##! Resource limitations for the dynamic image scaler.
##! Exceeding these thresholds will cause Workhorse to serve images in their original size.
##!
##! Maximum number of scaler processes that are allowed to execute concurrently.
##! It is recommended for this not to exceed the number of CPUs available.
# gitlab_workhorse['image_scaler_max_procs'] = 4
##!
##! Maximum file size in bytes for an image to be considered eligible for rescaling
# gitlab_workhorse['image_scaler_max_filesize'] = 250000
################################################################################
## GitLab User Settings
##! Modify default git user.
Loading
Loading
Loading
Loading
@@ -644,6 +644,8 @@ default['gitlab']['gitlab-workhorse']['env'] = {
'HOME' => node['gitlab']['user']['home'],
'SSL_CERT_DIR' => "#{node['package']['install-dir']}/embedded/ssl/certs/"
}
default['gitlab']['gitlab-workhorse']['image_scaler_max_procs'] = [2, node['cpu']['total'].to_i / 2].max
default['gitlab']['gitlab-workhorse']['image_scaler_max_filesize'] = 250_000
 
####
# mailroom
Loading
Loading
Loading
Loading
@@ -87,13 +87,25 @@ config_file_path = File.join(working_dir, "config.toml")
object_store = node['gitlab']['gitlab-rails']['object_store']
provider = object_store.dig('connection', 'provider')
object_store_provider = provider if %w(AWS AzureRM).include?(provider)
image_scaler_max_procs = node['gitlab']['gitlab-workhorse']['image_scaler_max_procs']
image_scaler_max_filesize = node['gitlab']['gitlab-workhorse']['image_scaler_max_filesize']
 
template config_file_path do
source "workhorse-config.toml.erb"
owner "root"
group account_helper.gitlab_group
mode "0640"
variables(object_store: object_store, object_store_provider: object_store_provider, redis_url: redis_url, password: redis_password, sentinels: redis_sentinels, sentinel_master: redis_sentinel_master, master_password: redis_sentinel_master_password)
variables(
object_store: object_store,
object_store_provider: object_store_provider,
redis_url: redis_url,
password: redis_password,
sentinels: redis_sentinels,
sentinel_master: redis_sentinel_master,
master_password: redis_sentinel_master_password,
image_scaler_max_procs: image_scaler_max_procs,
image_scaler_max_filesize: image_scaler_max_filesize
)
notifies :restart, "runit_service[gitlab-workhorse]"
notifies :run, 'bash[Set proper security context on ssh files for selinux]', :delayed if SELinuxHelper.enabled?
end
Loading
Loading
@@ -22,3 +22,7 @@ Password = "<%= @master_password %>"
azure_storage_access_key = "<%= @object_store.dig('connection', 'azure_storage_access_key') %>"
<%- end %>
<%- end %>
[image_resizer]
max_scaler_procs = <%= @image_scaler_max_procs %>
max_filesize = <%= @image_scaler_max_filesize %>
require 'chef_helper'
 
RSpec.describe 'gitlab::gitlab-workhorse' do
let(:chef_run) { ChefSpec::SoloRunner.new(step_into: %w(runit_service)).converge('gitlab::default') }
let(:node_cpus) { 1 }
let(:chef_run) do
ChefSpec::SoloRunner.new(step_into: %w(runit_service)) do |node|
node.automatic['cpu']['total'] = node_cpus
end.converge('gitlab::default')
end
let(:default_vars) do
{
'SSL_CERT_DIR' => '/opt/gitlab/embedded/ssl/certs/',
Loading
Loading
@@ -408,4 +413,51 @@ RSpec.describe 'gitlab::gitlab-workhorse' do
expect(chef_run).not_to render_file("/var/opt/gitlab/gitlab-workhorse/config.toml").with_content(content_url)
end
end
context 'image scaler' do
context 'with default values' do
it 'sets the default maximum file size' do
expect(chef_run).to render_file(config_file).with_content { |content|
expect(content).to match(/\[image_resizer\]\n max_scaler_procs = \d+\n max_filesize = 250000/m)
}
end
context 'when reported CPU cores are at least 4' do
let(:node_cpus) { 4 }
it 'sets default max procs to half the number of cores' do
expect(chef_run).to render_file(config_file).with_content { |content|
expect(content).to match(/\[image_resizer\]\n max_scaler_procs = 2/m)
}
end
end
context 'when reported CPU cores are less than 4' do
let(:node_cpus) { 3 }
it 'pins default max procs to 2' do
expect(chef_run).to render_file(config_file).with_content { |content|
expect(content).to match(/\[image_resizer\]\n max_scaler_procs = 2/m)
}
end
end
end
context 'with custom values' do
before do
stub_gitlab_rb(
gitlab_workhorse: {
image_scaler_max_procs: 5,
image_scaler_max_filesize: 1024
}
)
end
it 'should generate config file with the specified values' do
expect(chef_run).to render_file(config_file).with_content { |content|
expect(content).to match(/\[image_resizer\]\n max_scaler_procs = 5\n max_filesize = 1024/m)
}
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment