Sha256: f36cbe61a50067d9c41570d7697b06caa3d758f593937b5aa50bc704df7471fd

Contents?: true

Size: 1.77 KB

Versions: 17

Compression:

Stored size: 1.77 KB

Contents

# frozen_string_literal: true

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

17 entries across 17 versions & 1 rubygems

Version Path
lhc-10.5.4 spec/interceptors/prometheus_spec.rb
lhc-10.5.3 spec/interceptors/prometheus_spec.rb
lhc-10.5.2 spec/interceptors/prometheus_spec.rb
lhc-10.5.1 spec/interceptors/prometheus_spec.rb
lhc-10.5.0 spec/interceptors/prometheus_spec.rb
lhc-10.4.3 spec/interceptors/prometheus_spec.rb
lhc-10.4.2 spec/interceptors/prometheus_spec.rb
lhc-10.4.1 spec/interceptors/prometheus_spec.rb
lhc-10.4.0 spec/interceptors/prometheus_spec.rb
lhc-10.3.0 spec/interceptors/prometheus_spec.rb
lhc-10.2.1 spec/interceptors/prometheus_spec.rb
lhc-10.2.0 spec/interceptors/prometheus_spec.rb
lhc-10.1.8 spec/interceptors/prometheus_spec.rb
lhc-10.1.7 spec/interceptors/prometheus_spec.rb
lhc-10.1.6 spec/interceptors/prometheus_spec.rb
lhc-10.1.5 spec/interceptors/prometheus_spec.rb
lhc-10.1.3 spec/interceptors/prometheus_spec.rb