Skip to content

Commit

Permalink
Rename Metrics to PrometheusMetrics
Browse files Browse the repository at this point in the history
To avoid conflicting with a namespace already called 'Metrics'.
  • Loading branch information
thomasleese committed Apr 11, 2022
1 parent 45c510b commit fe54f2e
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/moves_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create_and_render

Notifier.prepare_notifications(topic: move, action_name: 'create')

Metrics.instance.record_move_count
PrometheusMetrics.instance.record_move_count

render_move(move, :created)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v2/moves_actions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create_and_render
create_automatic_event!(eventable: move, event_class: GenericEvent::MoveProposed) if move.proposed?
create_automatic_event!(eventable: move, event_class: GenericEvent::MoveRequested) if move.requested?

Metrics.instance.record_move_count
PrometheusMetrics.instance.record_move_count

render_move(move, :created)
end
Expand Down
2 changes: 1 addition & 1 deletion app/lib/metrics.rb → app/lib/prometheus_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'prometheus/client/data_stores/direct_file_store'

class Metrics
class PrometheusMetrics
include Singleton

def configure
Expand Down
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require 'prometheus/middleware/exporter'
use Prometheus::Middleware::Collector
use Prometheus::Middleware::Exporter

Metrics.instance.record_move_count
PrometheusMetrics.instance.record_move_count

run Rails.application
Rails.application.load_server
3 changes: 0 additions & 3 deletions config/initializers/metrics.rb

This file was deleted.

3 changes: 3 additions & 0 deletions config/initializers/prometheus_metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

PrometheusMetrics.instance.configure
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'rails_helper'

RSpec.describe Metrics do
RSpec.describe PrometheusMetrics do
subject(:instance) { described_class.send(:new) }

let(:registry) { instance_double(Prometheus::Client::Registry) }
Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api/moves_controller_create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
let(:content_type) { ApiController::CONTENT_TYPE }

before do
allow_any_instance_of(Metrics).to receive(:record_move_count) # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(PrometheusMetrics).to receive(:record_move_count) # rubocop:disable RSpec/AnyInstance
end

context 'when successful' do
Expand Down Expand Up @@ -74,7 +74,7 @@
end

it 'records the move count metric' do
expect_any_instance_of(Metrics).to receive(:record_move_count) # rubocop:disable RSpec/AnyInstance
expect_any_instance_of(PrometheusMetrics).to receive(:record_move_count) # rubocop:disable RSpec/AnyInstance
post_moves
end

Expand Down
4 changes: 2 additions & 2 deletions spec/requests/api/moves_controller_create_v2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
before do
allow(person).to receive(:update_nomis_data)
allow_any_instance_of(Move).to receive(:person).and_return(person) # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Metrics).to receive(:record_move_count) # rubocop:disable RSpec/AnyInstance
allow_any_instance_of(PrometheusMetrics).to receive(:record_move_count) # rubocop:disable RSpec/AnyInstance
end

it_behaves_like 'an endpoint that responds with success 201' do
Expand Down Expand Up @@ -88,7 +88,7 @@
end

it 'records the move count metric' do
expect_any_instance_of(Metrics).to receive(:record_move_count) # rubocop:disable RSpec/AnyInstance
expect_any_instance_of(PrometheusMetrics).to receive(:record_move_count) # rubocop:disable RSpec/AnyInstance
do_post
end

Expand Down

0 comments on commit fe54f2e

Please sign in to comment.