diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/initializers/7_prometheus_metrics.rb | 15 | ||||
-rw-r--r-- | config/puma.example.development.rb | 4 | ||||
-rw-r--r-- | config/puma.rb.example | 4 | ||||
-rw-r--r-- | config/unicorn.rb.example | 15 | ||||
-rw-r--r-- | config/unicorn.rb.example.development | 15 |
5 files changed, 27 insertions, 26 deletions
diff --git a/config/initializers/7_prometheus_metrics.rb b/config/initializers/7_prometheus_metrics.rb index 68f8487d377..54cdefc2a10 100644 --- a/config/initializers/7_prometheus_metrics.rb +++ b/config/initializers/7_prometheus_metrics.rb @@ -43,14 +43,21 @@ if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled? end end -Gitlab::Cluster::LifecycleEvents.on_master_restart do +def cleanup_prometheus_multiproc_dir # The following is necessary to ensure stale Prometheus metrics don't # accumulate over time. It needs to be done in this hook as opposed to # inside an init script to ensure metrics files aren't deleted after new # unicorn workers start after a SIGUSR2 is received. - prometheus_multiproc_dir = ENV['prometheus_multiproc_dir'] - if prometheus_multiproc_dir - old_metrics = Dir[File.join(prometheus_multiproc_dir, '*.db')] + if dir = ::Prometheus::Client.configuration.multiprocess_files_dir + old_metrics = Dir[File.join(dir, '*.db')] FileUtils.rm_rf(old_metrics) end end + +Gitlab::Cluster::LifecycleEvents.on_master_start do + cleanup_prometheus_multiproc_dir +end + +Gitlab::Cluster::LifecycleEvents.on_master_restart do + cleanup_prometheus_multiproc_dir +end diff --git a/config/puma.example.development.rb b/config/puma.example.development.rb index 7cb9fb01b25..9df24bf74e3 100644 --- a/config/puma.example.development.rb +++ b/config/puma.example.development.rb @@ -49,10 +49,6 @@ on_restart do end before_fork do - # We want to clean things up (e.g. metric files) at first boot. So make sure - # Puma calls the same callback at boot as Unicorn. - Gitlab::Cluster::LifecycleEvents.do_master_restart - # Signal to the puma killer Gitlab::Cluster::PumaWorkerKillerInitializer.start @config.options unless ENV['DISABLE_PUMA_WORKER_KILLER'] diff --git a/config/puma.rb.example b/config/puma.rb.example index 731c2563150..6558dbc6cfe 100644 --- a/config/puma.rb.example +++ b/config/puma.rb.example @@ -44,10 +44,6 @@ on_restart do end before_fork do - # We want to clean things up (e.g. metric files) at first boot. So make sure - # Puma calls the same callback at boot as Unicorn. - Gitlab::Cluster::LifecycleEvents.do_master_restart - # Signal to the puma killer Gitlab::Cluster::PumaWorkerKillerInitializer.start @config.options unless ENV['DISABLE_PUMA_WORKER_KILLER'] diff --git a/config/unicorn.rb.example b/config/unicorn.rb.example index b4da1568511..581fde84c95 100644 --- a/config/unicorn.rb.example +++ b/config/unicorn.rb.example @@ -92,17 +92,18 @@ run_once = true before_fork do |server, worker| if run_once + # There is a difference between Puma and Unicorn: + # - Puma calls before_fork once when booting up master process + # - Unicorn runs before_fork whenever new work is spawned + # To unify this behavior we call before_fork only once (we use + # this callback for deleting Prometheus files so for our purposes + # it makes sense to align behavior with Puma) run_once = false - # The Unicorn before_exec hook only gets called on a Unicorn - # restart, but we want to clean things up (e.g. metric files) at - # first boot. - Gitlab::Cluster::LifecycleEvents.do_master_restart + # Signal application hooks that we're about to fork + Gitlab::Cluster::LifecycleEvents.do_before_fork end - # Signal application hooks that we're about to fork - Gitlab::Cluster::LifecycleEvents.do_before_fork - # The following is only recommended for memory/DB-constrained # installations. It is not needed if your system can house # twice as many worker_processes as you have configured. diff --git a/config/unicorn.rb.example.development b/config/unicorn.rb.example.development index 1ff55701c14..9a02d5f1007 100644 --- a/config/unicorn.rb.example.development +++ b/config/unicorn.rb.example.development @@ -25,17 +25,18 @@ run_once = true before_fork do |server, worker| if run_once + # There is a difference between Puma and Unicorn: + # - Puma calls before_fork once when booting up master process + # - Unicorn runs before_fork whenever new work is spawned + # To unify this behavior we call before_fork only once (we use + # this callback for deleting Prometheus files so for our purposes + # it makes sense to align behavior with Puma) run_once = false - # The Unicorn before_exec hook only gets called on a Unicorn - # restart, but we want to clean things up (e.g. metric files) at - # first boot. - Gitlab::Cluster::LifecycleEvents.do_master_restart + # Signal application hooks that we're about to fork + Gitlab::Cluster::LifecycleEvents.do_before_fork end - # Signal application hooks that we're about to fork - Gitlab::Cluster::LifecycleEvents.do_before_fork - # The following is only recommended for memory/DB-constrained # installations. It is not needed if your system can house # twice as many worker_processes as you have configured. |