Welcome to mirror list, hosted at ThFree Co, Russian Federation.

client_metrics.rb « sidekiq_middleware « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef80ed706f3d30b3af48163e267db9912af518ca (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
# frozen_string_literal: true

module Gitlab
  module SidekiqMiddleware
    class ClientMetrics
      include ::Gitlab::SidekiqMiddleware::MetricsHelper

      ENQUEUED = :sidekiq_enqueued_jobs_total

      def initialize
        @metrics = init_metrics
      end

      def call(worker_class, job, queue, _redis_pool)
        # worker_class can either be the string or class of the worker being enqueued.
        worker_class = worker_class.to_s.safe_constantize

        labels = create_labels(worker_class, queue, job)
        if job.key?('at')
          labels[:scheduling] = 'delayed'
          job[:scheduled_at] = job['at']
        else
          labels[:scheduling] = 'immediate'
        end

        @metrics.fetch(ENQUEUED).increment(labels, 1)

        yield
      end

      private

      def init_metrics
        {
          ENQUEUED => ::Gitlab::Metrics.counter(ENQUEUED, 'Sidekiq jobs enqueued')
        }
      end
    end
  end
end