blob: 473ed1b8094c7413837157ad1b3c3a7c58ea7be0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# frozen_string_literal: true
module Gitlab
module Memory
class Watchdog
class SidekiqEventReporter
include ::Gitlab::Utils::StrongMemoize
delegate :threshold_violated, :started, :stopped, :logger, to: :event_reporter
def initialize(logger: ::Sidekiq.logger)
@event_reporter = EventReporter.new(logger: logger)
@sidekiq_daemon_monitor = Gitlab::SidekiqDaemon::Monitor.instance
init_prometheus_metrics
end
def strikes_exceeded(monitor_name, labels = {})
running_jobs = fetch_running_jobs
labels[:running_jobs] = running_jobs
increment_worker_counters(running_jobs)
event_reporter.strikes_exceeded(monitor_name, labels)
end
private
attr_reader :event_reporter
def fetch_running_jobs
@sidekiq_daemon_monitor.jobs.map do |jid, job|
{
jid: jid,
worker_class: job[:worker_class].name
}
end
end
def increment_worker_counters(running_jobs)
running_jobs.each do |job|
@sidekiq_watchdog_running_jobs_counter.increment({ worker_class: job[:worker_class] })
end
end
def init_prometheus_metrics
@sidekiq_watchdog_running_jobs_counter = ::Gitlab::Metrics.counter(
:sidekiq_watchdog_running_jobs_total,
'Current running jobs when limit was reached'
)
end
end
end
end
end
|