2019-09-30 21:07:59 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
module RuggedImpl
|
|
|
|
module UseRugged
|
|
|
|
def use_rugged?(repo, feature_key)
|
|
|
|
feature = Feature.get(feature_key)
|
|
|
|
return feature.enabled? if Feature.persisted?(feature)
|
|
|
|
|
2020-03-09 13:42:32 +05:30
|
|
|
# Disable Rugged auto-detect(can_use_disk?) when Puma threads>1
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/issues/119326
|
|
|
|
return false if running_puma_with_multiple_threads?
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
Gitlab::GitalyClient.can_use_disk?(repo.storage)
|
|
|
|
end
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
def execute_rugged_call(method_name, *args)
|
2019-09-30 21:07:59 +05:30
|
|
|
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
|
2019-10-12 21:52:04 +05:30
|
|
|
start = Gitlab::Metrics::System.monotonic_time
|
|
|
|
|
|
|
|
result = send(method_name, *args) # rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
|
|
|
|
duration = Gitlab::Metrics::System.monotonic_time - start
|
|
|
|
|
|
|
|
if Gitlab::RuggedInstrumentation.active?
|
|
|
|
Gitlab::RuggedInstrumentation.increment_query_count
|
|
|
|
Gitlab::RuggedInstrumentation.query_time += duration
|
|
|
|
|
|
|
|
Gitlab::RuggedInstrumentation.add_call_details(
|
|
|
|
feature: method_name,
|
|
|
|
args: args,
|
|
|
|
duration: duration,
|
2020-03-09 13:42:32 +05:30
|
|
|
backtrace: Gitlab::BacktraceCleaner.clean_backtrace(caller))
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
result
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
def running_puma_with_multiple_threads?
|
|
|
|
return false unless Gitlab::Runtime.puma?
|
|
|
|
|
|
|
|
::Puma.respond_to?(:cli_config) && ::Puma.cli_config.options[:max_threads] > 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def rugged_feature_keys
|
|
|
|
Gitlab::Git::RuggedImpl::Repository::FEATURE_FLAGS
|
|
|
|
end
|
|
|
|
|
|
|
|
def rugged_enabled_through_feature_flag?
|
|
|
|
rugged_feature_keys.any? do |feature_key|
|
|
|
|
Feature.enabled?(feature_key)
|
|
|
|
end
|
|
|
|
end
|
2019-09-30 21:07:59 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|