File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
lib/prometheus/middleware
spec/prometheus/middleware Expand file tree Collapse file tree 2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 11# encoding: UTF-8
22
3- require 'benchmark'
43require 'prometheus/client'
54
65module Prometheus
@@ -34,6 +33,12 @@ def call(env) # :nodoc:
3433
3534 protected
3635
36+ def realtime
37+ start_time = Process . clock_gettime ( Process ::CLOCK_MONOTONIC )
38+ yield
39+ Process . clock_gettime ( Process ::CLOCK_MONOTONIC ) - start_time
40+ end
41+
3742 def init_request_metrics
3843 @requests = @registry . counter (
3944 :"#{ @metrics_prefix } _requests_total" ,
@@ -58,7 +63,7 @@ def init_exception_metrics
5863
5964 def trace ( env )
6065 response = nil
61- duration = Benchmark . realtime { response = yield }
66+ duration = realtime { response = yield }
6267 record ( env , response . first . to_s , duration )
6368 return response
6469 rescue => exception
Original file line number Diff line number Diff line change 4242 end
4343
4444 it 'traces request information' do
45- expect ( Benchmark ) . to receive ( :realtime ) . and_yield . and_return ( 0.2 )
45+ expect ( app ) . to receive ( :realtime ) . and_yield . and_return ( 0.2 )
4646
4747 get '/foo'
4848
6868 end
6969
7070 it 'normalizes paths containing numeric IDs by default' do
71- expect ( Benchmark ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
71+ expect ( app ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
7272
7373 get '/foo/42/bars'
7474
8282 end
8383
8484 it 'normalizes paths containing UUIDs by default' do
85- expect ( Benchmark ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
85+ expect ( app ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
8686
8787 get '/foo/5180349d-a491-4d73-af30-4194a46bdff3/bars'
8888
9696 end
9797
9898 it 'handles consecutive path segments containing IDs' do
99- expect ( Benchmark ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
99+ expect ( app ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
100100
101101 get '/foo/42/24'
102102
110110 end
111111
112112 it 'handles consecutive path segments containing UUIDs' do
113- expect ( Benchmark ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
113+ expect ( app ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
114114
115115 get '/foo/5180349d-a491-4d73-af30-4194a46bdff3/5180349d-a491-4d73-af30-4194a46bdff2'
116116
You can’t perform that action at this time.
0 commit comments