summaryrefslogtreecommitdiff
path: root/metrics_server
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /metrics_server
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
downloadgitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'metrics_server')
-rw-r--r--metrics_server/dependencies.rb1
-rw-r--r--metrics_server/metrics_server.rb58
2 files changed, 53 insertions, 6 deletions
diff --git a/metrics_server/dependencies.rb b/metrics_server/dependencies.rb
index bfa6aae8ef8..3f188658ba2 100644
--- a/metrics_server/dependencies.rb
+++ b/metrics_server/dependencies.rb
@@ -26,7 +26,6 @@ require_relative '../lib/gitlab/metrics/exporter/base_exporter'
require_relative '../lib/gitlab/metrics/exporter/web_exporter'
require_relative '../lib/gitlab/metrics/exporter/sidekiq_exporter'
require_relative '../lib/gitlab/metrics/exporter/metrics_middleware'
-require_relative '../lib/gitlab/metrics/exporter/health_checks_middleware'
require_relative '../lib/gitlab/metrics/exporter/gc_request_middleware'
require_relative '../lib/gitlab/health_checks/probes/collection'
require_relative '../lib/gitlab/health_checks/probes/status'
diff --git a/metrics_server/metrics_server.rb b/metrics_server/metrics_server.rb
index 695f3a65930..a5c448b5105 100644
--- a/metrics_server/metrics_server.rb
+++ b/metrics_server/metrics_server.rb
@@ -7,6 +7,10 @@ class MetricsServer # rubocop:disable Gitlab/NamespacedClass
PumaProcessSupervisor = Class.new(Gitlab::ProcessSupervisor)
class << self
+ def version
+ Rails.root.join('GITLAB_METRICS_EXPORTER_VERSION').read.chomp
+ end
+
def start_for_puma
metrics_dir = ::Prometheus::Client.configuration.multiprocess_files_dir
@@ -18,22 +22,54 @@ class MetricsServer # rubocop:disable Gitlab/NamespacedClass
supervisor = PumaProcessSupervisor.instance
supervisor.supervise(start_server.call) do
- next unless supervisor.alive
-
Gitlab::AppLogger.info('Puma metrics server terminated, restarting...')
start_server.call
end
end
- def spawn(target, metrics_dir:, gitlab_config: nil, wipe_metrics_dir: false)
+ def start_for_sidekiq(**options)
+ if new_metrics_server?
+ self.spawn('sidekiq', **options)
+ else
+ self.fork('sidekiq', **options)
+ end
+ end
+
+ def spawn(target, metrics_dir:, **options)
+ return spawn_ruby_server(target, metrics_dir: metrics_dir, **options) unless new_metrics_server?
+
+ name = settings_key(target)
+ settings = ::Settings.monitoring[name]
+ path = options[:path]&.then { |p| Pathname.new(p) } || Pathname.new('')
+ cmd = path.join('gitlab-metrics-exporter').to_path
+ env = {
+ 'GME_MMAP_METRICS_DIR' => metrics_dir.to_s,
+ 'GME_PROBES' => 'self,mmap',
+ 'GME_SERVER_HOST' => settings['address'],
+ 'GME_SERVER_PORT' => settings['port'].to_s
+ }
+
+ if settings['log_enabled']
+ env['GME_LOG_FILE'] = File.join(Rails.root, 'log', "#{name}.log")
+ env['GME_LOG_LEVEL'] = 'info'
+ else
+ env['GME_LOG_LEVEL'] = 'quiet'
+ end
+
+ Process.spawn(env, cmd, err: $stderr, out: $stdout, pgroup: true).tap do |pid|
+ Process.detach(pid)
+ end
+ end
+
+ def spawn_ruby_server(target, metrics_dir:, wipe_metrics_dir: false, **options)
ensure_valid_target!(target)
cmd = "#{Rails.root}/bin/metrics-server"
env = {
'METRICS_SERVER_TARGET' => target,
- 'WIPE_METRICS_DIR' => wipe_metrics_dir ? '1' : '0'
+ 'WIPE_METRICS_DIR' => wipe_metrics_dir ? '1' : '0',
+ 'GITLAB_CONFIG' => ENV['GITLAB_CONFIG']
}
- env['GITLAB_CONFIG'] = gitlab_config if gitlab_config
Process.spawn(env, cmd, err: $stderr, out: $stdout, pgroup: true).tap do |pid|
Process.detach(pid)
@@ -66,9 +102,21 @@ class MetricsServer # rubocop:disable Gitlab/NamespacedClass
private
+ def new_metrics_server?
+ Gitlab::Utils.to_boolean(ENV['GITLAB_GOLANG_METRICS_SERVER'])
+ end
+
def ensure_valid_target!(target)
raise "Target must be one of [puma,sidekiq]" unless %w(puma sidekiq).include?(target)
end
+
+ def settings_key(target)
+ case target
+ when 'puma' then 'web_exporter'
+ when 'sidekiq' then 'sidekiq_exporter'
+ else ensure_valid_target!(target)
+ end
+ end
end
def initialize(target, metrics_dir, wipe_metrics_dir)