Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/sidekiq_prometheus.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require "benchmark"
require "rack"
require "rackup"
require "prometheus/client"
Expand Down
8 changes: 7 additions & 1 deletion lib/sidekiq_prometheus/job_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def call(worker, job, queue)
labels.merge!(custom_labels(worker))

result = nil
duration = Benchmark.realtime { result = yield }
duration = measuring_duration { result = yield }

# In case the labels have changed after the worker perform method has been called
labels.merge!(custom_labels(worker))
Expand Down Expand Up @@ -52,4 +52,10 @@ def registry
def custom_labels(worker)
worker.respond_to?(:prometheus_labels) ? worker.prometheus_labels : {}
end

def measuring_duration
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
yield
Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
end
end