Commit b4f8e281 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch 'rs-basic-config-files-ee' into 'master'

Wrap EE-only initializer settings in `Gitlab.ee` blocks

See merge request gitlab-org/gitlab-ee!14602
parents f4d2d082 d2b2791e
...@@ -6,6 +6,7 @@ Bundler.require(:default, Rails.env) ...@@ -6,6 +6,7 @@ Bundler.require(:default, Rails.env)
module Gitlab module Gitlab
class Application < Rails::Application class Application < Rails::Application
require_dependency Rails.root.join('lib/gitlab')
require_dependency Rails.root.join('lib/gitlab/redis/wrapper') 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/cache')
require_dependency Rails.root.join('lib/gitlab/redis/queues') require_dependency Rails.root.join('lib/gitlab/redis/queues')
......
begin # frozen_string_literal: true
public_key_file = File.read(Rails.root.join(".license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file) Gitlab.ee do
Gitlab::License.encryption_key = public_key begin
rescue public_key_file = File.read(Rails.root.join(".license_encryption_key.pub"))
warn "WARNING: No valid license encryption key provided." public_key = OpenSSL::PKey::RSA.new(public_key_file)
end Gitlab::License.encryption_key = public_key
rescue
warn "WARNING: No valid license encryption key provided."
end
# Needed to run migration # Needed to run migration
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses') if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses')
message = LicenseHelper.license_message(signed_in: true, is_admin: true, in_html: false) message = LicenseHelper.license_message(signed_in: true, is_admin: true, in_html: false)
if ::License.block_changes? && message.present? if ::License.block_changes? && message.present?
warn "WARNING: #{message}" warn "WARNING: #{message}"
end
end end
end end
...@@ -2,17 +2,18 @@ ...@@ -2,17 +2,18 @@
if defined?(Rails::Console) if defined?(Rails::Console)
# note that this will not print out when using `spring` # note that this will not print out when using `spring`
justify = 15 justify = 15
puts "-------------------------------------------------------------------------------------"
puts '-' * 80
puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision})" puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision})"
puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.new.version)}" puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.new.version)}"
puts " #{Gitlab::Database.human_adapter_name}:".ljust(justify) + Gitlab::Database.version puts " #{Gitlab::Database.human_adapter_name}:".ljust(justify) + Gitlab::Database.version
# EE-specific start Gitlab.ee do
if Gitlab::Geo.enabled? if Gitlab::Geo.enabled?
puts " Geo enabled:".ljust(justify) + 'yes' puts " Geo enabled:".ljust(justify) + 'yes'
puts " Geo server:".ljust(justify) + EE::GeoHelper.current_node_human_status puts " Geo server:".ljust(justify) + EE::GeoHelper.current_node_human_status
end
end end
# EE specific end
puts "-------------------------------------------------------------------------------------" puts '-' * 80
end end
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
require 'gitlab/current_settings' require 'gitlab/current_settings'
Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records Gitlab.ee do
Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records
Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods Elasticsearch::Model::Adapter::Multiple::Records.prepend GemExtensions::Elasticsearch::Model::Adapter::Multiple::Records
Elasticsearch::Model::Indexing::InstanceMethods.prepend GemExtensions::Elasticsearch::Model::Indexing::InstanceMethods
module Elasticsearch
module Model module Elasticsearch
module Client module Model
# This mutex is only used to synchronize *creation* of a new client, so module Client
# all including classes can share the same client instance # This mutex is only used to synchronize *creation* of a new client, so
CLIENT_MUTEX = Mutex.new # all including classes can share the same client instance
CLIENT_MUTEX = Mutex.new
cattr_accessor :cached_client
cattr_accessor :cached_config cattr_accessor :cached_client
cattr_accessor :cached_config
module ClassMethods
# Override the default ::Elasticsearch::Model::Client implementation to module ClassMethods
# return a client configured from application settings. All including # Override the default ::Elasticsearch::Model::Client implementation to
# classes will use the same instance, which is refreshed automatically # return a client configured from application settings. All including
# if the settings change. # classes will use the same instance, which is refreshed automatically
# # if the settings change.
# _client is present to match the arity of the overridden method, where #
# it is also not used. # _client is present to match the arity of the overridden method, where
# # it is also not used.
# @return [Elasticsearch::Transport::Client] #
def client(_client = nil) # @return [Elasticsearch::Transport::Client]
store = ::Elasticsearch::Model::Client def client(_client = nil)
store = ::Elasticsearch::Model::Client
store::CLIENT_MUTEX.synchronize do
config = Gitlab::CurrentSettings.elasticsearch_config store::CLIENT_MUTEX.synchronize do
config = Gitlab::CurrentSettings.elasticsearch_config
if store.cached_client.nil? || config != store.cached_config
store.cached_client = ::Gitlab::Elastic::Client.build(config) if store.cached_client.nil? || config != store.cached_config
store.cached_config = config store.cached_client = ::Gitlab::Elastic::Client.build(config)
store.cached_config = config
end
end end
end
store.cached_client store.cached_client
end
end end
end end
end end
......
if File.exist?(Rails.root.join('config/database_geo.yml')) # frozen_string_literal: true
Rails.application.configure do
config.geo_database = config_for(:database_geo) Gitlab.ee do
if File.exist?(Rails.root.join('config/database_geo.yml'))
Rails.application.configure do
config.geo_database = config_for(:database_geo)
end
end end
end
begin begin
if Gitlab::Geo.connected? && Gitlab::Geo.primary? if Gitlab::Geo.connected? && Gitlab::Geo.primary?
Gitlab::Geo.current_node&.update_clone_url! Gitlab::Geo.current_node&.update_clone_url!
end
rescue => e
warn "WARNING: Unable to check/update clone_url_prefix for Geo: #{e}"
end end
rescue => e
warn "WARNING: Unable to check/update clone_url_prefix for Geo: #{e}"
end end
...@@ -2,7 +2,9 @@ HealthCheck.setup do |config| ...@@ -2,7 +2,9 @@ HealthCheck.setup do |config|
config.standard_checks = %w(database migrations cache) config.standard_checks = %w(database migrations cache)
config.full_checks = %w(database migrations cache) config.full_checks = %w(database migrations cache)
config.add_custom_check('geo') do Gitlab.ee do
Gitlab::Geo::HealthCheck.new.perform_checks config.add_custom_check('geo') do
Gitlab::Geo::HealthCheck.new.perform_checks
end
end end
end end
# frozen_string_literal: true
# We need to run this initializer after migrations are done so it doesn't fail on CI # We need to run this initializer after migrations are done so it doesn't fail on CI
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses')
if Gitlab::Database::LoadBalancing.enable?
Gitlab::Database.disable_prepared_statements
Gitlab::Application.configure do |config| Gitlab.ee do
config.middleware.use(Gitlab::Database::LoadBalancing::RackMiddleware) if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses')
end if Gitlab::Database::LoadBalancing.enable?
Gitlab::Database.disable_prepared_statements
Gitlab::Database::LoadBalancing.configure_proxy Gitlab::Application.configure do |config|
config.middleware.use(Gitlab::Database::LoadBalancing::RackMiddleware)
end
# This needs to be executed after fork of clustered processes Gitlab::Database::LoadBalancing.configure_proxy
Gitlab::Cluster::LifecycleEvents.on_worker_start do
# Service discovery must be started after configuring the proxy, as service
# discovery depends on this.
Gitlab::Database::LoadBalancing.start_service_discovery
end
# This needs to be executed after fork of clustered processes
Gitlab::Cluster::LifecycleEvents.on_worker_start do
# Service discovery must be started after configuring the proxy, as service
# discovery depends on this.
Gitlab::Database::LoadBalancing.start_service_discovery
end
end
end end
end end
...@@ -77,10 +77,6 @@ Sidekiq.configure_server do |config| ...@@ -77,10 +77,6 @@ Sidekiq.configure_server do |config|
end end
Sidekiq::Cron::Job.load_from_hash! cron_jobs Sidekiq::Cron::Job.load_from_hash! cron_jobs
Gitlab::Mirror.configure_cron_job!
Gitlab::Geo.configure_cron_jobs!
Gitlab::SidekiqVersioning.install! Gitlab::SidekiqVersioning.install!
db_config = Gitlab::Database.config || db_config = Gitlab::Database.config ||
...@@ -89,12 +85,17 @@ Sidekiq.configure_server do |config| ...@@ -89,12 +85,17 @@ Sidekiq.configure_server do |config|
ActiveRecord::Base.establish_connection(db_config) ActiveRecord::Base.establish_connection(db_config)
Rails.logger.debug("Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}") Rails.logger.debug("Connection Pool size for Sidekiq Server is now: #{ActiveRecord::Base.connection.pool.instance_variable_get('@size')}")
# EE only Gitlab.ee do
if Gitlab::Geo.geo_database_configured? Gitlab::Mirror.configure_cron_job!
Rails.configuration.geo_database['pool'] = Sidekiq.options[:concurrency]
Geo::TrackingBase.establish_connection(Rails.configuration.geo_database) Gitlab::Geo.configure_cron_jobs!
Rails.logger.debug("Connection Pool size for Sidekiq Server is now: #{Geo::TrackingBase.connection_pool.size} (Geo tracking database)") if Gitlab::Geo.geo_database_configured?
Rails.configuration.geo_database['pool'] = Sidekiq.options[:concurrency]
Geo::TrackingBase.establish_connection(Rails.configuration.geo_database)
Rails.logger.debug("Connection Pool size for Sidekiq Server is now: #{Geo::TrackingBase.connection_pool.size} (Geo tracking database)")
end
end end
# Avoid autoload issue such as 'Mail::Parsers::AddressStruct' # Avoid autoload issue such as 'Mail::Parsers::AddressStruct'
......
if ENV['ENABLE_SIDEKIQ_CLUSTER'] # frozen_string_literal: true
if ENV['ENABLE_SIDEKIQ_CLUSTER'] && Gitlab.ee?
Thread.new do Thread.new do
Thread.current.abort_on_exception = true Thread.current.abort_on_exception = true
......
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