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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-12-20 16:37:47 +0300
commitaee0a117a889461ce8ced6fcf73207fe017f1d99 (patch)
tree891d9ef189227a8445d83f35c1b0fc99573f4380 /metrics_server
parent8d46af3258650d305f53b819eabf7ab18d22f59e (diff)
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'metrics_server')
-rw-r--r--metrics_server/dependencies.rb27
-rw-r--r--metrics_server/metrics_server.rb59
-rw-r--r--metrics_server/override_rails_constants.rb20
-rw-r--r--metrics_server/settings_overrides.rb14
4 files changed, 120 insertions, 0 deletions
diff --git a/metrics_server/dependencies.rb b/metrics_server/dependencies.rb
new file mode 100644
index 00000000000..a459efef1ad
--- /dev/null
+++ b/metrics_server/dependencies.rb
@@ -0,0 +1,27 @@
+# rubocop:disable Naming/FileName
+# frozen_string_literal: true
+
+require 'shellwords'
+require 'fileutils'
+
+require 'active_support/concern'
+require 'active_support/inflector'
+
+require 'prometheus/client'
+require 'rack'
+
+require_relative 'settings_overrides'
+
+require_relative '../lib/gitlab/daemon'
+require_relative '../lib/gitlab/utils'
+require_relative '../lib/gitlab/utils/strong_memoize'
+require_relative '../lib/prometheus/cleanup_multiproc_dir_service'
+require_relative '../lib/gitlab/metrics/prometheus'
+require_relative '../lib/gitlab/metrics'
+require_relative '../lib/gitlab/metrics/exporter/base_exporter'
+require_relative '../lib/gitlab/metrics/exporter/sidekiq_exporter'
+require_relative '../lib/gitlab/health_checks/probes/collection'
+require_relative '../lib/gitlab/health_checks/probes/status'
+require_relative '../lib/gitlab/process_management'
+
+# rubocop:enable Naming/FileName
diff --git a/metrics_server/metrics_server.rb b/metrics_server/metrics_server.rb
new file mode 100644
index 00000000000..56fc20dcc9d
--- /dev/null
+++ b/metrics_server/metrics_server.rb
@@ -0,0 +1,59 @@
+# frozen_string_literal: true
+
+require_relative '../config/boot'
+
+require_relative 'dependencies'
+
+class MetricsServer # rubocop:disable Gitlab/NamespacedClass
+ class << self
+ def spawn(target, metrics_dir:, wipe_metrics_dir: false, trapped_signals: [])
+ raise "The only valid target is 'sidekiq' currently" unless target == 'sidekiq'
+
+ pid = Process.fork
+
+ if pid.nil? # nil means we're inside the fork
+ # Remove any custom signal handlers the parent process had registered, since we do
+ # not want to inherit them, and Ruby forks with a `clone` that has the `CLONE_SIGHAND`
+ # flag set.
+ Gitlab::ProcessManagement.modify_signals(trapped_signals, 'DEFAULT')
+
+ server = MetricsServer.new(target, metrics_dir, wipe_metrics_dir)
+ # This rewrites /proc/cmdline, since otherwise tools like `top` will show the
+ # parent process `cmdline` which is really confusing.
+ $0 = server.name
+
+ server.start
+ else
+ Process.detach(pid)
+ end
+
+ pid
+ end
+ end
+
+ def initialize(target, metrics_dir, wipe_metrics_dir)
+ @target = target
+ @metrics_dir = metrics_dir
+ @wipe_metrics_dir = wipe_metrics_dir
+ end
+
+ def start
+ ::Prometheus::Client.configure do |config|
+ config.multiprocess_files_dir = @metrics_dir
+ end
+
+ FileUtils.mkdir_p(@metrics_dir, mode: 0700)
+ ::Prometheus::CleanupMultiprocDirService.new.execute if @wipe_metrics_dir
+
+ settings = Settings.new(Settings.monitoring[name])
+
+ exporter_class = "Gitlab::Metrics::Exporter::#{@target.camelize}Exporter".constantize
+ server = exporter_class.instance(settings, synchronous: true)
+
+ server.start
+ end
+
+ def name
+ "#{@target}_exporter"
+ end
+end
diff --git a/metrics_server/override_rails_constants.rb b/metrics_server/override_rails_constants.rb
new file mode 100644
index 00000000000..76e49edfbb0
--- /dev/null
+++ b/metrics_server/override_rails_constants.rb
@@ -0,0 +1,20 @@
+# rubocop:disable Naming/FileName
+# frozen_string_literal: true
+
+require 'active_support/environment_inquirer'
+
+module Rails
+ extend self
+
+ def env
+ @env ||= ActiveSupport::EnvironmentInquirer.new(
+ ENV["RAILS_ENV"].presence || ENV["RACK_ENV"].presence || "development"
+ )
+ end
+
+ def root
+ Pathname.new(File.expand_path('..', __dir__))
+ end
+end
+
+# rubocop:enable Naming/FileName
diff --git a/metrics_server/settings_overrides.rb b/metrics_server/settings_overrides.rb
new file mode 100644
index 00000000000..8572b4f86b0
--- /dev/null
+++ b/metrics_server/settings_overrides.rb
@@ -0,0 +1,14 @@
+# rubocop:disable Naming/FileName
+# frozen_string_literal: true
+
+# Sidekiq-cluster code is loaded both inside a Rails/Rspec
+# context as well as outside of it via CLI invocation. When it
+# is loaded outside of a Rails/Rspec context we do not have access
+# to all necessary constants. For example, we need Rails.root to
+# determine the location of bin/metrics-server.
+# Here we make the necessary constants available conditionally.
+require_relative 'override_rails_constants' unless Object.const_defined?('Rails')
+
+require_relative '../config/settings'
+
+# rubocop:enable Naming/FileName