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

redis_metric_spec.rb « instrumentations « metrics « usage « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c4d6edd43e183ac79da1caf890fd5d1ebaccd128 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Usage::Metrics::Instrumentations::RedisMetric, :clean_gitlab_redis_shared_state do
  before do
    4.times do
      Gitlab::UsageDataCounters::SourceCodeCounter.count(:pushes)
    end
  end

  let(:expected_value) { 4 }

  it_behaves_like 'a correct instrumented metric value', {
    options: { event: 'pushes', prefix: 'source_code' },
    time_frame: 'all'
  }

  it 'raises an exception if event option is not present' do
    expect do
      described_class.new(options: { prefix: 'source_code' }, time_frame: 'all')
    end.to raise_error(ArgumentError, /'event' option is required/)
  end

  it 'raises an exception if prefix option is not present' do
    expect do
      described_class.new(options: { event: 'pushes' }, time_frame: 'all')
    end.to raise_error(ArgumentError, /'prefix' option is required/)
  end

  describe 'children classes' do
    let(:options) { { event: 'pushes', prefix: 'source_code' } }

    context 'availability not defined' do
      subject { Class.new(described_class).new(time_frame: nil, options: options) }

      it 'returns default availability' do
        expect(subject.available?).to eq(true)
      end
    end

    context 'availability defined' do
      subject do
        Class.new(described_class) do
          available? { false }
        end.new(time_frame: nil, options: options)
      end

      it 'returns defined availability' do
        expect(subject.available?).to eq(false)
      end
    end
  end

  context "with usage prefix disabled" do
    let(:expected_value) { 3 }

    before do
      3.times do
        Gitlab::UsageDataCounters::WebIdeCounter.increment_merge_requests_count
      end
    end

    it_behaves_like 'a correct instrumented metric value', {
      options: { event: 'merge_requests_count', prefix: 'web_ide', include_usage_prefix: false },
      time_frame: 'all'
    }
  end

  context "with prefix disabled" do
    let(:expected_value) { 3 }

    before do
      3.times do
        Gitlab::UsageDataCounters::SearchCounter.count(:all_searches)
      end
    end

    it_behaves_like 'a correct instrumented metric value', {
      options: { event: 'all_searches_count', prefix: nil, include_usage_prefix: false }, time_frame: 'all'
    }
  end
end