diff --git a/files/gitlab-cookbooks/gitlab/libraries/sidekiq.rb b/files/gitlab-cookbooks/gitlab/libraries/sidekiq.rb index d4a0aa558cfcaa64930b4b42f824ab4f9022f49d_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL3NpZGVraXEucmI=..c0dcd7dd919feee508faee3fe90a0440603f64f7_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvbGlicmFyaWVzL3NpZGVraXEucmI= 100644 --- a/files/gitlab-cookbooks/gitlab/libraries/sidekiq.rb +++ b/files/gitlab-cookbooks/gitlab/libraries/sidekiq.rb @@ -11,6 +11,10 @@ default_config = Gitlab['node']['gitlab']['sidekiq'] user_config = Gitlab['sidekiq'] + metrics_enabled = user_config['metrics_enabled'].nil? ? default_config['metrics_enabled'] : user_config['metrics_enabled'] + health_checks_enabled = user_config['health_checks_enabled'].nil? ? default_config['health_checks_enabled'] : user_config['health_checks_enabled'] + return unless metrics_enabled && health_checks_enabled + listen_address = user_config['listen_address'] || default_config['listen_address'] health_checks_address = user_config['health_checks_listen_address'] || default_config['health_checks_listen_address'] listen_port = user_config['listen_port'] || default_config['listen_port'] diff --git a/spec/chef/cookbooks/gitlab/recipes/default_spec.rb b/spec/chef/cookbooks/gitlab/recipes/default_spec.rb index d4a0aa558cfcaa64930b4b42f824ab4f9022f49d_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9kZWZhdWx0X3NwZWMucmI=..c0dcd7dd919feee508faee3fe90a0440603f64f7_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9kZWZhdWx0X3NwZWMucmI= 100644 --- a/spec/chef/cookbooks/gitlab/recipes/default_spec.rb +++ b/spec/chef/cookbooks/gitlab/recipes/default_spec.rb @@ -137,8 +137,8 @@ end context 'with sidekiq exporter settings' do - context 'when Sidekiq exporter and Sidekiq health checks addresses are both loopback addresses and the ports are the same' do + context 'when Sidekiq exporter is not enabled' do before do stub_gitlab_rb( sidekiq: { @@ -141,8 +141,8 @@ before do stub_gitlab_rb( sidekiq: { - metrics_enabled: true, + metrics_enabled: false, listen_address: 'localhost', listen_port: 3807, health_checks_enabled: true, @@ -152,8 +152,8 @@ ) end - it 'raises an error' do - expect { chef_run }.to raise_error("The Sidekiq metrics and health checks servers are binding the same address and port. This is unsupported in GitLab 15.0 and newer. See https://docs.gitlab.com/ee/administration/sidekiq.html for up-to-date instructions.") + it 'does not raise an error' do + expect { chef_run }.not_to raise_error end end @@ -157,7 +157,7 @@ end end - context 'when Sidekiq exporter and Sidekiq health checks port are the same' do + context 'when Sidekiq health checks is not enabled' do before do stub_gitlab_rb( sidekiq: @@ -165,10 +165,10 @@ metrics_enabled: true, listen_address: 'localhost', listen_port: 3807, - health_checks_enabled: true, - health_checks_listen_address: 'localhost', + health_checks_enabled: false, + health_checks_listen_address: '127.0.0.1', health_checks_listen_port: 3807 } ) end @@ -170,29 +170,9 @@ health_checks_listen_port: 3807 } ) end - it 'raises an error' do - expect { chef_run }.to raise_error("The Sidekiq metrics and health checks servers are binding the same address and port. This is unsupported in GitLab 15.0 and newer. See https://docs.gitlab.com/ee/administration/sidekiq.html for up-to-date instructions.") - end - end - - context 'when Sidekiq exporter and Sidekiq health checks port are different' do - before do - stub_gitlab_rb( - sidekiq: - { - metrics_enabled: true, - listen_address: 'localhost', - listen_port: 3807, - health_checks_enabled: true, - health_checks_listen_address: 'localhost', - health_checks_listen_port: 3907 - } - ) - end - it 'does not raise an error' do expect { chef_run }.not_to raise_error end end @@ -195,7 +175,69 @@ it 'does not raise an error' do expect { chef_run }.not_to raise_error end end + + context 'when both Sidekiq exporter and Sidekiq health checks are enabled' do + context 'when Sidekiq exporter and Sidekiq health checks addresses are both loopback addresses and the ports are the same' do + before do + stub_gitlab_rb( + sidekiq: + { + metrics_enabled: true, + listen_address: 'localhost', + listen_port: 3807, + health_checks_enabled: true, + health_checks_listen_address: '127.0.0.1', + health_checks_listen_port: 3807 + } + ) + end + + it 'raises an error' do + expect { chef_run }.to raise_error("The Sidekiq metrics and health checks servers are binding the same address and port. This is unsupported in GitLab 15.0 and newer. See https://docs.gitlab.com/ee/administration/sidekiq.html for up-to-date instructions.") + end + end + + context 'when Sidekiq exporter and Sidekiq health checks port are the same' do + before do + stub_gitlab_rb( + sidekiq: + { + metrics_enabled: true, + listen_address: 'localhost', + listen_port: 3807, + health_checks_enabled: true, + health_checks_listen_address: 'localhost', + health_checks_listen_port: 3807 + } + ) + end + + it 'raises an error' do + expect { chef_run }.to raise_error("The Sidekiq metrics and health checks servers are binding the same address and port. This is unsupported in GitLab 15.0 and newer. See https://docs.gitlab.com/ee/administration/sidekiq.html for up-to-date instructions.") + end + end + + context 'when Sidekiq exporter and Sidekiq health checks port are different' do + before do + stub_gitlab_rb( + sidekiq: + { + metrics_enabled: true, + listen_address: 'localhost', + listen_port: 3807, + health_checks_enabled: true, + health_checks_listen_address: 'localhost', + health_checks_listen_port: 3907 + } + ) + end + + it 'does not raise an error' do + expect { chef_run }.not_to raise_error + end + end + end end context 'with sidekiq exporter settings not set (default settings)' do