2020-01-16 13:08:46 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module SidekiqMiddleware
|
2020-11-26 10:09:30 -05:00
|
|
|
class ClientMetrics
|
|
|
|
include ::Gitlab::SidekiqMiddleware::MetricsHelper
|
|
|
|
|
2020-01-16 13:08:46 -05:00
|
|
|
ENQUEUED = :sidekiq_enqueued_jobs_total
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@metrics = init_metrics
|
|
|
|
end
|
|
|
|
|
2021-02-05 04:09:10 -05:00
|
|
|
def call(worker_class, job, queue, _redis_pool)
|
2020-01-23 10:08:46 -05:00
|
|
|
# worker_class can either be the string or class of the worker being enqueued.
|
2021-10-04 08:11:58 -04:00
|
|
|
worker_class = worker_class.to_s.safe_constantize
|
2021-09-20 20:09:28 -04:00
|
|
|
|
2021-02-05 04:09:10 -05:00
|
|
|
labels = create_labels(worker_class, queue, job)
|
2021-10-05 20:11:56 -04:00
|
|
|
if job.key?('at')
|
|
|
|
labels[:scheduling] = 'delayed'
|
|
|
|
job[:scheduled_at] = job['at']
|
|
|
|
else
|
|
|
|
labels[:scheduling] = 'immediate'
|
|
|
|
end
|
2020-01-16 13:08:46 -05:00
|
|
|
|
|
|
|
@metrics.fetch(ENQUEUED).increment(labels, 1)
|
|
|
|
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def init_metrics
|
|
|
|
{
|
|
|
|
ENQUEUED => ::Gitlab::Metrics.counter(ENQUEUED, 'Sidekiq jobs enqueued')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|