2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module SidekiqMiddleware
|
2021-02-22 17:27:13 +05:30
|
|
|
class ClientMetrics
|
|
|
|
include ::Gitlab::SidekiqMiddleware::MetricsHelper
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
ENQUEUED = :sidekiq_enqueued_jobs_total
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@metrics = init_metrics
|
|
|
|
end
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
def call(worker_class, job, queue, _redis_pool)
|
2020-03-13 15:44:24 +05:30
|
|
|
# worker_class can either be the string or class of the worker being enqueued.
|
2021-11-18 22:05:49 +05:30
|
|
|
worker_class = worker_class.to_s.safe_constantize
|
|
|
|
|
2021-03-11 19:13:27 +05:30
|
|
|
labels = create_labels(worker_class, queue, job)
|
2021-11-18 22:05:49 +05:30
|
|
|
if job.key?('at')
|
|
|
|
labels[:scheduling] = 'delayed'
|
|
|
|
job[:scheduled_at] = job['at']
|
|
|
|
else
|
|
|
|
labels[:scheduling] = 'immediate'
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
@metrics.fetch(ENQUEUED).increment(labels, 1)
|
|
|
|
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def init_metrics
|
|
|
|
{
|
|
|
|
ENQUEUED => ::Gitlab::Metrics.counter(ENQUEUED, 'Sidekiq jobs enqueued')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|