summaryrefslogtreecommitdiff
path: root/metrics_server
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-01-20 09:16:11 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-01-20 09:16:11 +0000
commitedaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch)
tree11f143effbfeba52329fb7afbd05e6e2a3790241 /metrics_server
parentd8a5691316400a0f7ec4f83832698f1988eb27c1 (diff)
downloadgitlab-ce-edaa33dee2ff2f7ea3fac488d41558eb5f86d68c.tar.gz
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'metrics_server')
-rw-r--r--metrics_server/dependencies.rb7
-rw-r--r--metrics_server/metrics_server.rb10
-rw-r--r--metrics_server/override_gitlab_current_settings.rb21
-rw-r--r--metrics_server/settings_overrides.rb5
4 files changed, 41 insertions, 2 deletions
diff --git a/metrics_server/dependencies.rb b/metrics_server/dependencies.rb
index a459efef1ad..5615cef42ce 100644
--- a/metrics_server/dependencies.rb
+++ b/metrics_server/dependencies.rb
@@ -6,6 +6,7 @@ require 'fileutils'
require 'active_support/concern'
require 'active_support/inflector'
+require 'active_support/core_ext/numeric/bytes'
require 'prometheus/client'
require 'rack'
@@ -18,8 +19,14 @@ 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/system'
+require_relative '../lib/gitlab/metrics/samplers/base_sampler'
+require_relative '../lib/gitlab/metrics/samplers/ruby_sampler'
require_relative '../lib/gitlab/metrics/exporter/base_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'
require_relative '../lib/gitlab/process_management'
diff --git a/metrics_server/metrics_server.rb b/metrics_server/metrics_server.rb
index 56fc20dcc9d..122a4e4fc1e 100644
--- a/metrics_server/metrics_server.rb
+++ b/metrics_server/metrics_server.rb
@@ -40,15 +40,21 @@ class MetricsServer # rubocop:disable Gitlab/NamespacedClass
def start
::Prometheus::Client.configure do |config|
config.multiprocess_files_dir = @metrics_dir
+ config.pid_provider = proc { "#{@target}_exporter" }
end
FileUtils.mkdir_p(@metrics_dir, mode: 0700)
::Prometheus::CleanupMultiprocDirService.new.execute if @wipe_metrics_dir
- settings = Settings.new(Settings.monitoring[name])
+ # We need to `warmup: true` since otherwise the sampler and exporter threads enter
+ # a race where not all Prometheus db files will be visible to the exporter, resulting
+ # in missing metrics.
+ # Warming up ensures that these files exist prior to the exporter starting up.
+ Gitlab::Metrics::Samplers::RubySampler.initialize_instance(warmup: true).start
exporter_class = "Gitlab::Metrics::Exporter::#{@target.camelize}Exporter".constantize
- server = exporter_class.instance(settings, synchronous: true)
+ settings = Settings.new(Settings.monitoring[name])
+ server = exporter_class.instance(settings, gc_requests: true, synchronous: true)
server.start
end
diff --git a/metrics_server/override_gitlab_current_settings.rb b/metrics_server/override_gitlab_current_settings.rb
new file mode 100644
index 00000000000..1dc19b5da23
--- /dev/null
+++ b/metrics_server/override_gitlab_current_settings.rb
@@ -0,0 +1,21 @@
+# rubocop:disable Naming/FileName
+# frozen_string_literal: true
+
+# We need to supply this outside of Rails because:
+# RubySampler needs Gitlab::Metrics needs Gitlab::Metrics::Prometheus needs Gitlab::CurrentSettings needs ::Settings
+# to check for `prometheus_metrics_enabled`. We therefore simply redirect it to our own Settings type.
+module Gitlab
+ module CurrentSettings
+ class << self
+ def prometheus_metrics_enabled
+ # We make the simplified assumption that when the metrics-server runs,
+ # Prometheus metrics are enabled. Since the latter is a setting stored
+ # in the application database, we have no access to it here, so we need
+ # to hard-code it.
+ true
+ end
+ end
+ end
+end
+
+# rubocop:enable Naming/FileName
diff --git a/metrics_server/settings_overrides.rb b/metrics_server/settings_overrides.rb
index 8572b4f86b0..b3fd39229d5 100644
--- a/metrics_server/settings_overrides.rb
+++ b/metrics_server/settings_overrides.rb
@@ -9,6 +9,11 @@
# Here we make the necessary constants available conditionally.
require_relative 'override_rails_constants' unless Object.const_defined?('Rails')
+# We need to supply this outside of Rails because:
+# RubySampler needs Gitlab::Metrics needs Gitlab::Metrics::Prometheus needs Gitlab::CurrentSettings needs ::Settings
+# to check for `prometheus_metrics_enabled`. We therefore simply redirect it to our own Settings type.
+require_relative 'override_gitlab_current_settings' unless Object.const_defined?('Gitlab::CurrentSettings')
+
require_relative '../config/settings'
# rubocop:enable Naming/FileName