diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 15:12:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 15:12:25 +0000 |
commit | 068b3a417794ab8506b2e149301b3a60c01df078 (patch) | |
tree | 26ce51b45ae535a6fc47fb04cad8da42ec408a2f /metrics_server | |
parent | 62c78157be8fe8888787162293f13945a5fa5d3e (diff) | |
download | gitlab-ce-068b3a417794ab8506b2e149301b3a60c01df078.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'metrics_server')
-rw-r--r-- | metrics_server/dependencies.rb | 4 | ||||
-rw-r--r-- | metrics_server/metrics_server.rb | 8 | ||||
-rw-r--r-- | metrics_server/override_gitlab_current_settings.rb | 21 | ||||
-rw-r--r-- | metrics_server/settings_overrides.rb | 5 |
4 files changed, 37 insertions, 1 deletions
diff --git a/metrics_server/dependencies.rb b/metrics_server/dependencies.rb index a459efef1ad..494b795b292 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,6 +19,9 @@ 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/health_checks/probes/collection' diff --git a/metrics_server/metrics_server.rb b/metrics_server/metrics_server.rb index 56fc20dcc9d..33b31326d2a 100644 --- a/metrics_server/metrics_server.rb +++ b/metrics_server/metrics_server.rb @@ -40,14 +40,20 @@ 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 + settings = Settings.new(Settings.monitoring[name]) server = exporter_class.instance(settings, synchronous: true) server.start 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 |