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

observe_histograms_service_spec.rb « prometheus_metrics « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a9ee5216d816d1b24ac4978137ca8c1ffe71a8b5 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::PrometheusMetrics::ObserveHistogramsService, feature_category: :continuous_integration do
  let_it_be(:project) { create(:project) }

  let(:params) { {} }

  subject(:execute) { described_class.new(project, params).execute }

  before do
    Gitlab::Metrics.reset_registry!
  end

  context 'with empty data' do
    it 'does not raise errors' do
      is_expected.to be_success
    end
  end

  context 'observes metrics successfully' do
    let(:params) do
      {
        histograms: [
          { name: 'pipeline_graph_link_calculation_duration_seconds', value: '1' },
          { name: 'pipeline_graph_links_per_job_ratio', value: '0.9' }
        ]
      }
    end

    it 'increments the metrics' do
      execute

      expect(histogram_data).to match(a_hash_including({ 0.8 => 0.0, 1 => 1.0, 2 => 1.0 }))

      expect(histogram_data(:pipeline_graph_links_per_job_ratio))
        .to match(a_hash_including({ 0.8 => 0.0, 0.9 => 1.0, 1 => 1.0 }))
    end

    it 'returns an empty body and status code' do
      is_expected.to be_success
      expect(subject.http_status).to eq(:created)
      expect(subject.payload).to eq({})
    end
  end

  context 'with unknown histograms' do
    let(:params) do
      { histograms: [{ name: 'chunky_bacon', value: '4' }] }
    end

    it 'raises ActiveRecord::RecordNotFound error' do
      expect { subject }.to raise_error ActiveRecord::RecordNotFound
    end
  end

  def histogram_data(name = :pipeline_graph_link_calculation_duration_seconds)
    Gitlab::Metrics.registry.get(name)&.get({})
  end
end