Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-17 06:07:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-17 06:07:45 +0300
commit9763c081708e4c2e08de1f4e9ca9abdef5cffe3c (patch)
treeb27794ba1a039cdc42cdf5d90bcb7b7503437324 /lib
parent7480d774dfca97ea905321d52c70fd19496f0084 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab.rb4
-rw-r--r--lib/gitlab/auth/auth_finders.rb14
-rw-r--r--lib/gitlab/auth/request_authenticator.rb3
-rw-r--r--lib/gitlab/cluster/lifecycle_events.rb6
-rw-r--r--lib/gitlab/gitaly_client.rb8
-rw-r--r--lib/gitlab/gpg.rb2
-rw-r--r--lib/gitlab/health_checks/puma_check.rb2
-rw-r--r--lib/gitlab/health_checks/unicorn_check.rb2
-rw-r--r--lib/gitlab/highlight.rb2
-rw-r--r--lib/gitlab/metrics/influx_db.rb2
-rw-r--r--lib/gitlab/metrics/samplers/influx_sampler.rb6
-rw-r--r--lib/gitlab/metrics/samplers/unicorn_sampler.rb2
-rw-r--r--lib/gitlab/redis/wrapper.rb4
-rw-r--r--lib/gitlab/runtime.rb62
-rw-r--r--lib/prometheus/pid_provider.rb6
15 files changed, 43 insertions, 82 deletions
diff --git a/lib/gitlab.rb b/lib/gitlab.rb
index f2bff51df38..0e6db54eb46 100644
--- a/lib/gitlab.rb
+++ b/lib/gitlab.rb
@@ -100,8 +100,8 @@ module Gitlab
end
def self.process_name
- return 'sidekiq' if Gitlab::Runtime.sidekiq?
- return 'console' if Gitlab::Runtime.console?
+ return 'sidekiq' if Sidekiq.server?
+ return 'console' if defined?(Rails::Console)
return 'test' if Rails.env.test?
'web'
diff --git a/lib/gitlab/auth/auth_finders.rb b/lib/gitlab/auth/auth_finders.rb
index 6210aca739a..33cbb070c2f 100644
--- a/lib/gitlab/auth/auth_finders.rb
+++ b/lib/gitlab/auth/auth_finders.rb
@@ -21,6 +21,7 @@ module Gitlab
prepend_if_ee('::EE::Gitlab::Auth::AuthFinders') # rubocop: disable Cop/InjectEnterpriseEditionModule
include Gitlab::Utils::StrongMemoize
+ include ActionController::HttpAuthentication::Basic
PRIVATE_TOKEN_HEADER = 'HTTP_PRIVATE_TOKEN'
PRIVATE_TOKEN_PARAM = :private_token
@@ -67,6 +68,19 @@ module Gitlab
job.user
end
+ def find_user_from_basic_auth_job
+ return unless has_basic_credentials?(current_request)
+
+ login, password = user_name_and_password(current_request)
+ return unless login.present? && password.present?
+ return unless ::Ci::Build::CI_REGISTRY_USER == login
+
+ job = ::Ci::Build.find_by_token(password)
+ raise UnauthorizedError unless job
+
+ job.user
+ end
+
# We only allow Private Access Tokens with `api` scope to be used by web
# requests on RSS feeds or ICS files for backwards compatibility.
# It is also used by GraphQL/API requests.
diff --git a/lib/gitlab/auth/request_authenticator.rb b/lib/gitlab/auth/request_authenticator.rb
index 9b1b7b8e879..34ccff588f4 100644
--- a/lib/gitlab/auth/request_authenticator.rb
+++ b/lib/gitlab/auth/request_authenticator.rb
@@ -32,7 +32,8 @@ module Gitlab
def find_sessionless_user(request_format)
find_user_from_web_access_token(request_format) ||
find_user_from_feed_token(request_format) ||
- find_user_from_static_object_token(request_format)
+ find_user_from_static_object_token(request_format) ||
+ find_user_from_basic_auth_job
rescue Gitlab::Auth::AuthenticationError
nil
end
diff --git a/lib/gitlab/cluster/lifecycle_events.rb b/lib/gitlab/cluster/lifecycle_events.rb
index 4ae75e0db0a..2b3dc94fc5e 100644
--- a/lib/gitlab/cluster/lifecycle_events.rb
+++ b/lib/gitlab/cluster/lifecycle_events.rb
@@ -149,10 +149,10 @@ module Gitlab
def in_clustered_environment?
# Sidekiq doesn't fork
- return false if Gitlab::Runtime.sidekiq?
+ return false if Sidekiq.server?
# Unicorn always forks
- return true if Gitlab::Runtime.unicorn?
+ return true if defined?(::Unicorn)
# Puma sometimes forks
return true if in_clustered_puma?
@@ -162,7 +162,7 @@ module Gitlab
end
def in_clustered_puma?
- return false unless Gitlab::Runtime.puma?
+ return false unless defined?(::Puma)
@puma_options && @puma_options[:workers] && @puma_options[:workers] > 0
end
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb
index 1ce30176644..9e033c705bd 100644
--- a/lib/gitlab/gitaly_client.rb
+++ b/lib/gitlab/gitaly_client.rb
@@ -29,7 +29,7 @@ module Gitlab
PEM_REGEX = /\-+BEGIN CERTIFICATE\-+.+?\-+END CERTIFICATE\-+/m.freeze
SERVER_VERSION_FILE = 'GITALY_SERVER_VERSION'
MAXIMUM_GITALY_CALLS = 30
- CLIENT_NAME = (Gitlab::Runtime.sidekiq? ? 'gitlab-sidekiq' : 'gitlab-web').freeze
+ CLIENT_NAME = (Sidekiq.server? ? 'gitlab-sidekiq' : 'gitlab-web').freeze
GITALY_METADATA_FILENAME = '.gitaly-metadata'
MUTEX = Mutex.new
@@ -382,13 +382,17 @@ module Gitlab
end
def self.long_timeout
- if Gitlab::Runtime.app_server?
+ if web_app_server?
default_timeout
else
6.hours
end
end
+ def self.web_app_server?
+ defined?(::Unicorn) || defined?(::Puma)
+ end
+
def self.storage_metadata_file_path(storage)
Gitlab::GitalyClient::StorageSettings.allow_disk_access do
File.join(
diff --git a/lib/gitlab/gpg.rb b/lib/gitlab/gpg.rb
index 7e6f6a519a6..e3c474bc0fe 100644
--- a/lib/gitlab/gpg.rb
+++ b/lib/gitlab/gpg.rb
@@ -135,7 +135,7 @@ module Gitlab
end
def cleanup_time
- Gitlab::Runtime.sidekiq? ? BG_CLEANUP_RUNTIME_S : FG_CLEANUP_RUNTIME_S
+ Sidekiq.server? ? BG_CLEANUP_RUNTIME_S : FG_CLEANUP_RUNTIME_S
end
def tmp_keychains_created
diff --git a/lib/gitlab/health_checks/puma_check.rb b/lib/gitlab/health_checks/puma_check.rb
index 9f09070a57d..7aafe29fbae 100644
--- a/lib/gitlab/health_checks/puma_check.rb
+++ b/lib/gitlab/health_checks/puma_check.rb
@@ -18,7 +18,7 @@ module Gitlab
end
def check
- return unless Gitlab::Runtime.puma?
+ return unless defined?(::Puma)
stats = Puma.stats
stats = JSON.parse(stats)
diff --git a/lib/gitlab/health_checks/unicorn_check.rb b/lib/gitlab/health_checks/unicorn_check.rb
index cdc6d2a7519..a30ae015257 100644
--- a/lib/gitlab/health_checks/unicorn_check.rb
+++ b/lib/gitlab/health_checks/unicorn_check.rb
@@ -30,7 +30,7 @@ module Gitlab
# to change so we can cache the list of servers.
def http_servers
strong_memoize(:http_servers) do
- next unless Gitlab::Runtime.unicorn?
+ next unless defined?(::Unicorn::HttpServer)
ObjectSpace.each_object(::Unicorn::HttpServer).to_a
end
diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb
index 22b9a038768..2c243a0d0ae 100644
--- a/lib/gitlab/highlight.rb
+++ b/lib/gitlab/highlight.rb
@@ -68,7 +68,7 @@ module Gitlab
end
def timeout_time
- Gitlab::Runtime.sidekiq? ? TIMEOUT_BACKGROUND : TIMEOUT_FOREGROUND
+ Sidekiq.server? ? TIMEOUT_BACKGROUND : TIMEOUT_FOREGROUND
end
def link_dependencies(text, highlighted_text)
diff --git a/lib/gitlab/metrics/influx_db.rb b/lib/gitlab/metrics/influx_db.rb
index 1f252572461..269d90fa971 100644
--- a/lib/gitlab/metrics/influx_db.rb
+++ b/lib/gitlab/metrics/influx_db.rb
@@ -150,7 +150,7 @@ module Gitlab
# Returns the prefix to use for the name of a series.
def series_prefix
- @series_prefix ||= Gitlab::Runtime.sidekiq? ? 'sidekiq_' : 'rails_'
+ @series_prefix ||= Sidekiq.server? ? 'sidekiq_' : 'rails_'
end
# Allow access from other metrics related middlewares
diff --git a/lib/gitlab/metrics/samplers/influx_sampler.rb b/lib/gitlab/metrics/samplers/influx_sampler.rb
index 4e16e335bee..1eae0a7bf45 100644
--- a/lib/gitlab/metrics/samplers/influx_sampler.rb
+++ b/lib/gitlab/metrics/samplers/influx_sampler.rb
@@ -39,10 +39,14 @@ module Gitlab
end
def add_metric(series, values, tags = {})
- prefix = Gitlab::Runtime.sidekiq? ? 'sidekiq_' : 'rails_'
+ prefix = sidekiq? ? 'sidekiq_' : 'rails_'
@metrics << Metric.new("#{prefix}#{series}", values, tags)
end
+
+ def sidekiq?
+ Sidekiq.server?
+ end
end
end
end
diff --git a/lib/gitlab/metrics/samplers/unicorn_sampler.rb b/lib/gitlab/metrics/samplers/unicorn_sampler.rb
index 8c4d150adad..355f938704e 100644
--- a/lib/gitlab/metrics/samplers/unicorn_sampler.rb
+++ b/lib/gitlab/metrics/samplers/unicorn_sampler.rb
@@ -61,7 +61,7 @@ module Gitlab
# it takes around 80ms. The instances of HttpServers are not a subject
# to change so we can cache the list of servers.
def http_servers
- return [] unless Gitlab::Runtime.unicorn?
+ return [] unless defined?(::Unicorn::HttpServer)
@http_servers ||= ObjectSpace.each_object(::Unicorn::HttpServer).to_a
end
diff --git a/lib/gitlab/redis/wrapper.rb b/lib/gitlab/redis/wrapper.rb
index beceed3fa75..412d00c6939 100644
--- a/lib/gitlab/redis/wrapper.rb
+++ b/lib/gitlab/redis/wrapper.rb
@@ -22,10 +22,10 @@ module Gitlab
def pool_size
# heuristic constant 5 should be a config setting somewhere -- related to CPU count?
size = 5
- if Gitlab::Runtime.sidekiq?
+ if Sidekiq.server?
# the pool will be used in a multi-threaded context
size += Sidekiq.options[:concurrency]
- elsif Gitlab::Runtime.puma?
+ elsif defined?(::Puma)
size += Puma.cli_config.options[:max_threads]
end
diff --git a/lib/gitlab/runtime.rb b/lib/gitlab/runtime.rb
deleted file mode 100644
index 07a3afb8834..00000000000
--- a/lib/gitlab/runtime.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-# frozen_string_literal: true
-
-module Gitlab
- # Provides routines to identify the current runtime as which the application
- # executes, such as whether it is an application server and which one.
- module Runtime
- class << self
- def name
- matches = []
- matches << :puma if puma?
- matches << :unicorn if unicorn?
- matches << :console if console?
- matches << :sidekiq if sidekiq?
-
- raise "Ambiguous process match: #{matches}" if matches.size > 1
-
- matches.first || :unknown
- end
-
- def puma?
- !!(defined?(::Puma) && bin == 'puma')
- end
-
- # For unicorn, we need to check for actual server instances to avoid false positives.
- def unicorn?
- !!(defined?(::Unicorn) && defined?(::Unicorn::HttpServer))
- end
-
- def sidekiq?
- !!(defined?(::Sidekiq) && Sidekiq.server? && bin == 'sidekiq')
- end
-
- def console?
- !!defined?(::Rails::Console)
- end
-
- def app_server?
- puma? || unicorn?
- end
-
- def multi_threaded?
- puma? || sidekiq?
- end
-
- private
-
- # Some example values from my system:
- # puma: /data/cache/bundle-2.5/bin/puma
- # unicorn: unicorn_rails master -E development -c /tmp/unicorn.rb -l 0.0.0.0:8080
- # sidekiq: /data/cache/bundle-2.5/bin/sidekiq
- # thin: bin/rails
- # console: bin/rails
- def script_name
- $0
- end
-
- def bin
- File.basename(script_name)
- end
- end
- end
-end
diff --git a/lib/prometheus/pid_provider.rb b/lib/prometheus/pid_provider.rb
index 32beeb0d31e..228639357ac 100644
--- a/lib/prometheus/pid_provider.rb
+++ b/lib/prometheus/pid_provider.rb
@@ -5,11 +5,11 @@ module Prometheus
extend self
def worker_id
- if Gitlab::Runtime.sidekiq?
+ if Sidekiq.server?
sidekiq_worker_id
- elsif Gitlab::Runtime.unicorn?
+ elsif defined?(Unicorn::Worker)
unicorn_worker_id
- elsif Gitlab::Runtime.puma?
+ elsif defined?(::Puma)
puma_worker_id
else
unknown_process_id