diff --git a/config.ru b/config.ru index e9964ddc96ebe5eb34bd09b84a72127b74b65ee0..c74a49cd0e2c6f1166350f72c1b853d4ddf9c7ab 100644 --- a/config.ru +++ b/config.ru @@ -9,6 +9,12 @@ def master_process? end warmup do |app| + # The following is necessary to ensure stale Prometheus metrics don't accumulate over time. + # It needs to be done as early as here to ensure metrics files aren't deleted. + # After we hit our app in `warmup`, first metrics and corresponding files already being created, + # for example in `lib/gitlab/metrics/requests_rack_middleware.rb`. + Prometheus::CleanupMultiprocDirService.new.execute if master_process? + client = Rack::MockRequest.new(app) client.get('/') end diff --git a/config/initializers/7_prometheus_metrics.rb b/config/initializers/7_prometheus_metrics.rb index fc69ae7b0777dcb0654828bb01847396e460a60d..d2d546a54386d0f1c46d2131d86db86a0b05024f 100644 --- a/config/initializers/7_prometheus_metrics.rb +++ b/config/initializers/7_prometheus_metrics.rb @@ -40,9 +40,6 @@ def prometheus_default_multiproc_dir # 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 - # Ensure that stale Prometheus metrics don't accumulate over time - ::Prometheus::CleanupMultiprocDirService.new.execute - ::Prometheus::Client.reinitialize_on_pid_change(force: true) if Gitlab::Runtime.puma?