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

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

module Gitlab
  module Metrics
    module SidekiqSlis
      EXECUTION_URGENCY_DURATIONS = {
        "high" => 10,
        "low" => 300,
        "throttled" => 300
      }.freeze
      # workers without urgency attribute have "low" urgency by default in
      # WorkerAttributes.get_urgency, just mirroring it here
      DEFAULT_EXECUTION_URGENCY_DURATION = EXECUTION_URGENCY_DURATIONS["low"]

      class << self
        def initialize_slis!(possible_labels)
          Gitlab::Metrics::Sli::Apdex.initialize_sli(:sidekiq_execution, possible_labels)
          Gitlab::Metrics::Sli::ErrorRate.initialize_sli(:sidekiq_execution, possible_labels)
        end

        def record_execution_apdex(labels, job_completion_duration)
          urgency_requirement = execution_duration_for_urgency(labels[:urgency])
          Gitlab::Metrics::Sli::Apdex[:sidekiq_execution].increment(
            labels: labels,
            success: job_completion_duration < urgency_requirement
          )
        end

        def record_execution_error(labels, error)
          Gitlab::Metrics::Sli::ErrorRate[:sidekiq_execution].increment(labels: labels, error: error)
        end

        def execution_duration_for_urgency(urgency)
          EXECUTION_URGENCY_DURATIONS.fetch(urgency, DEFAULT_EXECUTION_URGENCY_DURATION)
        end
      end
    end
  end
end