discourse / prometheus_exporter

A framework for collecting and aggregating prometheus metrics
MIT License
525 stars 153 forks source link

How to test with rspec or another testing framework #178

Open Ri1a opened 2 years ago

Ri1a commented 2 years ago

Using the prometheus_exporter I wanted to check if the metrics I calculate are correctly set when I navigate to /metrics. Is there a way to test this with rspec request specs (or with another testing framework)? Maybe I missed some documentation, but I couldn't find any.

Context: spec/requests/customer_collector_request_spec.rb

require 'rails_helper'

RSpec.describe 'Customer Collector', type: :request do
  describe 'GET /metrics' do
    it 'returns http success' do
      get '/metrics'
      expect(response).to have_http_status(:success)
    end
  end
end

Results into the following failure:

F

Failures:

  1) Customer Collector GET /metrics returns http success
     Failure/Error: get '/metrics'

     ActionController::RoutingError:
       No route matches [GET] "/metrics"
     # ./spec/requests/customer_collector_request_spec.rb:8:in `block (3 levels) in <top (required)>'

Finished in 0.35432 seconds (files took 3.37 seconds to load)
1 example, 1 failure