diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-21 18:12:22 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-21 18:12:22 +0300 |
commit | 5dc70663c4ff1feb215428ce50673b5b646f9809 (patch) | |
tree | 944bde8a8350ac8ee64335cc5b98d1c60ba9c3c5 /lib/gitlab/memory | |
parent | fbc1f4ffc29ae99f438b07872c3c00fbe7651caa (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/gitlab/memory')
-rw-r--r-- | lib/gitlab/memory/reports/heap_dump.rb | 45 | ||||
-rw-r--r-- | lib/gitlab/memory/watchdog.rb | 14 | ||||
-rw-r--r-- | lib/gitlab/memory/watchdog/configuration.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/memory/watchdog/configurator.rb | 14 |
4 files changed, 64 insertions, 15 deletions
diff --git a/lib/gitlab/memory/reports/heap_dump.rb b/lib/gitlab/memory/reports/heap_dump.rb new file mode 100644 index 00000000000..b81464ed5cf --- /dev/null +++ b/lib/gitlab/memory/reports/heap_dump.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +module Gitlab + module Memory + module Reports + class HeapDump + class << self + def enqueue! + log_event('enqueue') + @write_heap_dump = true + end + + # This is a no-op currently and will be implemented at a later time in + # https://gitlab.com/gitlab-org/gitlab/-/issues/370077 + def write_conditionally + return false unless enqueued? + + log_event('write') + + true + end + + private + + def enqueued? + !!@write_heap_dump + end + + def log_event(message) + Gitlab::AppLogger.info( + message: message, + pid: $$, + worker_id: worker_id, + perf_report: 'heap_dump' + ) + end + + def worker_id + ::Prometheus::PidProvider.worker_id + end + end + end + end + end +end diff --git a/lib/gitlab/memory/watchdog.rb b/lib/gitlab/memory/watchdog.rb index 19dfc640b5d..435b416e7e9 100644 --- a/lib/gitlab/memory/watchdog.rb +++ b/lib/gitlab/memory/watchdog.rb @@ -55,16 +55,8 @@ module Gitlab end ## - # Configuration for Watchdog, use like: - # - # watchdog.configure do |config| - # config.handler = Gitlab::Memory::Watchdog::TermProcessHandler - # config.sleep_time_seconds = 60 - # config.logger = Gitlab::AppLogger - # config.monitors do |stack| - # stack.push MyMonitorClass, args*, max_strikes:, kwargs**, &block - # end - # end + # Configuration for Watchdog, see Gitlab::Memory::Watchdog::Configurator + # for examples. def configure yield @configuration end @@ -106,6 +98,8 @@ module Gitlab logger.warn(all_labels) @counter_violations_handled.increment(reason: monitor_name) + Gitlab::Memory::Reports::HeapDump.enqueue! if @configuration.write_heap_dumps? + handler.call end diff --git a/lib/gitlab/memory/watchdog/configuration.rb b/lib/gitlab/memory/watchdog/configuration.rb index 793f75adf59..4bad9475531 100644 --- a/lib/gitlab/memory/watchdog/configuration.rb +++ b/lib/gitlab/memory/watchdog/configuration.rb @@ -39,7 +39,7 @@ module Gitlab DEFAULT_SLEEP_TIME_SECONDS = 60 - attr_writer :logger, :handler, :sleep_time_seconds + attr_writer :logger, :handler, :sleep_time_seconds, :write_heap_dumps def monitors @monitor_stack ||= MonitorStack.new @@ -59,6 +59,10 @@ module Gitlab def sleep_time_seconds @sleep_time_seconds ||= DEFAULT_SLEEP_TIME_SECONDS end + + def write_heap_dumps? + !!@write_heap_dumps + end end end end diff --git a/lib/gitlab/memory/watchdog/configurator.rb b/lib/gitlab/memory/watchdog/configurator.rb index 6d6f97dc8ba..da3733731a7 100644 --- a/lib/gitlab/memory/watchdog/configurator.rb +++ b/lib/gitlab/memory/watchdog/configurator.rb @@ -7,26 +7,32 @@ module Gitlab class << self def configure_for_puma lambda do |config| - sleep_time_seconds = ENV.fetch('GITLAB_MEMWD_SLEEP_TIME_SEC', 60).to_i config.logger = Gitlab::AppLogger config.handler = Gitlab::Memory::Watchdog::PumaHandler.new - config.sleep_time_seconds = sleep_time_seconds + config.write_heap_dumps = write_heap_dumps? + config.sleep_time_seconds = ENV.fetch('GITLAB_MEMWD_SLEEP_TIME_SEC', 60).to_i config.monitors(&configure_monitors_for_puma) end end def configure_for_sidekiq lambda do |config| - sleep_time_seconds = [ENV.fetch('SIDEKIQ_MEMORY_KILLER_CHECK_INTERVAL', 3).to_i, 2].max config.logger = Sidekiq.logger config.handler = Gitlab::Memory::Watchdog::TermProcessHandler.new - config.sleep_time_seconds = sleep_time_seconds + config.write_heap_dumps = write_heap_dumps? + config.sleep_time_seconds = [ + ENV.fetch('SIDEKIQ_MEMORY_KILLER_CHECK_INTERVAL', 3).to_i, 2 + ].max config.monitors(&configure_monitors_for_sidekiq) end end private + def write_heap_dumps? + Gitlab::Utils.to_boolean(ENV['GITLAB_MEMWD_DUMP_HEAP'], default: false) + end + def configure_monitors_for_puma lambda do |stack| max_strikes = ENV.fetch('GITLAB_MEMWD_MAX_STRIKES', 5).to_i |