2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
# Keep separate directories for separate processes
|
|
|
|
def prometheus_default_multiproc_dir
|
|
|
|
return unless Rails.env.development? || Rails.env.test?
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
if Gitlab::Runtime.sidekiq?
|
2019-09-30 21:07:59 +05:30
|
|
|
Rails.root.join('tmp/prometheus_multiproc_dir/sidekiq')
|
2020-03-13 15:44:24 +05:30
|
|
|
elsif Gitlab::Runtime.puma?
|
2019-09-30 21:07:59 +05:30
|
|
|
Rails.root.join('tmp/prometheus_multiproc_dir/puma')
|
|
|
|
else
|
|
|
|
Rails.root.join('tmp/prometheus_multiproc_dir')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
::Prometheus::Client.configure do |config|
|
2020-11-24 15:15:51 +05:30
|
|
|
config.logger = Gitlab::AppLogger
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
config.initial_mmap_file_size = 4 * 1024
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
config.multiprocess_files_dir = ENV['prometheus_multiproc_dir'] || prometheus_default_multiproc_dir
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
config.pid_provider = ::Prometheus::PidProvider.method(:worker_id)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
Gitlab::Application.configure do |config|
|
|
|
|
# 0 should be Sentry to catch errors in this middleware
|
2021-09-04 01:27:46 +05:30
|
|
|
config.middleware.insert_after(Labkit::Middleware::Rack, Gitlab::Metrics::RequestsRackMiddleware)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
Sidekiq.configure_server do |config|
|
|
|
|
config.on(:startup) do
|
2020-01-01 13:55:28 +05:30
|
|
|
# Do not clean the metrics directory here - the supervisor script should
|
|
|
|
# have already taken care of that
|
2019-12-21 20:55:43 +05:30
|
|
|
Gitlab::Metrics::Exporter::SidekiqExporter.instance.start
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
|
2021-03-11 19:13:27 +05:30
|
|
|
# When running Puma in a Single mode, `on_master_start` and `on_worker_start` are the same.
|
|
|
|
# Thus, we order these events to run `reinitialize_on_pid_change` with `force: true` first.
|
|
|
|
Gitlab::Cluster::LifecycleEvents.on_master_start do
|
|
|
|
::Prometheus::Client.reinitialize_on_pid_change(force: true)
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
if Gitlab::Runtime.puma?
|
2021-03-11 19:13:27 +05:30
|
|
|
Gitlab::Metrics::Samplers::PumaSampler.instance.start
|
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
Gitlab::Metrics.gauge(:deployments, 'GitLab Version', {}, :max).set({ version: Gitlab::VERSION, revision: Gitlab.revision }, 1)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
if Gitlab::Runtime.web_server?
|
2021-03-11 19:13:27 +05:30
|
|
|
Gitlab::Metrics::RequestsRackMiddleware.initialize_metrics
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Ci::Parsers.instrument!
|
|
|
|
rescue IOError => e
|
|
|
|
Gitlab::ErrorTracking.track_exception(e)
|
|
|
|
Gitlab::Metrics.error_detected!
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
Gitlab::Cluster::LifecycleEvents.on_worker_start do
|
2021-09-30 23:02:18 +05:30
|
|
|
defined?(::Prometheus::Client.reinitialize_on_pid_change) && ::Prometheus::Client.reinitialize_on_pid_change
|
2018-12-13 13:39:08 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
Gitlab::Metrics::Samplers::RubySampler.initialize_instance.start
|
|
|
|
Gitlab::Metrics::Samplers::DatabaseSampler.initialize_instance.start
|
2020-10-24 23:57:45 +05:30
|
|
|
Gitlab::Metrics::Samplers::ThreadsSampler.initialize_instance.start
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
if Gitlab::Runtime.action_cable?
|
|
|
|
Gitlab::Metrics::Samplers::ActionCableSampler.instance.start
|
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
if Gitlab.ee? && Gitlab::Runtime.sidekiq?
|
2020-06-23 00:09:42 +05:30
|
|
|
Gitlab::Metrics::Samplers::GlobalSearchSampler.instance.start
|
2020-04-22 19:07:51 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
Gitlab::Ci::Parsers.instrument!
|
2020-01-12 00:16:45 +05:30
|
|
|
rescue IOError => e
|
|
|
|
Gitlab::ErrorTracking.track_exception(e)
|
|
|
|
Gitlab::Metrics.error_detected!
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
if Gitlab::Runtime.web_server?
|
2019-12-21 20:55:43 +05:30
|
|
|
Gitlab::Cluster::LifecycleEvents.on_master_start do
|
|
|
|
Gitlab::Metrics::Exporter::WebExporter.instance.start
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
# DEPRECATED: TO BE REMOVED
|
|
|
|
# This is needed to implement blackout period of `web_exporter`
|
|
|
|
# https://gitlab.com/gitlab-org/gitlab/issues/35343#note_238479057
|
|
|
|
Gitlab::Cluster::LifecycleEvents.on_before_blackout_period do
|
|
|
|
Gitlab::Metrics::Exporter::WebExporter.instance.mark_as_not_running!
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Cluster::LifecycleEvents.on_before_graceful_shutdown do
|
|
|
|
# We need to ensure that before we re-exec or shutdown server
|
2019-12-21 20:55:43 +05:30
|
|
|
# we do stop the exporter
|
|
|
|
Gitlab::Metrics::Exporter::WebExporter.instance.stop
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Cluster::LifecycleEvents.on_before_master_restart do
|
|
|
|
# We need to ensure that before we re-exec server
|
|
|
|
# we do stop the exporter
|
|
|
|
#
|
|
|
|
# We do it again, for being extra safe,
|
|
|
|
# but it should not be needed
|
|
|
|
Gitlab::Metrics::Exporter::WebExporter.instance.stop
|
|
|
|
end
|
|
|
|
|
|
|
|
Gitlab::Cluster::LifecycleEvents.on_worker_start do
|
|
|
|
# The `#close_on_exec=` takes effect only on `execve`
|
|
|
|
# but this does not happen for Ruby fork
|
|
|
|
#
|
|
|
|
# This does stop server, as it is running on master.
|
|
|
|
Gitlab::Metrics::Exporter::WebExporter.instance.stop
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
end
|