Skip to content

Commit

Permalink
Merge d2aab1a into 8b20201
Browse files Browse the repository at this point in the history
  • Loading branch information
rzjfr committed Jan 1, 2021
2 parents 8b20201 + d2aab1a commit 21312ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/prometheus/middleware/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def strip_ids_from_path(path)
path
.gsub(%r{/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(/|$)}, '/:uuid\\1')
.gsub(%r{/\d+(/|$)}, '/:id\\1')
.gsub(%r{/\w+--[0-9a-f]+(/|$)}, '/:signed_id\\1')
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/prometheus/middleware/collector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1)
end

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

get '/foo/eyJfcmFpbHMiOnsibWVzc2FnZSI6--a419915169c2dc3419/bars'

metric = :http_server_requests_total
labels = { method: 'get', path: '/foo/:signed_id/bars', code: '200' }
expect(registry.get(metric).get(labels: labels)).to eql(1.0)

metric = :http_server_request_duration_seconds
labels = { method: 'get', path: '/foo/:signed_id/bars' }
expect(registry.get(metric).get(labels: labels)).to include("0.1" => 0, "0.5" => 1)
end

context 'when the app raises an exception' do
let(:original_app) do
lambda do |env|
Expand Down

0 comments on commit 21312ad

Please sign in to comment.