Skip to content

Commit

Permalink
Merge 0761f59 into 726536c
Browse files Browse the repository at this point in the history
  • Loading branch information
dmagliola committed Oct 14, 2020
2 parents 726536c + 0761f59 commit e6eb3e3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/prometheus/middleware/collector.rb
Expand Up @@ -67,15 +67,17 @@ def trace(env)
end

def record(env, code, duration)
path = [env["SCRIPT_NAME"], env['PATH_INFO']].join

counter_labels = {
code: code,
method: env['REQUEST_METHOD'].downcase,
path: strip_ids_from_path(env['PATH_INFO']),
path: strip_ids_from_path(path),
}

duration_labels = {
method: env['REQUEST_METHOD'].downcase,
path: strip_ids_from_path(env['PATH_INFO']),
path: strip_ids_from_path(path),
}

@requests.increment(labels: counter_labels)
Expand Down
12 changes: 12 additions & 0 deletions spec/prometheus/middleware/collector_spec.rb
Expand Up @@ -55,6 +55,18 @@
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.25" => 1)
end

it 'includes SCRIPT_NAME in the path if provided' do
metric = :http_server_requests_total

get '/foo'
expect(registry.get(metric).values.keys.last[:path]).to eql("/foo")

env('SCRIPT_NAME', '/engine')
get '/foo'
env('SCRIPT_NAME', nil)
expect(registry.get(metric).values.keys.last[:path]).to eql("/engine/foo")
end

it 'normalizes paths containing numeric IDs by default' do
expect(Benchmark).to receive(:realtime).and_yield.and_return(0.3)

Expand Down

0 comments on commit e6eb3e3

Please sign in to comment.