diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-26 00:09:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-26 00:09:46 +0300 |
commit | 44fb0702f3d2161d286df9b409f4309ed41207df (patch) | |
tree | 413f71c07a4ef9d13f17fee357832693e6cb3c48 /metrics_server | |
parent | c7531da771f30a54e2220f8f62efeba4b0b1a674 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'metrics_server')
-rw-r--r-- | metrics_server/metrics_server.rb | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/metrics_server/metrics_server.rb b/metrics_server/metrics_server.rb index 695f3a65930..7bc48ed1ff8 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 @@ -25,15 +29,41 @@ class MetricsServer # rubocop:disable Gitlab/NamespacedClass 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? + + settings = settings_for(target) + 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 + } + + 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 +96,23 @@ 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_for(target) + settings_key = + case target + when 'puma' then 'web_exporter' + when 'sidekiq' then 'sidekiq_exporter' + else ensure_valid_target!(target) + end + ::Settings.monitoring[settings_key] + end end def initialize(target, metrics_dir, wipe_metrics_dir) |