Commit 5a0eab44 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Use env variables for ActionCable configuration

This is going to be used early when computing Runtime.max_threads so
we can't use gitlab.yml to store these.
parent 790ea015
......@@ -17,6 +17,7 @@ module Gitlab
class Application < Rails::Application
require_dependency Rails.root.join('lib/gitlab')
require_dependency Rails.root.join('lib/gitlab/utils')
require_dependency Rails.root.join('lib/gitlab/action_cable/config')
require_dependency Rails.root.join('lib/gitlab/redis/wrapper')
require_dependency Rails.root.join('lib/gitlab/redis/cache')
require_dependency Rails.root.join('lib/gitlab/redis/queues')
......
......@@ -54,4 +54,8 @@ Rails.application.configure do
config.logger = ActiveSupport::TaggedLogging.new(Logger.new(nil))
config.log_level = :fatal
end
# Mount the ActionCable Engine in-app so that we don't have to spawn another Puma
# process for feature specs
ENV['ACTION_CABLE_IN_APP'] = 'true'
end
......@@ -515,7 +515,7 @@ production: &base
# NOTE: This will only take effect if elasticsearch is enabled.
elastic_index_bulk_cron_worker:
cron: "*/1 * * * *"
# Elasticsearch bulk updater for initial updates.
# NOTE: This will only take effect if elasticsearch is enabled.
elastic_index_initial_bulk_cron_worker:
......@@ -1111,14 +1111,6 @@ production: &base
# host: localhost
# port: 3808
## ActionCable settings
action_cable:
# Enables handling of ActionCable requests on the Puma web workers
# When this is disabled, a standalone ActionCable server must be started
in_app: true
# Number of threads used to process ActionCable connection callbacks and channel actions
# worker_pool_size: 4
## Monitoring
# Built in monitoring settings
monitoring:
......
......@@ -740,13 +740,6 @@ Settings.webpack.dev_server['enabled'] ||= false
Settings.webpack.dev_server['host'] ||= 'localhost'
Settings.webpack.dev_server['port'] ||= 3808
#
# ActionCable settings
#
Settings['action_cable'] ||= Settingslogic.new({})
Settings.action_cable['in_app'] ||= false
Settings.action_cable['worker_pool_size'] ||= 4
#
# Monitoring settings
#
......
......@@ -4,10 +4,10 @@ require 'action_cable/subscription_adapter/redis'
Rails.application.configure do
# Mount the ActionCable engine when in-app mode is enabled
config.action_cable.mount_path = Gitlab.config.action_cable.in_app ? '/-/cable' : nil
config.action_cable.mount_path = Gitlab::ActionCable::Config.in_app? ? '/-/cable' : nil
config.action_cable.url = Gitlab::Utils.append_path(Gitlab.config.gitlab.relative_url_root, '/-/cable')
config.action_cable.worker_pool_size = Gitlab.config.action_cable.worker_pool_size
config.action_cable.worker_pool_size = Gitlab::ActionCable::Config.worker_pool_size
end
# https://github.com/rails/rails/blob/bb5ac1623e8de08c1b7b62b1368758f0d3bb6379/actioncable/lib/action_cable/subscription_adapter/redis.rb#L18
......
# frozen_string_literal: true
module Gitlab
module ActionCable
class Config
class << self
def in_app?
Gitlab::Utils.to_boolean(ENV.fetch('ACTION_CABLE_IN_APP', false))
end
def worker_pool_size
ENV.fetch('ACTION_CABLE_WORKER_POOL_SIZE', 4).to_i
end
end
end
end
end
......@@ -74,7 +74,7 @@ module Gitlab
end
def action_cable?
web_server? && (!!defined?(ACTION_CABLE_SERVER) || Gitlab.config.action_cable.in_app)
web_server? && (!!defined?(ACTION_CABLE_SERVER) || Gitlab::ActionCable::Config.in_app?)
end
def multi_threaded?
......@@ -93,7 +93,7 @@ module Gitlab
end
if action_cable?
threads += Gitlab.config.action_cable.worker_pool_size
threads += Gitlab::ActionCable::Config.worker_pool_size
end
threads
......
......@@ -48,14 +48,15 @@ RSpec.describe Gitlab::Runtime do
before do
stub_const('::Puma', puma_type)
allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(max_threads: 2)
stub_config(action_cable: { in_app: false })
stub_env('ACTION_CABLE_IN_APP', 'false')
end
it_behaves_like "valid runtime", :puma, 3
context "when ActionCable in-app mode is enabled" do
before do
stub_config(action_cable: { in_app: true, worker_pool_size: 3 })
stub_env('ACTION_CABLE_IN_APP', 'true')
stub_env('ACTION_CABLE_WORKER_POOL_SIZE', '3')
end
it_behaves_like "valid runtime", :puma, 6
......@@ -64,7 +65,7 @@ RSpec.describe Gitlab::Runtime do
context "when ActionCable standalone is run" do
before do
stub_const('ACTION_CABLE_SERVER', true)
stub_config(action_cable: { worker_pool_size: 8 })
stub_env('ACTION_CABLE_WORKER_POOL_SIZE', '8')
end
it_behaves_like "valid runtime", :puma, 11
......@@ -75,14 +76,15 @@ RSpec.describe Gitlab::Runtime do
before do
stub_const('::Unicorn', Module.new)
stub_const('::Unicorn::HttpServer', Class.new)
stub_config(action_cable: { in_app: false })
stub_env('ACTION_CABLE_IN_APP', 'false')
end
it_behaves_like "valid runtime", :unicorn, 1
context "when ActionCable in-app mode is enabled" do
before do
stub_config(action_cable: { in_app: true, worker_pool_size: 3 })
stub_env('ACTION_CABLE_IN_APP', 'true')
stub_env('ACTION_CABLE_WORKER_POOL_SIZE', '3')
end
it_behaves_like "valid runtime", :unicorn, 4
......
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