lib/gitlab/sidekiq_middleware/server_metrics.rb
# SIDEKIQ_LATENCY_BUCKETS are latency histogram buckets better suited to Sidekiq
# timeframes than the DEFAULT_BUCKET definition. Defined in seconds.
SIDEKIQ_LATENCY_BUCKETS are latency histogram buckets better suited to Sidekiq
timeframes than the DEFAULT_BUCKET definition. Defined in seconds.
SIDEKIQ_LATENCY_BUCKETS are latency histogram buckets better suited to Sidekiq timeframes than the DEFAULT_BUCKET definition . Defined in seconds .
def call(worker, job, queue)
        labels = create_labels(worker.class, queue)
        queue_duration = ::Gitlab::InstrumentationHelper.queue_duration_for_job(job)
        @metrics[:sidekiq_jobs_queue_duration_seconds].observe(labels, queue_duration) if queue_duration
        @metrics[:sidekiq_running_jobs].increment(labels, 1)
        if job['retry_count'].present?
          @metrics[:sidekiq_jobs_retried_total].increment(labels, 1)
        end
        job_succeeded = false
        monotonic_time_start = Gitlab::Metrics::System.monotonic_time
        job_thread_cputime_start = get_thread_cputime
        begin
          yield
          job_succeeded = true
        ensure
          monotonic_time_end = Gitlab::Metrics::System.monotonic_time
          job_thread_cputime_end = get_thread_cputime
          monotonic_time = monotonic_time_end - monotonic_time_start
          job_thread_cputime = job_thread_cputime_end - job_thread_cputime_start
          @metrics[:sidekiq_running_jobs].increment(labels, -1)
          @metrics[:sidekiq_jobs_failed_total].increment(labels, 1) unless job_succeeded
          labels[:job_status] = job_succeeded ? "done" : "fail"
          @metrics[:sidekiq_jobs_cpu_seconds].observe(labels, job_thread_cputime)
          @metrics[:sidekiq_jobs_completion_seconds].observe(labels, monotonic_time)
          @metrics[:sidekiq_jobs_db_seconds].observe(labels, ActiveRecord::LogSubscriber.runtime / 1000)
          @metrics[:sidekiq_jobs_gitaly_seconds].observe(labels, get_gitaly_time(job))
          @metrics[:sidekiq_redis_requests_total].increment(labels, get_redis_calls(job))
          @metrics[:sidekiq_redis_requests_duration_seconds].observe(labels, get_redis_time(job))
          @metrics[:sidekiq_elasticsearch_requests_total].increment(labels, get_elasticsearch_calls(job))
          @metrics[:sidekiq_elasticsearch_requests_duration_seconds].observe(labels, get_elasticsearch_time(job))
        end
      end
def call ( worker , job , queue ) labels = create_labels ( worker . class , queue ) queue_duration = :: Gitlab :: InstrumentationHelper . queue_duration_for_job ( job ) @metrics [ :sidekiq_jobs_queue_duration_seconds ] . observe ( labels , queue_duration ) if queue_duration @metrics [ :sidekiq_running_jobs ] . increment ( labels , 1 ) if job [ 'retry_count' ] . present? @metrics [ :sidekiq_jobs_retried_total ] . increment ( labels , 1 ) end job_succeeded = false monotonic_time_start = Gitlab :: Metrics :: System . monotonic_time job_thread_cputime_start = get_thread_cputime begin yield job_succeeded = true ensure monotonic_time_end = Gitlab :: Metrics :: System . monotonic_time job_thread_cputime_end = get_thread_cputime monotonic_time = monotonic_time_end - monotonic_time_start job_thread_cputime = job_thread_cputime_end - job_thread_cputime_start @metrics [ :sidekiq_running_jobs ] . increment ( labels , - 1 ) @metrics [ :sidekiq_jobs_failed_total ] . increment ( labels , 1 ) unless job_succeeded labels [ :job_status ] = job_succeeded ? "done" : "fail" @metrics [ :sidekiq_jobs_cpu_seconds ] . observe ( labels , job_thread_cputime ) @metrics [ :sidekiq_jobs_completion_seconds ] . observe ( labels , monotonic_time ) @metrics [ :sidekiq_jobs_db_seconds ] . observe ( labels , ActiveRecord :: LogSubscriber . runtime / 1000 ) @metrics [ :sidekiq_jobs_gitaly_seconds ] . observe ( labels , get_gitaly_time ( job ) ) @metrics [ :sidekiq_redis_requests_total ] . increment ( labels , get_redis_calls ( job ) ) @metrics [ :sidekiq_redis_requests_duration_seconds ] . observe ( labels , get_redis_time ( job ) ) @metrics [ :sidekiq_elasticsearch_requests_total ] . increment ( labels , get_elasticsearch_calls ( job ) ) @metrics [ :sidekiq_elasticsearch_requests_duration_seconds ] . observe ( labels , get_elasticsearch_time ( job ) ) end end
SIDEKIQ_LATENCY_BUCKETS are latency histogram buckets better suited to Sidekiq
timeframes than the DEFAULT_BUCKET definition.
SIDEKIQ_LATENCY_BUCKETS are latency histogram buckets better suited to Sidekiq timeframes than the DEFAULT_BUCKET definition .
# sidekiq_running_jobs, sidekiq_jobs_failed_total should not include the job_status label # job_status: done, fail match the job_status attribute in structured logging
worker
<not_specific>
job
<not_specific>
queue
<not_specific>