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

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

require 'spec_helper'

RSpec.describe Gitlab::Usage::ServicePing::PayloadKeysProcessor do
  context 'with an object metric' do
    let(:payload) { { counts: { issues: 1, boards: 1 }, topology: { duration_d: 100 }, redis_hll_counters: { search: { i_search_total_monthly: 1 } } } }

    it 'returns the payload keys that have a metric definition' do
      expect(described_class.new(payload).key_paths).to match_array(['counts.issues', 'counts.boards', 'topology', 'redis_hll_counters.search.i_search_total_monthly'])
    end
  end

  context 'with a missing metric definition' do
    let(:payload) { { counts: { issues: 1, boards: 1 }, missing_definition: 1, topology: { duration_d: 100 } } }

    it 'returns the payload keys that have a metric definition' do
      expect(described_class.new(payload).key_paths).to match_array(['counts.issues', 'counts.boards', 'topology'])
    end
  end

  context 'with array metric' do
    let(:payload) { { counts: { issues: 1, boards: 1 }, settings: { collected_data_categories: ['standard'] }, topology: { duration_d: 100 } } }

    it 'returns the payload keys that have a metric definition' do
      expect(described_class.new(payload).key_paths).to match_array(['counts.issues', 'counts.boards', 'topology', 'settings.collected_data_categories'])
    end
  end

  context 'missing_instrumented_metrics_key_paths' do
    let(:payload) do
      {
        counts: { issues: 1, boards: 1 },
        topology: { duration_d: 100 },
        redis_hll_counters: { search: { i_search_total_monthly: 1 } }
      }
    end

    let(:metrics_definitions) do
      [
        double(:issues, key_path: 'counts.issues'),
        double(:topology, key_path: 'topology'),
        double(:i_search_total_monthly, key_path: 'redis_hll_counters.search.i_search_total_monthly'),
        double(:collected_data_categories, key_path: 'settings.collected_data_categories')
      ]
    end

    before do
      allow(::Gitlab::Usage::MetricDefinition).to receive(:with_instrumentation_class).and_return(metrics_definitions)
    end

    it 'returns the missing keys' do
      expect(described_class.new(payload).missing_instrumented_metrics_key_paths).to match_array(['settings.collected_data_categories'])
    end
  end
end