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

sidekiq_slis_spec.rb « metrics « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: eef9a9c79e6dca0cd568b968886a03bdffa36f24 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Metrics::SidekiqSlis, feature_category: :error_budgets do
  using RSpec::Parameterized::TableSyntax

  describe ".initialize_slis!" do
    let(:possible_labels) do
      [
        {
          worker: "Projects::RecordTargetPlatformsWorker",
          feature_category: "projects",
          urgency: "low"
        }
      ]
    end

    it "initializes the apdex and error rate SLIs" do
      expect(Gitlab::Metrics::Sli::Apdex).to receive(:initialize_sli).with(:sidekiq_execution, possible_labels)
      expect(Gitlab::Metrics::Sli::ErrorRate).to receive(:initialize_sli).with(:sidekiq_execution, possible_labels)

      described_class.initialize_slis!(possible_labels)
    end
  end

  describe ".record_execution_apdex" do
    where(:urgency, :duration, :success) do
      "high"      | 5   | true
      "high"      | 11  | false
      "low"       | 295 | true
      "low"       | 400 | false
      "throttled" | 295 | true
      "throttled" | 400 | false
      "not_found" | 295 | true
      "not_found" | 400 | false
    end

    with_them do
      it "increments the apdex SLI with success based on urgency requirement" do
        labels = { urgency: urgency }
        expect(Gitlab::Metrics::Sli::Apdex[:sidekiq_execution]).to receive(:increment).with(
          labels: labels,
          success: success
        )

        described_class.record_execution_apdex(labels, duration)
      end
    end
  end

  describe ".record_execution_error" do
    it "increments the error rate SLI with the given labels and error" do
      labels = { urgency: :throttled }
      error = StandardError.new("something went wrong")

      expect(Gitlab::Metrics::Sli::ErrorRate[:sidekiq_execution]).to receive(:increment).with(
        labels: labels,
        error: error
      )

      described_class.record_execution_error(labels, error)
    end
  end
end