debian-mirror-gitlab/lib/gitlab/memory/watchdog/configuration.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.7 KiB
Ruby
Raw Normal View History

2022-11-25 23:54:43 +05:30
# frozen_string_literal: true
module Gitlab
module Memory
class Watchdog
class Configuration
class MonitorStack
def initialize
@monitors = []
end
2023-01-13 00:05:48 +05:30
def push(monitor_class, *args, **kwargs, &block)
2022-11-25 23:54:43 +05:30
@monitors.push(build_monitor_state(monitor_class, *args, **kwargs, &block))
end
def call_each
@monitors.each do |monitor|
yield monitor.call
end
end
2023-03-04 22:38:38 +05:30
def empty?
@monitors.empty?
2022-11-25 23:54:43 +05:30
end
2023-03-04 22:38:38 +05:30
private
def build_monitor_state(monitor_class, *args, max_strikes:, monitor_name: nil, **kwargs, &block)
2022-11-25 23:54:43 +05:30
monitor = build_monitor(monitor_class, *args, **kwargs, &block)
2023-03-04 22:38:38 +05:30
monitor_name ||= monitor_class.name.demodulize.underscore
2022-11-25 23:54:43 +05:30
2023-03-04 22:38:38 +05:30
Gitlab::Memory::Watchdog::MonitorState.new(monitor, max_strikes: max_strikes, monitor_name: monitor_name)
2022-11-25 23:54:43 +05:30
end
def build_monitor(monitor_class, *args, **kwargs, &block)
monitor_class.new(*args, **kwargs, &block)
end
end
DEFAULT_SLEEP_TIME_SECONDS = 60
2023-03-04 22:38:38 +05:30
attr_writer :event_reporter, :handler, :sleep_time_seconds
2022-11-25 23:54:43 +05:30
2023-01-13 00:05:48 +05:30
def monitors
@monitor_stack ||= MonitorStack.new
yield @monitor_stack if block_given?
@monitor_stack
2022-11-25 23:54:43 +05:30
end
def handler
@handler ||= NullHandler.instance
end
2023-03-04 22:38:38 +05:30
def event_reporter
@event_reporter ||= EventReporter.new
2022-11-25 23:54:43 +05:30
end
# Used to control the frequency with which the watchdog will wake up and poll the GC.
def sleep_time_seconds
@sleep_time_seconds ||= DEFAULT_SLEEP_TIME_SECONDS
end
end
end
end
end