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)
module Gitlab
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/cache')
require_dependency Rails.root.join('lib/gitlab/redis/queues')
......
begin
public_key_file = File.read(Rails.root.join(".license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key
rescue
warn "WARNING: No valid license encryption key provided."
end
# frozen_string_literal: true
Gitlab.ee do
begin
public_key_file = File.read(Rails.root.join(".license_encryption_key.pub"))
public_key = OpenSSL::PKey::RSA.new(public_key_file)
Gitlab::License.encryption_key = public_key
rescue
warn "WARNING: No valid license encryption key provided."
end
# Needed to run migration
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses')
message = LicenseHelper.license_message(signed_in: true, is_admin: true, in_html: false)
if ::License.block_changes? && message.present?
warn "WARNING: #{message}"
# Needed to run migration
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses')
message = LicenseHelper.license_message(signed_in: true, is_admin: true, in_html: false)
if ::License.block_changes? && message.present?
warn "WARNING: #{message}"
end
end
end
......@@ -2,17 +2,18 @@
if defined?(Rails::Console)
# note that this will not print out when using `spring`
justify = 15
puts "-------------------------------------------------------------------------------------"
puts '-' * 80
puts " GitLab:".ljust(justify) + "#{Gitlab::VERSION} (#{Gitlab.revision})"
puts " GitLab Shell:".ljust(justify) + "#{Gitlab::VersionInfo.parse(Gitlab::Shell.new.version)}"
puts " #{Gitlab::Database.human_adapter_name}:".ljust(justify) + Gitlab::Database.version
# EE-specific start
if Gitlab::Geo.enabled?
puts " Geo enabled:".ljust(justify) + 'yes'
puts " Geo server:".ljust(justify) + EE::GeoHelper.current_node_human_status
Gitlab.ee do
if Gitlab::Geo.enabled?
puts " Geo enabled:".ljust(justify) + 'yes'
puts " Geo server:".ljust(justify) + EE::GeoHelper.current_node_human_status
end
end
# EE specific end
puts "-------------------------------------------------------------------------------------"
puts '-' * 80
end
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
require 'gitlab/current_settings'
Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records
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 Client
# This mutex is only used to synchronize *creation* of a new client, so
# all including classes can share the same client instance
CLIENT_MUTEX = Mutex.new
cattr_accessor :cached_client
cattr_accessor :cached_config
module ClassMethods
# Override the default ::Elasticsearch::Model::Client implementation to
# return a client configured from application settings. All including
# 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.
#
# @return [Elasticsearch::Transport::Client]
def client(_client = nil)
store = ::Elasticsearch::Model::Client
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)
store.cached_config = config
Gitlab.ee do
Elasticsearch::Model::Response::Records.prepend GemExtensions::Elasticsearch::Model::Response::Records
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 Client
# This mutex is only used to synchronize *creation* of a new client, so
# all including classes can share the same client instance
CLIENT_MUTEX = Mutex.new
cattr_accessor :cached_client
cattr_accessor :cached_config
module ClassMethods
# Override the default ::Elasticsearch::Model::Client implementation to
# return a client configured from application settings. All including
# 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.
#
# @return [Elasticsearch::Transport::Client]
def client(_client = nil)
store = ::Elasticsearch::Model::Client
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)
store.cached_config = config
end
end
end
store.cached_client
store.cached_client
end
end
end
end
......
if File.exist?(Rails.root.join('config/database_geo.yml'))
Rails.application.configure do
config.geo_database = config_for(:database_geo)
# frozen_string_literal: true
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
begin
if Gitlab::Geo.connected? && Gitlab::Geo.primary?
Gitlab::Geo.current_node&.update_clone_url!
begin
if Gitlab::Geo.connected? && Gitlab::Geo.primary?
Gitlab::Geo.current_node&.update_clone_url!
end
rescue => e
warn "WARNING: Unable to check/update clone_url_prefix for Geo: #{e}"
end
rescue => e
warn "WARNING: Unable to check/update clone_url_prefix for Geo: #{e}"
end
......@@ -2,7 +2,9 @@ HealthCheck.setup do |config|
config.standard_checks = %w(database migrations cache)
config.full_checks = %w(database migrations cache)
config.add_custom_check('geo') do
Gitlab::Geo::HealthCheck.new.perform_checks
Gitlab.ee do
config.add_custom_check('geo') do
Gitlab::Geo::HealthCheck.new.perform_checks
end
end
end
# frozen_string_literal: true
# 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|
config.middleware.use(Gitlab::Database::LoadBalancing::RackMiddleware)
end
Gitlab.ee do
if ActiveRecord::Base.connected? && ActiveRecord::Base.connection.data_source_exists?('licenses')
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::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
Gitlab::Database::LoadBalancing.configure_proxy
# 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
......@@ -77,10 +77,6 @@ Sidekiq.configure_server do |config|
end
Sidekiq::Cron::Job.load_from_hash! cron_jobs
Gitlab::Mirror.configure_cron_job!
Gitlab::Geo.configure_cron_jobs!
Gitlab::SidekiqVersioning.install!
db_config = Gitlab::Database.config ||
......@@ -89,12 +85,17 @@ Sidekiq.configure_server do |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')}")
# EE only
if Gitlab::Geo.geo_database_configured?
Rails.configuration.geo_database['pool'] = Sidekiq.options[:concurrency]
Geo::TrackingBase.establish_connection(Rails.configuration.geo_database)
Gitlab.ee do
Gitlab::Mirror.configure_cron_job!
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
# 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.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