Commit 60f2892d authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'enable-zeitwerk' into 'master'

[RUN ALL RSPEC] [RUN AS-IF-FOSS] Switch to Zeitwerk autoloader

See merge request gitlab-org/gitlab!64321
parents d608ed99 5118ca34
...@@ -2305,7 +2305,6 @@ Gitlab/NamespacedClass: ...@@ -2305,7 +2305,6 @@ Gitlab/NamespacedClass:
- 'ee/app/workers/sync_security_reports_to_report_approval_rules_worker.rb' - 'ee/app/workers/sync_security_reports_to_report_approval_rules_worker.rb'
- 'ee/app/workers/update_all_mirrors_worker.rb' - 'ee/app/workers/update_all_mirrors_worker.rb'
- 'ee/app/workers/update_max_seats_used_for_gitlab_com_subscriptions_worker.rb' - 'ee/app/workers/update_max_seats_used_for_gitlab_com_subscriptions_worker.rb'
- 'ee/lib/generators/rails/geo_migration_generator.rb'
- 'ee/lib/gitlab/path_locks_finder.rb' - 'ee/lib/gitlab/path_locks_finder.rb'
- 'ee/spec/support/elastic_query_name_inspector.rb' - 'ee/spec/support/elastic_query_name_inspector.rb'
- 'ee/spec/support/ssh_keygen.rb' - 'ee/spec/support/ssh_keygen.rb'
......
...@@ -32,7 +32,7 @@ module Gitlab ...@@ -32,7 +32,7 @@ module Gitlab
require_dependency Rails.root.join('lib/gitlab/middleware/rack_multipart_tempfile_factory') require_dependency Rails.root.join('lib/gitlab/middleware/rack_multipart_tempfile_factory')
require_dependency Rails.root.join('lib/gitlab/runtime') require_dependency Rails.root.join('lib/gitlab/runtime')
config.autoloader = :classic config.autoloader = :zeitwerk
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
...@@ -86,7 +86,11 @@ module Gitlab ...@@ -86,7 +86,11 @@ module Gitlab
# Rake tasks ignore the eager loading settings, so we need to set the # Rake tasks ignore the eager loading settings, so we need to set the
# autoload paths explicitly # autoload paths explicitly
config.autoload_paths = config.eager_load_paths.dup config.autoload_paths = config.eager_load_paths.dup
# These are only used in Rake tasks so we don't need to add these to eager_load_paths
config.autoload_paths.push("#{config.root}/lib/generators") config.autoload_paths.push("#{config.root}/lib/generators")
Gitlab.ee { config.autoload_paths.push("#{config.root}/ee/lib/generators") }
Gitlab.jh { config.autoload_paths.push("#{config.root}/jh/lib/generators") }
# Only load the plugins named here, in the order given (default is alphabetical). # Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named. # :all can be used as a placeholder for all plugins not explicitly named.
......
# frozen_string_literal: true
require_dependency 'gitlab'
...@@ -5,15 +5,11 @@ Rails.autoloaders.each do |autoloader| ...@@ -5,15 +5,11 @@ Rails.autoloaders.each do |autoloader|
# that do not define Ruby classes / modules # that do not define Ruby classes / modules
autoloader.ignore(Rails.root.join('lib/support')) autoloader.ignore(Rails.root.join('lib/support'))
# Ignore generators since these are loaded manually by Rails # Mailer previews are loaded manually by Rails
# https://github.com/rails/rails/blob/v6.1.3.2/railties/lib/rails/command/behavior.rb#L56-L65
autoloader.ignore(Rails.root.join('lib/generators'))
autoloader.ignore(Rails.root.join('ee/lib/generators')) if Gitlab.ee?
# Mailer previews are also loaded manually by Rails
# https://github.com/rails/rails/blob/v6.1.3.2/actionmailer/lib/action_mailer/preview.rb#L121-L125 # https://github.com/rails/rails/blob/v6.1.3.2/actionmailer/lib/action_mailer/preview.rb#L121-L125
autoloader.ignore(Rails.root.join('app/mailers/previews')) autoloader.ignore(Rails.root.join('app/mailers/previews'))
autoloader.ignore(Rails.root.join('ee/app/mailers/previews')) if Gitlab.ee? autoloader.ignore(Rails.root.join('ee/app/mailers/previews')) if Gitlab.ee?
autoloader.ignore(Rails.root.join('jh/app/mailers/previews')) if Gitlab.jh?
autoloader.inflector.inflect( autoloader.inflector.inflect(
'api' => 'API', 'api' => 'API',
......
...@@ -389,7 +389,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -389,7 +389,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
namespace :design_management do namespace :design_management do
namespace :designs, path: 'designs/:design_id(/:sha)', constraints: -> (params) { params[:sha].nil? || Gitlab::Git.commit_id?(params[:sha]) } do namespace :designs, path: 'designs/:design_id(/:sha)', constraints: -> (params) { params[:sha].nil? || Gitlab::Git.commit_id?(params[:sha]) } do
resource :raw_image, only: :show resource :raw_image, only: :show
resources :resized_image, only: :show, constraints: -> (params) { DesignManagement::DESIGN_IMAGE_SIZES.include?(params[:id]) } resources :resized_image, only: :show, constraints: -> (params) { ::DesignManagement::DESIGN_IMAGE_SIZES.include?(params[:id]) }
end end
end end
......
...@@ -3,12 +3,6 @@ ...@@ -3,12 +3,6 @@
require 'settingslogic' require 'settingslogic'
require 'digest/md5' require 'digest/md5'
# We can not use `Rails.root` here, as this file might be loaded without the
# full Rails environment being loaded. We can not use `require_relative` either,
# as Rails uses `load` for `require_dependency` (used when loading the Rails
# environment). This could then lead to this file being loaded twice.
require_dependency File.expand_path('../lib/gitlab', __dir__)
class Settings < Settingslogic class Settings < Settingslogic
source ENV.fetch('GITLAB_CONFIG') { Pathname.new(File.expand_path('..', __dir__)).join('config/gitlab.yml') } source ENV.fetch('GITLAB_CONFIG') { Pathname.new(File.expand_path('..', __dir__)).join('config/gitlab.yml') }
namespace ENV.fetch('GITLAB_ENV') { Rails.env } namespace ENV.fetch('GITLAB_ENV') { Rails.env }
......
...@@ -15,9 +15,9 @@ module EE ...@@ -15,9 +15,9 @@ module EE
end end
def geo_connection_stats def geo_connection_stats
return [] unless Geo::TrackingBase.connected? return [] unless ::Geo::TrackingBase.connected?
[{ labels: labels_for_class(Geo::TrackingBase), stats: Geo::TrackingBase.connection_pool.stat }] [{ labels: labels_for_class(::Geo::TrackingBase), stats: ::Geo::TrackingBase.connection_pool.stat }]
end end
end end
end end
......
...@@ -4,7 +4,8 @@ require 'rails/generators' ...@@ -4,7 +4,8 @@ require 'rails/generators'
require 'rails/generators/active_record' require 'rails/generators/active_record'
require 'rails/generators/active_record/migration/migration_generator' require 'rails/generators/active_record/migration/migration_generator'
class GeoMigrationGenerator < ActiveRecord::Generators::MigrationGenerator module GeoMigration
class GeoMigrationGenerator < ActiveRecord::Generators::MigrationGenerator
source_root File.join(Rails.root, 'generator_templates/active_record/migration') source_root File.join(Rails.root, 'generator_templates/active_record/migration')
def create_migration_file def create_migration_file
...@@ -12,4 +13,5 @@ class GeoMigrationGenerator < ActiveRecord::Generators::MigrationGenerator ...@@ -12,4 +13,5 @@ class GeoMigrationGenerator < ActiveRecord::Generators::MigrationGenerator
validate_file_name! validate_file_name!
migration_template @migration_template, "ee/db/geo/migrate/#{file_name}.rb" migration_template @migration_template, "ee/db/geo/migrate/#{file_name}.rb"
end end
end
end end
...@@ -11,7 +11,7 @@ module GemExtensions ...@@ -11,7 +11,7 @@ module GemExtensions
@relation_delegate_cache2 = {} # rubocop:disable Gitlab/ModuleWithInstanceVariables @relation_delegate_cache2 = {} # rubocop:disable Gitlab/ModuleWithInstanceVariables
[ [
DisableJoins::Relation ::GemExtensions::ActiveRecord::DisableJoins::Relation
].each do |klass| ].each do |klass|
delegate = Class.new(klass) do delegate = Class.new(klass) do
include ::ActiveRecord::Delegation::ClassSpecificRelation include ::ActiveRecord::Delegation::ClassSpecificRelation
......
...@@ -17,7 +17,7 @@ module Gitlab ...@@ -17,7 +17,7 @@ module Gitlab
ALLOWED_OPERATIONS = %w(count distinct_count).freeze ALLOWED_OPERATIONS = %w(count distinct_count).freeze
source_root File.expand_path('templates', __dir__) source_root File.expand_path('usage_metric/templates', __dir__)
class_option :ee, type: :boolean, optional: true, default: false, desc: 'Indicates if instrumentation is for EE' class_option :ee, type: :boolean, optional: true, default: false, desc: 'Indicates if instrumentation is for EE'
class_option :type, type: :string, desc: "Metric type, must be one of: #{ALLOWED_SUPERCLASSES.keys.join(', ')}" class_option :type, type: :string, desc: "Metric type, must be one of: #{ALLOWED_SUPERCLASSES.keys.join(', ')}"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'rails/generators' require 'rails/generators'
module Rails module PostDeploymentMigration
class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase
def create_migration_file def create_migration_file
timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S') timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
......
...@@ -29,11 +29,11 @@ module Gitlab ...@@ -29,11 +29,11 @@ module Gitlab
@host = host @host = host
@port = port @port = port
@load_balancer = load_balancer @load_balancer = load_balancer
@pool = load_balancer.create_replica_connection_pool(LoadBalancing.pool_size, host, port) @pool = load_balancer.create_replica_connection_pool(::Gitlab::Database::LoadBalancing.pool_size, host, port)
@online = true @online = true
@last_checked_at = Time.zone.now @last_checked_at = Time.zone.now
interval = LoadBalancing.replica_check_interval interval = ::Gitlab::Database::LoadBalancing.replica_check_interval
@intervals = (interval..(interval * 2)).step(0.5).to_a @intervals = (interval..(interval * 2)).step(0.5).to_a
end end
...@@ -54,7 +54,7 @@ module Gitlab ...@@ -54,7 +54,7 @@ module Gitlab
end end
def offline! def offline!
LoadBalancing::Logger.warn( ::Gitlab::Database::LoadBalancing::Logger.warn(
event: :host_offline, event: :host_offline,
message: 'Marking host as offline', message: 'Marking host as offline',
db_host: @host, db_host: @host,
...@@ -72,14 +72,14 @@ module Gitlab ...@@ -72,14 +72,14 @@ module Gitlab
refresh_status refresh_status
if @online if @online
LoadBalancing::Logger.info( ::Gitlab::Database::LoadBalancing::Logger.info(
event: :host_online, event: :host_online,
message: 'Host is online after replica status check', message: 'Host is online after replica status check',
db_host: @host, db_host: @host,
db_port: @port db_port: @port
) )
else else
LoadBalancing::Logger.warn( ::Gitlab::Database::LoadBalancing::Logger.warn(
event: :host_offline, event: :host_offline,
message: 'Host is offline after replica status check', message: 'Host is offline after replica status check',
db_host: @host, db_host: @host,
...@@ -108,7 +108,7 @@ module Gitlab ...@@ -108,7 +108,7 @@ module Gitlab
def replication_lag_below_threshold? def replication_lag_below_threshold?
if (lag_time = replication_lag_time) if (lag_time = replication_lag_time)
lag_time <= LoadBalancing.max_replication_lag_time lag_time <= ::Gitlab::Database::LoadBalancing.max_replication_lag_time
else else
false false
end end
...@@ -125,7 +125,7 @@ module Gitlab ...@@ -125,7 +125,7 @@ module Gitlab
# only do this if we haven't replicated in a while so we only need # only do this if we haven't replicated in a while so we only need
# to connect to the primary when truly necessary. # to connect to the primary when truly necessary.
if (lag_size = replication_lag_size) if (lag_size = replication_lag_size)
lag_size <= LoadBalancing.max_replication_difference lag_size <= ::Gitlab::Database::LoadBalancing.max_replication_difference
else else
false false
end end
......
...@@ -18,9 +18,9 @@ module Gitlab ...@@ -18,9 +18,9 @@ module Gitlab
# namespace - The namespace to use for sticking. # namespace - The namespace to use for sticking.
# id - The identifier to use for sticking. # id - The identifier to use for sticking.
def self.stick_or_unstick(env, namespace, id) def self.stick_or_unstick(env, namespace, id)
return unless LoadBalancing.enable? return unless ::Gitlab::Database::LoadBalancing.enable?
Sticking.unstick_or_continue_sticking(namespace, id) ::Gitlab::Database::LoadBalancing::Sticking.unstick_or_continue_sticking(namespace, id)
env[STICK_OBJECT] ||= Set.new env[STICK_OBJECT] ||= Set.new
env[STICK_OBJECT] << [namespace, id] env[STICK_OBJECT] << [namespace, id]
...@@ -56,7 +56,7 @@ module Gitlab ...@@ -56,7 +56,7 @@ module Gitlab
namespaces_and_ids = sticking_namespaces_and_ids(env) namespaces_and_ids = sticking_namespaces_and_ids(env)
namespaces_and_ids.each do |namespace, id| namespaces_and_ids.each do |namespace, id|
Sticking.unstick_or_continue_sticking(namespace, id) ::Gitlab::Database::LoadBalancing::Sticking.unstick_or_continue_sticking(namespace, id)
end end
end end
...@@ -65,17 +65,17 @@ module Gitlab ...@@ -65,17 +65,17 @@ module Gitlab
namespaces_and_ids = sticking_namespaces_and_ids(env) namespaces_and_ids = sticking_namespaces_and_ids(env)
namespaces_and_ids.each do |namespace, id| namespaces_and_ids.each do |namespace, id|
Sticking.stick_if_necessary(namespace, id) ::Gitlab::Database::LoadBalancing::Sticking.stick_if_necessary(namespace, id)
end end
end end
def clear def clear
load_balancer.release_host load_balancer.release_host
Session.clear_session ::Gitlab::Database::LoadBalancing::Session.clear_session
end end
def load_balancer def load_balancer
LoadBalancing.proxy.load_balancer ::Gitlab::Database::LoadBalancing.proxy.load_balancer
end end
# Determines the sticking namespace and identifier based on the Rack # Determines the sticking namespace and identifier based on the Rack
......
...@@ -106,7 +106,7 @@ module Gitlab ...@@ -106,7 +106,7 @@ module Gitlab
end end
def design? def design?
klass == DesignManagement::Design klass == ::DesignManagement::Design
end end
def diff_commit_user? def diff_commit_user?
......
...@@ -66,28 +66,28 @@ module Gitlab ...@@ -66,28 +66,28 @@ module Gitlab
def call(env) def call(env)
method = env['REQUEST_METHOD'].downcase method = env['REQUEST_METHOD'].downcase
method = 'INVALID' unless HTTP_METHODS.key?(method) method = 'INVALID' unless HTTP_METHODS.key?(method)
started = Gitlab::Metrics::System.monotonic_time started = ::Gitlab::Metrics::System.monotonic_time
health_endpoint = health_endpoint?(env['PATH_INFO']) health_endpoint = health_endpoint?(env['PATH_INFO'])
status = 'undefined' status = 'undefined'
begin begin
status, headers, body = @app.call(env) status, headers, body = @app.call(env)
elapsed = Gitlab::Metrics::System.monotonic_time - started elapsed = ::Gitlab::Metrics::System.monotonic_time - started
if !health_endpoint && Gitlab::Metrics.record_duration_for_status?(status) if !health_endpoint && ::Gitlab::Metrics.record_duration_for_status?(status)
RequestsRackMiddleware.http_request_duration_seconds.observe({ method: method }, elapsed) self.class.http_request_duration_seconds.observe({ method: method }, elapsed)
end end
[status, headers, body] [status, headers, body]
rescue StandardError rescue StandardError
RequestsRackMiddleware.rack_uncaught_errors_count.increment self.class.rack_uncaught_errors_count.increment
raise raise
ensure ensure
if health_endpoint if health_endpoint
RequestsRackMiddleware.http_health_requests_total.increment(status: status.to_s, method: method) self.class.http_health_requests_total.increment(status: status.to_s, method: method)
else else
RequestsRackMiddleware.http_requests_total.increment( self.class.http_requests_total.increment(
status: status.to_s, status: status.to_s,
method: method, method: method,
feature_category: feature_category.presence || FEATURE_CATEGORY_DEFAULT feature_category: feature_category.presence || FEATURE_CATEGORY_DEFAULT
......
...@@ -23,7 +23,7 @@ module Gitlab ...@@ -23,7 +23,7 @@ module Gitlab
def safe_sample def safe_sample
sample sample
rescue StandardError => e rescue StandardError => e
Gitlab::AppLogger.warn("#{self.class}: #{e}, stopping") ::Gitlab::AppLogger.warn("#{self.class}: #{e}, stopping")
stop stop
end end
......
...@@ -40,7 +40,7 @@ module Gitlab ...@@ -40,7 +40,7 @@ module Gitlab
end end
def current_transaction def current_transaction
Transaction.current ::Gitlab::Metrics::Transaction.current
end end
end end
end end
......
...@@ -65,7 +65,7 @@ module Gitlab ...@@ -65,7 +65,7 @@ module Gitlab
private private
def current_transaction def current_transaction
Transaction.current ::Gitlab::Metrics::Transaction.current
end end
def metric_cache_operation_duration_seconds def metric_cache_operation_duration_seconds
......
...@@ -6,10 +6,10 @@ module Gitlab ...@@ -6,10 +6,10 @@ module Gitlab
attach_to :active_record attach_to :active_record
def sql(event) def sql(event)
return if !Transaction.current || event.payload.fetch(:cached, event.payload[:name] == 'CACHE') return if !::Gitlab::QueryLimiting::Transaction.current || event.payload.fetch(:cached, event.payload[:name] == 'CACHE')
Transaction.current.increment ::Gitlab::QueryLimiting::Transaction.current.increment
Transaction.current.executed_sql(event.payload[:sql]) ::Gitlab::QueryLimiting::Transaction.current.executed_sql(event.payload[:sql])
end end
end end
end end
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
end end
def call(env) def call(env)
transaction, retval = Transaction.run do transaction, retval = ::Gitlab::QueryLimiting::Transaction.run do
@app.call(env) @app.call(env)
end end
......
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Aggregates
UNION_OF_AGGREGATED_METRICS = 'OR'
INTERSECTION_OF_AGGREGATED_METRICS = 'AND'
ALLOWED_METRICS_AGGREGATIONS = [UNION_OF_AGGREGATED_METRICS, INTERSECTION_OF_AGGREGATED_METRICS].freeze
AGGREGATED_METRICS_PATH = Rails.root.join('config/metrics/aggregates/*.yml')
AggregatedMetricError = Class.new(StandardError)
UnknownAggregationOperator = Class.new(AggregatedMetricError)
UnknownAggregationSource = Class.new(AggregatedMetricError)
DisallowedAggregationTimeFrame = Class.new(AggregatedMetricError)
DATABASE_SOURCE = 'database'
REDIS_SOURCE = 'redis'
SOURCES = {
DATABASE_SOURCE => Sources::PostgresHll,
REDIS_SOURCE => Sources::RedisHll
}.freeze
end
end
end
end
...@@ -4,23 +4,6 @@ module Gitlab ...@@ -4,23 +4,6 @@ module Gitlab
module Usage module Usage
module Metrics module Metrics
module Aggregates module Aggregates
UNION_OF_AGGREGATED_METRICS = 'OR'
INTERSECTION_OF_AGGREGATED_METRICS = 'AND'
ALLOWED_METRICS_AGGREGATIONS = [UNION_OF_AGGREGATED_METRICS, INTERSECTION_OF_AGGREGATED_METRICS].freeze
AGGREGATED_METRICS_PATH = Rails.root.join('config/metrics/aggregates/*.yml')
AggregatedMetricError = Class.new(StandardError)
UnknownAggregationOperator = Class.new(AggregatedMetricError)
UnknownAggregationSource = Class.new(AggregatedMetricError)
DisallowedAggregationTimeFrame = Class.new(AggregatedMetricError)
DATABASE_SOURCE = 'database'
REDIS_SOURCE = 'redis'
SOURCES = {
DATABASE_SOURCE => Sources::PostgresHll,
REDIS_SOURCE => Sources::RedisHll
}.freeze
class Aggregate class Aggregate
include Gitlab::Usage::TimeFrame include Gitlab::Usage::TimeFrame
......
# frozen_string_literal: true
module Gitlab
module Usage
module Metrics
module Aggregates
module Sources
UnionNotAvailable = Class.new(AggregatedMetricError)
end
end
end
end
end
...@@ -5,8 +5,6 @@ module Gitlab ...@@ -5,8 +5,6 @@ module Gitlab
module Metrics module Metrics
module Aggregates module Aggregates
module Sources module Sources
UnionNotAvailable = Class.new(AggregatedMetricError)
class RedisHll class RedisHll
extend Calculations::Intersection extend Calculations::Intersection
def self.calculate_metrics_union(metric_names:, start_date:, end_date:, recorded_at: nil) def self.calculate_metrics_union(metric_names:, start_date:, end_date:, recorded_at: nil)
......
...@@ -18,9 +18,11 @@ require_relative '../config/settings' ...@@ -18,9 +18,11 @@ require_relative '../config/settings'
require_relative 'support/rspec' require_relative 'support/rspec'
require 'active_support/all' require 'active_support/all'
ActiveSupport::Dependencies.autoload_paths << 'lib' unless ActiveSupport::Dependencies.autoload_paths.frozen?
ActiveSupport::Dependencies.autoload_paths << 'ee/lib' ActiveSupport::Dependencies.autoload_paths << 'lib'
ActiveSupport::Dependencies.autoload_paths << 'jh/lib' ActiveSupport::Dependencies.autoload_paths << 'ee/lib'
ActiveSupport::Dependencies.autoload_paths << 'jh/lib'
end
ActiveSupport::XmlMini.backend = 'Nokogiri' ActiveSupport::XmlMini.backend = 'Nokogiri'
......
...@@ -183,18 +183,17 @@ RSpec.describe Gitlab::Database::LoadBalancing::RackMiddleware, :redis do ...@@ -183,18 +183,17 @@ RSpec.describe Gitlab::Database::LoadBalancing::RackMiddleware, :redis do
describe '#clear' do describe '#clear' do
it 'clears the currently used host and session' do it 'clears the currently used host and session' do
lb = double(:lb) lb = double(:lb)
session = double(:session) session = spy(:session)
allow(middleware).to receive(:load_balancer).and_return(lb) allow(middleware).to receive(:load_balancer).and_return(lb)
expect(lb).to receive(:release_host) expect(lb).to receive(:release_host)
stub_const('Gitlab::Database::LoadBalancing::RackMiddleware::Session', stub_const('Gitlab::Database::LoadBalancing::Session', session)
session)
expect(session).to receive(:clear_session)
middleware.clear middleware.clear
expect(session).to have_received(:clear_session)
end end
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'fast_spec_helper' require 'fast_spec_helper'
ActiveSupport::Dependencies.autoload_paths << 'app/services' require_relative '../../app/services/service_response'
RSpec.describe ServiceResponse do RSpec.describe ServiceResponse do
describe '.success' do describe '.success' do
......
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