summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/metrics/exporter/web_exporter_spec.rb
blob: ce98c807e2ef9a64d291acc41ff7e110cc6556f1 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Metrics::Exporter::WebExporter do
  let(:exporter) { described_class.new }
  let(:readiness_probe) { exporter.send(:readiness_probe).execute }

  before do
    stub_config(
      monitoring: {
        web_exporter: {
          enabled: true,
          port: 0,
          address: '127.0.0.1'
        }
      }
    )

    exporter.start
  end

  after do
    exporter.stop
  end

  context 'when running server' do
    it 'readiness probe returns succesful status' do
      expect(readiness_probe.http_status).to eq(200)
      expect(readiness_probe.json).to include(status: 'ok')
      expect(readiness_probe.json).to include('web_exporter' => [{ 'status': 'ok' }])
    end
  end

  describe '#mark_as_not_running!' do
    it 'readiness probe returns a failure status' do
      exporter.mark_as_not_running!

      expect(readiness_probe.http_status).to eq(503)
      expect(readiness_probe.json).to include(status: 'failed')
      expect(readiness_probe.json).to include('web_exporter' => [{ 'status': 'failed' }])
    end
  end
end