Sha256: 6b40da9a4516b225da80c9ad115a0b034cfa253d3170a65f54b1b86494188da5

Contents?: true

Size: 1.74 KB

Versions: 39

Compression:

Stored size: 1.74 KB

Contents

require 'rails_helper'
require 'prometheus/client'

describe LHC::Prometheus do
  before(:each) do
    LHC.config.interceptors = [LHC::Prometheus]
    LHC::Prometheus.client = Prometheus::Client
    LHC::Prometheus.namespace = 'test_app'
    stub_request(:get, 'http://local.ch')
    expect(Prometheus::Client).to receive(:registry).and_call_original.at_least(:once)
  end

  let(:client) { double("prometheus/client") }

  context 'registering' do
    it 'creates a counter and histogram registry in the prometheus client' do
      expect(Prometheus::Client.registry).to receive(:counter).and_call_original.once
        .with(:test_app_lhc_requests, 'Counter of all LHC requests.')
      expect(Prometheus::Client.registry).to receive(:histogram).and_call_original.once
        .with(:test_app_lhc_times, 'Times for all LHC requests.')

      LHC.get('http://local.ch')
      LHC.get('http://local.ch') # second request, registration should happen only once
    end
  end

  context 'logging' do
    let(:requests_registry_double) { double('requests_registry_double') }
    let(:times_registry_double) { double('times_registry_double') }

    it 'logs monitoring information to the created registries' do
      expect(Prometheus::Client.registry).to receive(:get).and_return(requests_registry_double).once
        .with(:test_app_lhc_requests)
      expect(Prometheus::Client.registry).to receive(:get).and_return(times_registry_double).once
        .with(:test_app_lhc_times)

      expect(requests_registry_double).to receive(:increment).once
        .with(
          code: 200,
          success: true,
          timeout: false
        )
      expect(times_registry_double).to receive(:observe).once
        .with({}, 0)

      LHC.get('http://local.ch')
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
lhc-10.1.2 spec/interceptors/prometheus_spec.rb
lhc-10.1.1 spec/interceptors/prometheus_spec.rb
lhc-10.1.0 spec/interceptors/prometheus_spec.rb
lhc-10.0.2 spec/interceptors/prometheus_spec.rb
lhc-9.4.4 spec/interceptors/prometheus_spec.rb
lhc-10.0.1 spec/interceptors/prometheus_spec.rb
lhc-10.0.0 spec/interceptors/prometheus_spec.rb
lhc-9.4.3 spec/interceptors/prometheus_spec.rb
lhc-9.4.2 spec/interceptors/prometheus_spec.rb
lhc-9.4.1 spec/interceptors/prometheus_spec.rb
lhc-9.4.0 spec/interceptors/prometheus_spec.rb
lhc-9.3.1 spec/interceptors/prometheus_spec.rb
lhc-9.3.0 spec/interceptors/prometheus_spec.rb
lhc-9.2.0 spec/interceptors/prometheus_spec.rb
lhc-9.1.2 spec/interceptors/prometheus_spec.rb
lhc-9.1.2.pre spec/interceptors/prometheus_spec.rb
lhc-9.1.1 spec/interceptors/prometheus_spec.rb
lhc-8.1.1 spec/interceptors/prometheus_spec.rb
lhc-9.1.0 spec/interceptors/prometheus_spec.rb
lhc-9.0.0 spec/interceptors/prometheus_spec.rb