Skip to content

Commit 2c73114

Browse files
committed
inject prometheus updater
1 parent aece723 commit 2c73114

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lib/delayed_job_plugins/delayed_jobs_metrics.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
module DelayedJobMetrics
22
class Plugin < Delayed::Plugin
3-
def self.prometheus
4-
@prometheus ||= CloudController::DependencyLocator.instance.cc_worker_prometheus_updater
3+
class << self
4+
attr_writer :prometheus
5+
6+
def prometheus
7+
@prometheus ||= CloudController::DependencyLocator.instance.cc_worker_prometheus_updater
8+
end
59
end
610

711
callbacks do |lifecycle|

spec/unit/lib/delayed_job_plugins/delayed_jobs_metrics_spec.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
require 'spec_helper'
22

33
RSpec.describe DelayedJobMetrics::Plugin do
4-
let(:worker) { instance_double(Delayed::Worker, name: 'test_worker') }
4+
let(:prometheus) { instance_double(VCAP::CloudController::Metrics::PrometheusUpdater) }
55

66
before do
7-
@prometheus = instance_double(VCAP::CloudController::Metrics::PrometheusUpdater)
8-
allow(CloudController::DependencyLocator.instance).to receive(:cc_worker_prometheus_updater).and_return(@prometheus)
9-
allow(@prometheus).to receive(:update_histogram_metric)
7+
DelayedJobMetrics::Plugin.prometheus = prometheus
8+
allow(prometheus).to receive(:update_histogram_metric)
9+
end
10+
11+
after do
12+
DelayedJobMetrics::Plugin.prometheus = nil # Reset after each test
1013
end
1114

1215
it 'loads the plugin' do
@@ -26,13 +29,13 @@
2629
worker.name = 'test_worker'
2730
worker.work_off(1)
2831

29-
expect(@prometheus).to have_received(:update_histogram_metric).with(
32+
expect(prometheus).to have_received(:update_histogram_metric).with(
3033
:cc_job_pickup_delay_seconds,
3134
be_within(0.5).of(10.0),
3235
labels: { queue: VCAP::CloudController::Jobs::Queues.generic, worker: 'test_worker' }
3336
).once
3437

35-
expect(@prometheus).to have_received(:update_histogram_metric).with(
38+
expect(prometheus).to have_received(:update_histogram_metric).with(
3639
:cc_job_duration_seconds,
3740
kind_of(Numeric),
3841
labels: { queue: VCAP::CloudController::Jobs::Queues.generic, worker: 'test_worker' }

0 commit comments

Comments
 (0)